【问题标题】:Why can't my WCF Client connect to my WCF Service?为什么我的 WCF 客户端无法连接到我的 WCF 服务?
【发布时间】:2014-01-22 11:28:19
【问题描述】:

我开发了 WCF 服务,但我在从客户端连接到它时遇到问题。

我可以在浏览器中看到服务的 wsdl,但是当我尝试通过 WCF 客户端连接服务时,我收到以下错误消息:

打开操作未在分配的超时时间 00:23:59.5339734 内完成。分配给此操作的时间可能是较长超时的一部分。

以下是我的客户端 app.config 详细信息:-

 <system.serviceModel>
<bindings>
  <wsDualHttpBinding>
    <binding name="WSDualHttpBinding_IService" closeTimeout="00:25:00" openTimeout="00:24:00" receiveTimeout="00:15:00" sendTimeout="00:25:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true">
      <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="409600" maxNameTableCharCount="16384"/>
      <reliableSession ordered="true" inactivityTimeout="00:25:00"/>
      <security mode="None">
        <!--<message clientCredentialType="Windows" negotiateServiceCredential="true" algorithmSuite="Default"/>-->
      </security>
    </binding>
  </wsDualHttpBinding>
</bindings>
<client>
  <endpoint address="http://silcore.co.in/Service.svc" 
                  binding="wsDualHttpBinding"
                  bindingConfiguration="WSDualHttpBinding_IService" 
                  contract="IService" 
                  name="WSDualHttpBinding_IService">
    <identity>
      <dns value="http://silcore.co.in"/>
    </identity>
  </endpoint>
</client>

这是超时错误的堆栈跟踪:

at System.ServiceModel.Channels.ReliableRequestor.ThrowTimeoutException()
at System.ServiceModel.Channels.ReliableRequestor.Request(TimeSpan timeout)
  at System.ServiceModel.Channels.ClientReliableSession.Open(TimeSpan timeout)
   at System.ServiceModel.Channels.ClientReliableDuplexSessionChannel.OnOpen(TimeSpan timeout)

at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)

Exception rethrown at [0]: 
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg,   IMessage retMsg)
 at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
 at System.ServiceModel.ICommunicationObject.Open(TimeSpan timeout)
 at   System.ServiceModel.ClientBase`1.System.ServiceModel.ICommunicationObject.Open(TimeSpan timeout)
 at System.ServiceModel.ClientBase`1.Open()
 at WCF_Client.Program.Main(String[] args)

服务器端 web.congif 文件

    <?xml version="1.0"?>
<configuration>

<system.web>
 <compilation targetFramework="4.0" defaultLanguage="c#" />
 <customErrors mode="Off" />
</system.web>
<system.webServer>
  <defaultDocument>
    <files>
      <add value="Service.svc" />
  </files>
</defaultDocument>
</system.webServer>
<system.serviceModel>
<bindings>
  <wsDualHttpBinding>
    <binding name="DualNewBinding" />
  </wsDualHttpBinding>
</bindings>
<services>
  <service behaviorConfiguration="HostWCF.ServiceBehavior" name="HostWCF.Service">
    <endpoint address="" binding="wsDualHttpBinding" bindingConfiguration="DualNewBinding" contract="HostWCF.IService">
      <identity>
        <dns value="silcore.co.in" />
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="http://silcore.co.in/" />
      </baseAddresses>
    </host>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="HostWCF.ServiceBehavior">
      <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
      <serviceMetadata httpGetEnabled="true" />
      <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
</configuration>

【问题讨论】:

  • 尝试显着增加所有超时。另外,您使用防火墙吗?
  • 这是你得到的only错误吗?什么时候发生错误,当你执行一个资源繁重、耗时的方法时,或者还有一个void Test() 方法时?
  • 我已经将时间增加了 24 分钟,但仍然出现错误,@ athabaska。 @CodeCaster 我没有使用任何繁重的资源。除了这些,我还能做什么?
  • 您可以从添加更多细节开始并查看正在发生的事情的细节,这没有灵丹妙药。首先,显示完整的异常。然后enable tracing 用于客户端和服务器,以查看请求的最终位置。该服务是否可以在您的开发机器上运行?如果你添加并调用一个实际上什么都不做的测试方法,它会起作用吗?
  • 我曾尝试在 localhost 中托管并且成功,但是当我移动到服务器时,就会出现这个问题。

标签: c# .net wcf


【解决方案1】:

我会说服务背后的操作确实需要很长时间。预计需要超过 24 分钟吗? 如果是这样,请增加超时时间,或者您应该使该操作异步。

如果 24 分钟不是预期的,请尝试更改操作以立即返回。它现在有效吗?如果是,那么这是您的操作需要很长时间,您需要找出如何以及为什么。

如果没有,您可能遇到了防火墙/网络问题。服务器或中间人可能不会拒绝您的连接,而只是忽略它。要对此进行调试,请尝试暂时停用安全性。 另外,请确保服务器端是否收到请求。放置断点或记录任何传入的请求。

希望对你有所帮助

【讨论】:

    【解决方案2】:

    我认为您需要在客户端配置中增加 OpenTimeOut 的值。

    检查天气是否有防火墙阻止服务器上的呼叫

    我也觉得服务器端的某种日志记录或网络监控工具也可以帮助你

    NetMon 是 Microsoft 的一个不错的工具。试试看

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-02-22
      • 1970-01-01
      • 2020-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多