尝试调用Web服务时出现通道超时错误

时间:2011-06-23 15:05:36

标签: c# wcf web-services

我在调用

时遇到此错误

请求频道在00:00:59.9970702之后等待回复时超时。增加传递给Request的调用的超时值或增加Binding上的SendTimeout值。分配给此操作的时间可能是较长超时的一部分。

我在SO中看过这个 WCF stops responding after about 10 or so calls (throttling)

但我不知道我必须在哪里实现这个......是在我的webconfig文件或webservice配置文件中。有什么建议吗?

EDIT(1):

这是我的webconfig文件

<system.serviceModel>
                <bindings>
            <basicHttpBinding>
                <binding name="BinaryCertTokenOverSSL" closeTimeout="00:01:00"
                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                    allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                    useDefaultWebProxy="true">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <security mode="TransportWithMessageCredential">
                        <transport clientCredentialType="None" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="Certificate" algorithmSuite="Default" />
                    </security>
                </binding>
                <binding name="UserNameTokenOverSSLBinding" closeTimeout="00:01:00"
                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                    allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                    useDefaultWebProxy="true">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <security mode="TransportWithMessageCredential">
                        <transport clientCredentialType="None" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="UserName" algorithmSuite="Default" />
                    </security>
                </binding>
            </basicHttpBinding>
            <wsHttpBinding>
                <binding name="WSBinaryCertReliable" closeTimeout="00:01:00"
                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                    bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                    messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
                    allowCookies="false">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <reliableSession ordered="true" inactivityTimeout="00:10:00"
                        enabled="true" />
                    <security mode="Message">
                        <transport clientCredentialType="Windows" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="Certificate" negotiateServiceCredential="false"
                            algorithmSuite="Default" establishSecurityContext="true" />
                    </security>
                </binding>
                <binding name="WSUserNameReliable" closeTimeout="00:01:00" openTimeout="00:01:00"
                    receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false"
                    transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                    messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
                    allowCookies="false">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <reliableSession ordered="true" inactivityTimeout="00:10:00"
                        enabled="true" />
                    <security mode="Message">
                        <transport clientCredentialType="Windows" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="UserName" negotiateServiceCredential="false"
                            algorithmSuite="Default" establishSecurityContext="true" />
                    </security>
                </binding>
                <binding name="WSBinaryCert" closeTimeout="00:01:00" openTimeout="00:01:00"
                    receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false"
                    transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                    messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
                    allowCookies="false">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <reliableSession ordered="true" inactivityTimeout="00:10:00"
                        enabled="false" />
                    <security mode="Message">
                        <transport clientCredentialType="Windows" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="Certificate" negotiateServiceCredential="false"
                            algorithmSuite="Default" establishSecurityContext="false" />
                    </security>
                </binding>
                <binding name="WSUserName" closeTimeout="00:01:00" openTimeout="00:01:00"
                    receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false"
                    transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                    messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
                    allowCookies="false">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <reliableSession ordered="true" inactivityTimeout="00:10:00"
                        enabled="false" />
                    <security mode="Message">
                        <transport clientCredentialType="Windows" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="UserName" negotiateServiceCredential="false"
                            algorithmSuite="Default" establishSecurityContext="false" />
                    </security>
                </binding>
            </wsHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://XXXvm134.rsimail.rsil.XXX.com/VWWebservice/VWSecurityServices.svc/WsBinaryCertReliable"
                binding="wsHttpBinding" bindingConfiguration="WSBinaryCertReliable"
                contract="IVWSecurityServices" name="WSBinaryCertReliable">
                <identity>
                    <certificate encodedValue="AwAAAAEAAAAUAAAAch9c8R+87NcfIPn0imYdQaHEFp8gAAAAAQAAAFcCAAAwggJTMIIBvKADAgECAhA3Zx4Bjx6gs0Cu4C0/9OpuMA0GCSqGSIb3DQEBBAUAMCwxKjAoBgNVBAMTIXJhbWNvdm0xMzQucnNpbWFpbC5yc2lsLnJhbWNvLmNvbTAeFw05OTEyMzExODMwMDBaFw0xNDEyMzExODMwMDBaMCwxKjAoBgNVBAMTIXJhbWNvdm0xMzQucnNpbWFpbC5yc2lsLnJhbWNvLmNvbTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAtcad6zbauhN5mo54MDt4JAuTtU0MIOuhXhsUGIGYkZ4+mhav3oCRiALzQWLfmm6jQZAsW8LXE/p1UZLfenaHRWTcDxZ0Qvuow51NU4r30Fr7U+XQCQNytaVHI/aYk2CreaOoPzlMxrFjw33yShBi9LXsM7FQZL3sAWFro2/A74sCAwEAAaN2MHQwEwYDVR0lBAwwCgYIKwYBBQUHAwEwXQYDVR0BBFYwVIAQI72gtckgLr+CwMqK5vo11qEuMCwxKjAoBgNVBAMTIXJhbWNvdm0xMzQucnNpbWFpbC5yc2lsLnJhbWNvLmNvbYIQN2ceAY8eoLNAruAtP/TqbjANBgkqhkiG9w0BAQQFAAOBgQAYUlt7PX01iokgi8jW96tdBiaJIb7XBt9DgUPqAhunbSrPq/sNaIy+hLBJ7W174Ozh0r/cJp18WoCD8S0IbBvvs3aSaCoBPAa+Rb2OSx21QgEpZ5+flxaXK9HxY0WmmTXRqsgR4bplZ5F1RFX9x6Px+yyQzu+IBPpwcL8JSs+pvA==" />
                </identity>
            </endpoint>
            <endpoint address="https://XXXvm134.rsimail.rsil.XXX.com/VWWebservice/VWSecurityServices.svc/BinaryCertTokenOverSSL"
                binding="basicHttpBinding" bindingConfiguration="BinaryCertTokenOverSSL"
                contract="IVWSecurityServices" name="BinaryCertTokenOverSSL" />
            <endpoint address="http://XXXvm134.rsimail.rsil.XXX.com/VWWebservice/VWSecurityServices.svc/WSUserNameReliable"
                binding="wsHttpBinding" bindingConfiguration="WSUserNameReliable"
                contract="IVWSecurityServices" name="WSUserNameReliable">
                <identity>
                    <certificate encodedValue="AwAAAAEAAAAUAAAAch9c8R+87NcfIPn0imYdQaHEFp8gAAAAAQAAAFcCAAAwggJTMIIBvKADAgECAhA3Zx4Bjx6gs0Cu4C0/9OpuMA0GCSqGSIb3DQEBBAUAMCwxKjAoBgNVBAMTIXJhbWNvdm0xMzQucnNpbWFpbC5yc2lsLnJhbWNvLmNvbTAeFw05OTEyMzExODMwMDBaFw0xNDEyMzExODMwMDBaMCwxKjAoBgNVBAMTIXJhbWNvdm0xMzQucnNpbWFpbC5yc2lsLnJhbWNvLmNvbTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAtcad6zbauhN5mo54MDt4JAuTtU0MIOuhXhsUGIGYkZ4+mhav3oCRiALzQWLfmm6jQZAsW8LXE/p1UZLfenaHRWTcDxZ0Qvuow51NU4r30Fr7U+XQCQNytaVHI/aYk2CreaOoPzlMxrFjw33yShBi9LXsM7FQZL3sAWFro2/A74sCAwEAAaN2MHQwEwYDVR0lBAwwCgYIKwYBBQUHAwEwXQYDVR0BBFYwVIAQI72gtckgLr+CwMqK5vo11qEuMCwxKjAoBgNVBAMTIXJhbWNvdm0xMzQucnNpbWFpbC5yc2lsLnJhbWNvLmNvbYIQN2ceAY8eoLNAruAtP/TqbjANBgkqhkiG9w0BAQQFAAOBgQAYUlt7PX01iokgi8jW96tdBiaJIb7XBt9DgUPqAhunbSrPq/sNaIy+hLBJ7W174Ozh0r/cJp18WoCD8S0IbBvvs3aSaCoBPAa+Rb2OSx21QgEpZ5+flxaXK9HxY0WmmTXRqsgR4bplZ5F1RFX9x6Px+yyQzu+IBPpwcL8JSs+pvA==" />
                </identity>
            </endpoint>
            <endpoint address="http://XXXvm134.rsimail.rsil.XXX.com/VWWebservice/VWSecurityServices.svc/WSBinaryCert"
                binding="wsHttpBinding" bindingConfiguration="WSBinaryCert"
                contract="IVWSecurityServices" name="WSBinaryCert">
                <identity>
                    <certificate encodedValue="AwAAAAEAAAAUAAAAch9c8R+87NcfIPn0imYdQaHEFp8gAAAAAQAAAFcCAAAwggJTMIIBvKADAgECAhA3Zx4Bjx6gs0Cu4C0/9OpuMA0GCSqGSIb3DQEBBAUAMCwxKjAoBgNVBAMTIXJhbWNvdm0xMzQucnNpbWFpbC5yc2lsLnJhbWNvLmNvbTAeFw05OTEyMzExODMwMDBaFw0xNDEyMzExODMwMDBaMCwxKjAoBgNVBAMTIXJhbWNvdm0xMzQucnNpbWFpbC5yc2lsLnJhbWNvLmNvbTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAtcad6zbauhN5mo54MDt4JAuTtU0MIOuhXhsUGIGYkZ4+mhav3oCRiALzQWLfmm6jQZAsW8LXE/p1UZLfenaHRWTcDxZ0Qvuow51NU4r30Fr7U+XQCQNytaVHI/aYk2CreaOoPzlMxrFjw33yShBi9LXsM7FQZL3sAWFro2/A74sCAwEAAaN2MHQwEwYDVR0lBAwwCgYIKwYBBQUHAwEwXQYDVR0BBFYwVIAQI72gtckgLr+CwMqK5vo11qEuMCwxKjAoBgNVBAMTIXJhbWNvdm0xMzQucnNpbWFpbC5yc2lsLnJhbWNvLmNvbYIQN2ceAY8eoLNAruAtP/TqbjANBgkqhkiG9w0BAQQFAAOBgQAYUlt7PX01iokgi8jW96tdBiaJIb7XBt9DgUPqAhunbSrPq/sNaIy+hLBJ7W174Ozh0r/cJp18WoCD8S0IbBvvs3aSaCoBPAa+Rb2OSx21QgEpZ5+flxaXK9HxY0WmmTXRqsgR4bplZ5F1RFX9x6Px+yyQzu+IBPpwcL8JSs+pvA==" />
                </identity>
            </endpoint>
            <endpoint address="http://XXXvm134.rsimail.rsil.XXX.com/VWWebservice/VWSecurityServices.svc/WSUserName"
                binding="wsHttpBinding" bindingConfiguration="WSUserName"
                contract="IVWSecurityServices" name="WSUserName">
                <identity>
                    <certificate encodedValue="AwAAAAEAAAAUAAAAch9c8R+87NcfIPn0imYdQaHEFp8gAAAAAQAAAFcCAAAwggJTMIIBvKADAgECAhA3Zx4Bjx6gs0Cu4C0/9OpuMA0GCSqGSIb3DQEBBAUAMCwxKjAoBgNVBAMTIXJhbWNvdm0xMzQucnNpbWFpbC5yc2lsLnJhbWNvLmNvbTAeFw05OTEyMzExODMwMDBaFw0xNDEyMzExODMwMDBaMCwxKjAoBgNVBAMTIXJhbWNvdm0xMzQucnNpbWFpbC5yc2lsLnJhbWNvLmNvbTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAtcad6zbauhN5mo54MDt4JAuTtU0MIOuhXhsUGIGYkZ4+mhav3oCRiALzQWLfmm6jQZAsW8LXE/p1UZLfenaHRWTcDxZ0Qvuow51NU4r30Fr7U+XQCQNytaVHI/aYk2CreaOoPzlMxrFjw33yShBi9LXsM7FQZL3sAWFro2/A74sCAwEAAaN2MHQwEwYDVR0lBAwwCgYIKwYBBQUHAwEwXQYDVR0BBFYwVIAQI72gtckgLr+CwMqK5vo11qEuMCwxKjAoBgNVBAMTIXJhbWNvdm0xMzQucnNpbWFpbC5yc2lsLnJhbWNvLmNvbYIQN2ceAY8eoLNAruAtP/TqbjANBgkqhkiG9w0BAQQFAAOBgQAYUlt7PX01iokgi8jW96tdBiaJIb7XBt9DgUPqAhunbSrPq/sNaIy+hLBJ7W174Ozh0r/cJp18WoCD8S0IbBvvs3aSaCoBPAa+Rb2OSx21QgEpZ5+flxaXK9HxY0WmmTXRqsgR4bplZ5F1RFX9x6Px+yyQzu+IBPpwcL8JSs+pvA==" />
                </identity>
            </endpoint>
            <endpoint address="https://XXXvm134.rsimail.rsil.XXX.com/VWWebservice/VWSecurityServices.svc/UserNameTokenOverSSL"
                binding="basicHttpBinding" bindingConfiguration="UserNameTokenOverSSLBinding"
                contract="IVWSecurityServices" name="UserNameTokenOverSSLBinding" />
        </client>
    </system.serviceModel>

这是我的webservice配置文件

<system.serviceModel>
    <extensions>
      <bindingElementExtensions>
        <add name="sslOffloadedHttpsTransport" type="XXX.VW.Web.Services.CustomBinding.SSLOffloadedHttpsTransportElement, XXX.VW.RT.WebServices.Core, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" />
      </bindingElementExtensions>
    </extensions>
    <behaviors>
      <serviceBehaviors>
      <behavior name="e-ServiceBehavior">
          <serviceCredentials>
            <clientCertificate>
              <authentication certificateValidationMode="None" revocationMode="Online" />
            </clientCertificate>
            <serviceCertificate findValue="XXXvm134.rsimail.rsil.XXX.com" storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName" />
            <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="XXX.VW.RT.VWCustomUserValidator,XXX.VW.RT.Library" />
          </serviceCredentials>
          <serviceDebug includeExceptionDetailInFaults="true" />
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="false" />
          <serviceAuthorization principalPermissionMode="None" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <basicHttpBinding>
        <binding name="UserNameTokenOverSSLBinding">
          <security mode="TransportWithMessageCredential" />
        </binding>
        <binding name="BinaryCertTokenOverSSLBinding" closeTimeout="00:10:00" openTimeout="00:10:00" sendTimeout="00:10:00">
          <security mode="TransportWithMessageCredential">
            <message clientCredentialType="Certificate" />
          </security>
        </binding>
         <binding name="Vw30BasicHttpBinding" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" maxBufferSize="65536" maxReceivedMessageSize="65536">
          <security>
            <transport clientCredentialType="None" />
            <message clientCredentialType="UserName" />
          </security>
        </binding>
      </basicHttpBinding>
      <customBinding>
          <binding name="Vw30netTcpHABinding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:01:00" sendTimeout="00:01:00">
            <binaryMessageEncoding>
            <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
            </binaryMessageEncoding>
            <tcpTransport maxBufferPoolSize="524288" maxReceivedMessageSize="99999998" connectionBufferSize="8192" hostNameComparisonMode="StrongWildcard" channelInitializationTimeout="00:01:00" maxBufferSize="99999998" maxPendingConnections="20" maxOutputDelay="00:00:00.2000000" maxPendingAccepts="5" transferMode="Buffered" listenBacklog="20" portSharingEnabled="false" teredoEnabled="false">
            <connectionPoolSettings groupName="default" leaseTimeout="00:00:02" idleTimeout="00:02:00" maxOutboundConnectionsPerEndpoint="20" />
            </tcpTransport>
            </binding>
            <binding name="Vw30HttpHABinding">
            <textMessageEncoding />
            <httpTransport keepAliveEnabled="false">
            </httpTransport>
        </binding> 

        <binding name="UserNameTokenOverSSLOffloaderBinding">
          <textMessageEncoding messageVersion="Soap11" />
          <security authenticationMode="UserNameOverTransport">
            <secureConversationBootstrap />
          </security>
          <sslOffloadedHttpsTransport />
        </binding>
        <binding name="BinaryCertTokenOverSSLOffloaderBinding">
          <textMessageEncoding messageVersion="Soap11" />
          <security authenticationMode="UserNameOverTransport">
            <secureConversationBootstrap />
          </security>
          <sslOffloadedHttpsTransport />
        </binding>
      </customBinding>
      <netTcpBinding>
        <binding name="Vw30netTcpBinding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:01:00" sendTimeout="00:01:00" transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions" hostNameComparisonMode="StrongWildcard" listenBacklog="10" maxBufferPoolSize="524288" maxBufferSize="65536" maxConnections="10" maxReceivedMessageSize="65536">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" />
          <security mode="None">
            <transport clientCredentialType="None" protectionLevel="None" />
            <message clientCredentialType="None" />
          </security>
        </binding>
      </netTcpBinding>
      <wsHttpBinding>
        <binding name="WSUserNameBinding" transactionFlow="true">
          <security>
            <transport clientCredentialType="None" />
            <message clientCredentialType="UserName" negotiateServiceCredential="false" establishSecurityContext="false" />
          </security>
        </binding>
        <binding name="WSBinaryCertBinding" transactionFlow="true">
          <security>
            <transport clientCredentialType="None" />
            <message clientCredentialType="Certificate" negotiateServiceCredential="false" establishSecurityContext="false" />
          </security>
        </binding>
        <binding name="WSUserNameReliableBinding" closeTimeout="00:10:00" openTimeout="00:10:00" sendTimeout="00:10:00" transactionFlow="true">
          <reliableSession enabled="true" />
          <security>
            <transport clientCredentialType="None" />
            <message clientCredentialType="UserName" negotiateServiceCredential="false" />
          </security>
        </binding>
        <binding name="WsBinaryCertReliableBinding" transactionFlow="true">
          <reliableSession enabled="true" />
          <security>
            <transport clientCredentialType="None" />
            <message clientCredentialType="Certificate" negotiateServiceCredential="false" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    <services configSource="Web.Services.config" />    
    <!--Should be uncommented when webservices are consumed through SSL Offloaders, and the application pool should be set to use .NET framework 4.0. -->
    <!--<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/> -->
  </system.serviceModel>    

3 个答案:

答案 0 :(得分:4)

这通常归结为会话和限制

在.NET 4之前,默认的最大并发会话数为10.这意味着第11个并发会话等待其中一个会话消失,并最终命中客户端发送超时(默认为1分钟)< / p>

在.NET 4之后,默认值为100 x处理器(核心),因此不太可能被命中

您有3个选项:

  1. 增加会话限制http://www.codegain.com/articles/wcf/security/wcf-service-throttling-behavior.aspx
  2. 更快地关闭现有会话(确保您立即在代理上调用Close)
  3. 增加客户端的发送超时时间

答案 1 :(得分:1)

一般建议,因为很难判断哪个服务导致了您的错误:

确保您的超时值在服务和客户端的配置中匹配。

对于刚接触Web服务的人来说,这是一个非常常见的问题。如果增加一个值,通常最好在另一端增加匹配值。

因此,请确保所有绑定行为的服务和客户端上的所有超时值都匹配,然后再给它一个镜头。

如果这不起作用,请尝试通过添加零来增加所有值,然后尝试一下。如果可以,那么就开始减少超时,直到找到导致问题的那个,然后调整它。

解决这个问题还有很长的路要走,但由于你不知道哪个服务导致了问题,这可能是你最好的选择。

答案 2 :(得分:1)

调用服务后可能没有关闭对象。

示例:

WCFServices.Module1 objWCFServ = new WCFServices.Module1(); DataSet ds = obj.MethodName(param1,param2); ... ....

objWCFServ.Close(); objWCFServ = NULL;