WCF服务为什么会经常崩溃呢
我是个WCF的初学者,在服务器上架构一个WCF服务,客户端在调用WCF服务的时候如果只开一个就正常
但是如果开了9个以上就会崩溃了~必须重启WCF服务才行
哪位大大可以帮忙看下是啥为题啊~
[最优解释]
没几句代码注释,高手啊!!!
[其他解释]
连接数一增加之后系统崩溃之后,如果再去连接WCF调用某个方法返回的值可能是别的方法的返回值
也就是说可能返回两列的表,也可能是三列的表~
相当吐血,感觉好像服务紊乱了~
[其他解释]
netTcp.ReliableSession.Ordered = true;
netTcp.ReliableSession.InactivityTimeout = new TimeSpan(0, 30, 0);
netTcp.ReliableSession.Enabled = false;
Type t = typeof(Service.Archieve.ArchieveContract);
Type[] iType = t.GetInterfaces();
if (iType == null
[其他解释]
iType.Length <= 0)
return;
foreach (Type tp in iType)
{
netTcp.Name = tp.ToString();
ServiceEndpoint point = host.AddServiceEndpoint(tp, netTcp, "");
}
{
ServiceMetadataBehavior behavior = host.Description.Behaviors.Find<ServiceMetadataBehavior>();
if (behavior == null)
{
behavior = new ServiceMetadataBehavior();
host.Description.Behaviors.Add(behavior);
}
behavior.HttpGetEnabled = true;
behavior.HttpGetUrl = new Uri("http://sc-tfsserver:8023");
}
{
ServiceThrottlingBehavior behavior = host.Description.Behaviors.Find<ServiceThrottlingBehavior>();
if (behavior == null)
{
behavior = new ServiceThrottlingBehavior();
host.Description.Behaviors.Add(behavior);
}
behavior.MaxConcurrentCalls = 1000;
behavior.MaxConcurrentInstances = 1000;
behavior.MaxConcurrentSessions = 1000;
}
{
ServiceDebugBehavior behavior = host.Description.Behaviors.Find<ServiceDebugBehavior>();
if (behavior == null)
{
behavior = new ServiceDebugBehavior();
host.Description.Behaviors.Add(behavior);
}
behavior.IncludeExceptionDetailInFaults = true;
}
if (host.Description.Behaviors.Find<DataContractSerializerOperationBehavior>() == null)
{
Type hostType = host.GetType();
object obj = hostType.Assembly.CreateInstance("System.ServiceModel.Dispatcher.DataContractSerializerServiceBehavior", true, BindingFlags.CreateInstance
[其他解释]
BindingFlags.Instance
[其他解释]
BindingFlags.NonPublic, null, new object[] { false, Int32.MaxValue }, null, null);
IServiceBehavior myServiceBehavior = obj as IServiceBehavior;
if (myServiceBehavior != null)
{
host.Description.Behaviors.Add(myServiceBehavior);
}
}
Binding mexBinding = MetadataExchangeBindings.CreateMexTcpBinding();
var bec = mexBinding.CreateBindingElements();
TcpTransportBindingElement secbec = bec.Find<TcpTransportBindingElement>();
secbec.PortSharingEnabled = true;
CustomBinding binding = new CustomBinding(bec);
host.AddServiceEndpoint(typeof(IMetadataExchange), binding, "mex");
host.Open();//启动服务
#endregion
[其他解释]
服务契约的实现:
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall,IncludeExceptionDetailInFaults = true,ConcurrencyMode = ConcurrencyMode.Multiple)]
public partial class ArchieveContract : Artech.WcfServices.Service.Interface.IEmployees
{
private static IList<Artech.WcfServices.Service.Interface.Employee> employees
{
get
{
if(1==1)
return EmployeesServiceArchieve.employees;
}
}
public Artech.WcfServices.Service.Interface.Employee Get(string id)
{
return EmployeesServiceArchieve.Get(id);
}
public void Create(Artech.WcfServices.Service.Interface.Employee employee)
{
EmployeesServiceArchieve.Create(employee);
}
public void Update(Artech.WcfServices.Service.Interface.Employee employee)
{
EmployeesServiceArchieve.Update(employee);
}
public void Delete(string id)
{
EmployeesServiceArchieve.Delete(id);
}
public IEnumerable<Artech.WcfServices.Service.Interface.Employee> GetAll()
{
return EmployeesServiceArchieve.GetAll();
}
}
[其他解释]
调用的时候:
public IHourData IHourDataChannel;
if (IHourDataChannelArea == null)
{
IHourDataChannelArea = GetChannel<IHourData>();
}
private T GetChannel<T>()
{
NetTcpBinding netBinding = new NetTcpBinding();
netBinding.SendTimeout = TimeSpan.FromMinutes(10);
netBinding.ReceiveTimeout = TimeSpan.FromMinutes(10);
netBinding.MaxBufferPoolSize = 2147483647;
netBinding.MaxBufferSize = 2147483647;
netBinding.ReaderQuotas.MaxDepth = 64;
netBinding.ReaderQuotas.MaxStringContentLength = 2147483647;
netBinding.ReaderQuotas.MaxArrayLength = 2147483647;
netBinding.ReaderQuotas.MaxBytesPerRead = 4096;
netBinding.ReaderQuotas.MaxNameTableCharCount = 16384;
netBinding.ReliableSession.Ordered = true;
netBinding.ReliableSession.InactivityTimeout = TimeSpan.FromMinutes(10);
netBinding.ReliableSession.Enabled = false;
netBinding.Security.Mode = SecurityMode.None;
EndpointAddress address = new EndpointAddress(InvokeContext.CommonConfig.Url);
ChannelFactory<T> factory = new ChannelFactory<T>(netBinding, address);
try
{
return factory.CreateChannel();
}
catch
{
}
return default(T);
}
[其他解释]
这个是自己测试用的代码,没必要加注释~
[其他解释]
崩溃的现象是什么?有没有错误信息/异常信息可以参考?
[其他解释]
tcp 有最大连接数限制。google一下吧。
[其他解释]
最大连接数我有改成netTcp.MaxConnections = 1000;
[其他解释]
忘了说明下我是把WCF寄宿在windows服务里面的~
[其他解释]
windows 自己也有连接数限制呀。比如 XP 就是 10个。查查。
[其他解释]