我们现在遇到了几天的WCF通信错误,我无法弄清楚导致错误的原因。我原本以为这是一个SSL证书问题,但事实并非如此。我还确保只需在Web浏览器上输入URL即可访问端点,并且可以查看端点。我还确保默认请求大小不会导致问题。我确定请求小于默认值30MB。
还有哪些其他方法可以防止此堆栈跟踪错误?
客户端堆栈跟踪:
由于通信失败,WCFDirector提取失败。
由于表单未正确加载,因此必须将其关闭。 ---> OSI.Framework.FrameworkException:由于通信失败,WCFDirector提取失败。 ---> System.ServiceModel.CommunicationException:底层连接已关闭:服务器已关闭预期保持活动状态的连接。 ---> System.Net.WebException:底层连接已关闭:服务器已关闭预期保持活动状态的连接。 ---> System.IO.IOException:无法从传输连接读取数据:远程主机强制关闭现有连接。 ---> System.Net.Sockets.SocketException:远程主机强制关闭现有连接 在System.Net.Sockets.Socket.Receive(Byte []缓冲区,Int32偏移量,Int32大小,SocketFlags socketFlags) 在System.Net.Sockets.NetworkStream.Read(Byte []缓冲区,Int32偏移量,Int32大小) ---内部异常堆栈跟踪结束--- 在System.Net.Sockets.NetworkStream.Read(Byte []缓冲区,Int32偏移量,Int32大小) 在System.Net.FixedSizeReader.ReadPacket(Byte []缓冲区,Int32偏移量,Int32计数) 在System.Net.Security._SslStream.StartFrameHeader(Byte []缓冲区,Int32偏移量,Int32计数,AsyncProtocolRequest asyncRequest) 在System.Net.Security._SslStream.StartReading(Byte []缓冲区,Int32偏移量,Int32计数,AsyncProtocolRequest asyncRequest) 在System.Net.Security._SslStream.ProcessRead(Byte []缓冲区,Int32偏移量,Int32计数,AsyncProtocolRequest asyncRequest) 在System.Net.TlsStream.Read(Byte []缓冲区,Int32偏移量,Int32大小) 在System.Net.PooledStream.Read(Byte []缓冲区,Int32偏移量,Int32大小) 在System.Net.Connection.SyncRead(HttpWebRequest请求,布尔userRetrievedStream,布尔probeRead) ---内部异常堆栈跟踪结束--- 在System.Net.HttpWebRequest.GetResponse() at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout) ---内部异常堆栈跟踪结束---
服务器堆栈跟踪:
at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException,HttpWebRequest request,HttpAbortReason abortReason) at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout) 在System.ServiceModel.Channels.RequestChannel.Request(消息消息,TimeSpan超时) 在System.ServiceModel.Dispatcher.RequestChannelBinder.Request(消息消息,TimeSpan超时) 在System.ServiceModel.Channels.ServiceChannel.Call(String action,Boolean oneway,ProxyOperationRuntime operation,Object [] ins,Object [] outs,TimeSpan timeout) 在System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall,ProxyOperationRuntime操作) 在System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
答案 0 :(得分:0)
尝试关闭KeepAlive。 类似的东西:
var client = new MyWcfClient();
var customBinding = new CustomBinding(client.Endpoint.Binding);
var transportElement = customBinding.Elements.Find<HttpTransportBindingElement>();
transportElement.KeepAliveEnabled = false;
client.Endpoint.Binding = customBinding;
仅配置Rest API和SOAP的版本
<services>
<service name="SecureTransportDemo.Service.GreetingService">
<endpoint address="Soap"
binding="customBinding"
bindingConfiguration="soap-secure-nokeepalive"
contract="SecureTransportDemo.Service.IGreetingService"
name="soap-nokeepalive"/>
<endpoint address="Rest"
binding="customBinding"
bindingConfiguration="rest-secure-nokeepalive"
behaviorConfiguration="web"
contract="SecureTransportDemo.Service.IGreetingService"
name="rest-nokeepalive"/>
</service>
</services>
<bindings>
<customBinding>
<binding name="soap-secure-nokeepalive">
<textMessageEncoding />
<httpsTransport allowCookies="false"
keepAliveEnabled="false"/>
</binding>
<binding name="rest-secure-nokeepalive">
<webMessageEncoding />
<httpsTransport manualAddressing="true"
allowCookies="false"
keepAliveEnabled="false"/>
</binding>
</customBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp automaticFormatSelectionEnabled="true"
faultExceptionEnabled="true"
helpEnabled="true"/>
</behavior>
</endpointBehaviors>
</behaviors>