c# - WCF 服务超时

标签 c# wcf

我有一个公开 wcf 服务的插件。如果我使用 WCFStorm 测试此服务,一切正常。我马上得到回应。当我尝试使用加载插件的应用程序的服务时,我超时了。

ProgrammingMaster_ServiceClient aClient = new ProgrammingMaster_ServiceClient();
aClient.Endpoint.Address = new EndpointAddress("http://localhost:8081/ProgrammingMaster/PM_Service");
aClient.BeginProgrammingSession(0x01);
aClient.Close();

是我用来使用服务的代码。 ProgrammingMaster_SErviceClient由svcutil.exe生成。

如果我删除这条线,我会遇到同样的问题

aClient.Endpoint.Address = new EndpointAddress("http://localhost:8081/ProgrammingMaster/PM_Service");

我不太确定应该从哪里开始调试它。

被调用的服务在不同的网络上发送消息。当我通过 wcfstorm 调用它时,我可以看到服务发送的消息。所以我知道该服务正常工作。

当我从导致超时的应用程序调用服务时,我做错了什么。

编辑:超时过期后(我正在捕获并记录异常),服务会像预期的那样在其他网络上发送消息。

编辑 2:希望这是一个更好的解释。

所以我有一个公开网络服务并使用不同网络服务的插件。 所以插件基本上连接到一个特殊网络上的对象,然后通过使用网络服务传递该对象的属性值。

我有一个应用程序公开了插件用来更新远程对象值的 Web 服务,并使用了插件公开的 Web 服务以将命令传递给远程对象。

插件向应用程序发送更新时没有超时问题。当应用程序使用 Web 服务通过插件向远程对象发送命令时,出现超时错误。超时到期后,将执行命令。所以 Web 服务被成功调用。我想我只是没有收到回复?

编辑 3: 这是我的应用程序配置文件。我将发送超时降低到 00:00:01,这样等待时间就不会那么长,但我真的很想修复它,这样它就不必每次都超时。

<?xml version="1.0"?>
<configuration>
  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="WSHttpBinding_IProgrammingMaster_Service" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:00:01" 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="">
              <extendedProtectionPolicy policyEnforcement="Never"/>
            </transport>
            <message clientCredentialType="Windows" negotiateServiceCredential="true" algorithmSuite="Default" establishSecurityContext="true"/>
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:8081/ProgrammingMaster/PM_Service" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IProgrammingMaster_Service" contract="IProgrammingMaster_Service" name="WSHttpBinding_IProgrammingMaster_Service">
        <identity>
          <userPrincipalName value="mzjkk7@nam.corp.gm.com"/>
        </identity>
      </endpoint>
    </client>
  </system.serviceModel>
<startup useLegacyV2RuntimeActivationPolicy="true">
  <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>

最佳答案

哦...

yes the time out only happens when the client and server are both part of the same application.

重要的问题是客户端和服务是否在同一个线程上运行?

如果是这样,那可能是您的问题。尝试在自己的线程中启动服务,看看是否能解决问题。

关于c# - WCF 服务超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4761079/

相关文章:

.net - WCF - 如何增加消息大小配额

ios - 通过 JSON 作为字节数组发送图像数据

c# - AppFapric 是否成熟可用于生产

c# - 这两个语句(asp.net/c#/entity框架)有什么区别

c# - 如何以编程方式在 OpenOffice.org 中保存文档?

c# - 将不同类型的对象传递给非托管函数

c# - WCF,从请求中检索信息,找不到时间戳

c# - 为什么 LINQ 返回的列值不是预期的?

c# - PdfContentByte.SetFontAndSize() 抛出 "Object reference not set to instance of object"

C#、WCF、何时重用客户端代理