首页 文章

WCF通信错误

提问于
浏览
0

我们几天来一直遇到WCF通信错误,我无法弄清楚导致错误的原因 . 我原本以为这是一个SSL证书问题,但事实并非如此 . 我还确保只需在Web浏览器上输入URL即可访问 endpoints ,并且可以查看 endpoints . 我还确保默认请求大小不会导致问题 . 我确定请求的默认值小于30MB .

还有什么能阻止这种堆栈跟踪错误?

客户端堆栈跟踪:

由于通信失败,WCFDirector提取失败 . 由于表格没有正确加载,因此必须关闭 . ---> OSI.Framework.FrameworkException:由于通信失败,WCFDirector提取失败 . ---> System.ServiceModel.CommunicationException:底层连接已关闭:服务器已关闭预期保持活动状态的连接 . ---> System.Net.WebException:底层连接已关闭:服务器已关闭预期保持活动状态的连接 . ---> System.IO.IOException:无法从传输连接读取数据:远程主机强制关闭现有连接 . ---> System.Net.Sockets.SocketException:远程主机在System的System.Net.Sockets.Socket.Receive(Byte []缓冲区,Int32偏移量,Int32大小,SocketFlags socketFlags)强制关闭现有连接 . Net.Sockets.NetworkStream.Read(Byte []缓冲区,Int32偏移量,Int32大小)---内部异常堆栈跟踪结束---在System.Net.Sockets.NetworkStream.Read(Byte []缓冲区,Int32偏移量,在系统上的System.Net.FixedSizeReader.ReadPacket(Byte []缓冲区,Int32偏移量,Int32计数)处的System32.Net.Security._SslStream.StartFrameHeader(Byte []缓冲区,Int32偏移量,Int32计数,AsyncProtocolRequest asyncRequest)处的Int32大小)系统中的System.Net.Security._SslStream.ProcessRead(Byte []缓冲区,Int32偏移量,Int32计数,AsyncProtocolRequest asyncRequest)的.Net.Security._SslStream.StartReading(Byte []缓冲区,Int32偏移量,Int32计数,AsyncProtocolRequest asyncRequest) System.Net.PooledStream.Read(Byte []缓冲区,Int32偏移量的.Net.TlsStream.Read(Byte []缓冲区,Int32偏移量,Int32大小) System.Net.Connection.SyncRead上的,Int32大小)(HttpWebRequest请求,布尔userRetrievedStream,布尔探测器读取)---内部异常堆栈跟踪的结束---在System.ServiceModel.Channels的System.Net.HttpWebRequest.GetResponse()处.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)---内部异常堆栈跟踪结束---

服务器堆栈跟踪:

System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException,HttpWebRequest请求,HttpAbortReason abortReason),位于System.ServiceModel.Channels.RequestChannel的System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout) . System.ServiceModel.Dispatcher.RequestChannelBinder.Request(消息消息,TimeSpan超时)在System.ServiceModel.Channels.ServiceChannel.Call(String action,Boolean oneway,ProxyOperationRuntime operation,Object [] ins,请求(消息消息,TimeSpan超时), System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage消息)中的System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall,ProxyOperationRuntime操作)中的Object [] outs,TimeSpan timeout)

1 回答

  • 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>
    

相关问题