我的服务的app.config
<system.serviceModel>
<client>
<endpoint name="DataLocal" address="net.tcp://SomeAddress" binding="netTcpBinding" contract="ISomeContract" bindingConfiguration="TcpCustomSecurity" behaviorConfiguration="SecureBehaviorName">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
</client>
<services>
<service name="SomeService">
<host>
<baseAddresses>
<add baseAddress="http://SomeService" />
<add baseAddress="net.tcp://SomeService" />
</baseAddresses>
</host>
<endpoint name="SomeService_Normal" address="Secure" binding="netTcpBinding" contract="ISomeService" bindingConfiguration="TcpNormal"/>
</service>
</services>
<bindings>
<netTcpBinding>
<binding name="TcpNormal" transferMode="Buffered" receiveTimeout="24.20:31:23.6470000">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
<security mode="None" />
</binding>
<binding name="TcpCustomSecurity" transferMode="Buffered" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="24.20:31:23.6470000" sendTimeout="00:01:00" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="2147483647">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
<security mode="Message">
<message clientCredentialType="UserName"/>
</security>
</binding>
</netTcpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="SecureBehaviorName">
<clientCredentials>
<serviceCertificate>
<authentication certificateValidationMode="None"/>
</serviceCertificate>
</clientCredentials>
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</endpointBehaviors>
</behaviors>
以下是我收到错误的堆栈声明..
> System.dll!System.Net.Sockets.Socket.Send(byte[] buffer, int offset, int size, System.Net.Sockets.SocketFlags socketFlags) + 0x5a bytes
System.ServiceModel.dll!System.ServiceModel.Channels.SocketConnection.Write(byte[] buffer, int offset, int size, bool immediate, System.TimeSpan timeout) + 0xa7 bytes
System.ServiceModel.dll!System.ServiceModel.Channels.SocketConnection.Write(byte[] buffer, int offset, int size, bool immediate, System.TimeSpan timeout, System.ServiceModel.Channels.BufferManager bufferManager) + 0x34 bytes
System.ServiceModel.dll!System.ServiceModel.Channels.BufferedConnection.WriteNow(byte[] buffer, int offset, int size, System.TimeSpan timeout, System.ServiceModel.Channels.BufferManager bufferManager) + 0x90 bytes
System.ServiceModel.dll!System.ServiceModel.Channels.BufferedConnection.Write(byte[] buffer, int offset, int size, bool immediate, System.TimeSpan timeout, System.ServiceModel.Channels.BufferManager bufferManager) + 0x47 bytes
System.ServiceModel.dll!System.ServiceModel.Channels.FramingDuplexSessionChannel.OnSend(System.ServiceModel.Channels.Message message, System.TimeSpan timeout) + 0x115 bytes
System.ServiceModel.dll!System.ServiceModel.Channels.OutputChannel.Send(System.ServiceModel.Channels.Message message, System.TimeSpan timeout) + 0x81 bytes
System.ServiceModel.dll!System.ServiceModel.Dispatcher.DuplexChannelBinder.Request(System.ServiceModel.Channels.Message message, System.TimeSpan timeout) + 0x154 bytes
System.ServiceModel.dll!System.ServiceModel.Channels.ServiceChannel.Call(string action, bool oneway, System.ServiceModel.Dispatcher.ProxyOperationRuntime operation, object[] ins, object[] outs, System.TimeSpan timeout) + 0x206 bytes
System.ServiceModel.dll!System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(System.Runtime.Remoting.Messaging.IMethodCallMessage methodCall, System.ServiceModel.Dispatcher.ProxyOperationRuntime operation) + 0x59 bytes
System.ServiceModel.dll!System.ServiceModel.Channels.ServiceChannelProxy.Invoke(System.Runtime.Remoting.Messaging.IMessage message) + 0x65 bytes
mscorlib.dll!System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(ref System.Runtime.Remoting.Proxies.MessageData msgData, int type) + 0xee bytes
//首先在上面的堆栈中进行服务调用......
服务行为是这样的: [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
经过几个小时的持续测试后发生错误......无法在调试时重现它..
修改
感谢Dejan ......我得到了跟踪结果。
首次出现错误时收到此消息:已达到最大待处理连接数。
在第二次出现时我收到此消息:系统达到油门'MaxConcurrentConnections'的限制设置。此油门的限制设置为200.可以通过修改服务油门中的属性'maxConcurrentSessions'来改变油门值元件。
所以对于第二条消息,我这样做了:
并将此服务行为分配给服务。我是否需要在第一条消息的绑定上设置maxConnections。此外,这是问题的根本原因,第一个或第二个或两个。因为在随后的消息中我总是得到第二条消息。
请指导更新我的app.config以避免出现这种情况。
更新
我有跟踪结果......
在第一次出现时我收到此消息:已达到最大待处理连接数。
关于第二次出现我收到此消息:系统达到了油门限制设置'MaxConcurrentConnections'。此油门的限制设置为200.可以通过修改服务油门元素中的属性'maxConcurrentSessions'来改变油门值。 / p>
所以对于第二条消息,我这样做了:
<serviceBehaviors>
<behavior name="tcpNormalBehavior">
<serviceThrottling maxConcurrentSessions="800" maxConcurrentInstances="800" maxConcurrentCalls="200" />
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>
</serviceBehaviors>
并将此服务行为分配给服务。 我是否需要在第一条消息的绑定上设置maxConnections。此外,这是问题的根本原因,第一个或第二个或两个。因为在随后的消息中我总是得到第二条消息。
请指导。
答案 0 :(得分:1)
您可能会在WCF服务中的某处出现未处理的异常,例如堆栈溢出。如果我得到正确的服务,该服务可以运行,但几个小时后就会停止工作。
调试WCF服务的第一步是WCF Tracing。启用它,尝试测试您的服务,并在它再次停止工作后,.svclog文件中应该有一个跟踪条目。
修改
关于您更新的问题:您获得该异常是因为在完成调用后您没有从客户端关闭连接。尝试重构您的代码,以便调用WCF如下所示:
WCFProxy clientProxy = null;
try
{
clientProxy = new WCFProxy();
clientProxy.SomeCall();
clientProxy.Close();
}
catch (Exception)
{
if (clientProxy != null)
{
clientProxy.Abort();
}
throw;
}
然后看看它是否会引起问题。