未调用 WCF 方法

发布于 2024-09-29 07:27:28 字数 326 浏览 0 评论 0原文

我有一个非常奇怪的问题。我有一个 WCF 服务和一个调用其中一些方法的控制台应用程序。在某些时候,它无法再调用其中之一。它只是调用该方法,但从未进入该方法。它只是等啊等……什么也没有发生。

我应该以某种方式刷新服务客户端吗?我尝试创建一个新的服务客户端对象

QueryingServiceClient queryingClient = new QueryingServiceClient();

,然后再次调用该方法,但它不起作用。只是补充一下,在该方法停止工作之前,我多次调用该方法和其他几个方法。

有什么想法吗?

谢谢。

I have a very strange problem. I have a WCF service and a console application that invokes some of it methods. At some point, it can't invoke one of them any more. It just calls the method, but it never enters it. It just waits and waits.. and nothing ever happens.

Should I maybe somehow refresh the service client? I tried creating a new service client object

QueryingServiceClient queryingClient = new QueryingServiceClient();

and then to call the method again, but it didn't work. Just to add that I call that method and several other ones few times before it stops working.

Any ideas?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

不弃不离 2024-10-06 07:27:28

假设:

  • 您的服务使用会话实例模式(默认模式),
  • 您的客户端为每次对服务的调用创建一个新的代理实例。
  • 您的客户端在调用后不会处理代理。

问题可能是您耗尽了服务器上的可用槽数(在这种情况下是会话数),以至于达到了最大并发会话数。然后,您的客户端将根据定义的超时等待服务端关闭会话(在这种情况下显然永远不会发生)。

建议的修复:

  • 将 InstanceContextMode 设置为 PerCall,除非您确实需要 WCF 会话。
  • 使用后请务必关闭代理。

编辑:

using (var proxy = new Proxy())
{
    // Use the proxy as much as needed
    proxy.Method();
}

Assumptions:

  • your service uses the Session instance mode (the default mode)
  • your client creates a new instance of the proxy for every call it makes to the service.
  • your client does not dispose the proxies after the calls.

The problem is probably that you are depleting the number of available slots (sessions in that case) on the server to the point where you are reaching the maximum number of concurrent sessions. Then your client will wait depending on the defined timeout for a session to be closed on the service side (which obviously will never happen in that case).

Suggested fixes:

  • Set the InstanceContextMode to PerCall, unless you really need WCF sessions.
  • Always close your proxies after use.

EDIT:

using (var proxy = new Proxy())
{
    // Use the proxy as much as needed
    proxy.Method();
}
一人独醉 2024-10-06 07:27:28

停止前的次数是否相同?您是否已达到连接限制?

您的 WCF 服务是如何实例化的?

单例、会话、PerCall?

您可以发布您的客户端和服务器端点的配置部分吗?

如果您使用 WcfClient 工具,它的工作是否一致?

Is it the same number of times before it stops? Are you reaching a connection limit perhaps?

How is your WCF service instanced?

Singleton, Session, PerCall?

Could you post the config section for your client and server endpoint?

Does it work consistently if you use the WcfClient tool?

漫漫岁月 2024-10-06 07:27:28

这很奇怪,它不会一直等下去。您应该收到 WCF 超时异常。 app.config 中的超时值是多少?

如果您没有收到任何超时异常,则可能是您没有调用该服务方法。我知道这很明显,但有时名称很长的方法可能会相互混淆。不过,如果您也在调试客户端,那么您一定已经排除了这种可能性。

That's strange, it wouldn't wait and wait forever. You should be getting a WCF timeout exception. What is the timeout value in your app.config?

If you aren't getting any timeout exceptions, then it might be the case you aren't calling that service method. I know it's obvious but sometimes methods with long names can be confused for each other. If you are debugging the client too, you must have ruled that out, though.

孤凫 2024-10-06 07:27:28

感谢您的回复。

这不是永远,我没有正确表达自己。一段时间后,我得到以下异常:

已超出最大重试次数,且远程端点没有响应。可靠会话出现故障。这通常表明远程端点不再可用。

这是一个单例。这是 app.config 的一部分:

<system.serviceModel>
    <bindings>
          <wsHttpBinding>
                <binding name="WSHttpBinding_QueryingService" closeTimeout="00:25:00"
                      openTimeout="00:25:00" receiveTimeout="00:25:00" sendTimeout="00:25:00"
                      bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                      maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647"
                      messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
                      allowCookies="false">
                      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
                            maxArrayLength="2147483647" maxBytesPerRead="2147483647"
                            maxNameTableCharCount="2147483647" />
                      <reliableSession ordered="true" inactivityTimeout="00:25:00"
                            enabled="true" />
                      <security>
                            <transport>
                                  <extendedProtectionPolicy policyEnforcement="Never" />
                            </transport>
                      </security>
                </binding>
...

在提供者方面:

<wsHttpBinding>
    <binding name="wsHttpConfig" maxReceivedMessageSize="2147483647" receiveTimeout="00:25:00">
      <readerQuotas maxDepth="2147483647"
                    maxStringContentLength="2147483647"
                    maxArrayLength="2147483647"
                    maxBytesPerRead="2147483647"
                    maxNameTableCharCount="2147483647" />
      <reliableSession enabled="true" ordered="true" />
    </binding>
  </wsHttpBinding>

...

<service name="Platform.WSLA.Impl.Services.Querying.QueryingService"
           behaviorConfiguration="Default.Behavior">

    <endpoint address="http://localhost:8004/Platform/wsla/querying/QueryingService"
              binding="wsHttpBinding"
              bindingConfiguration="wsHttpConfig"
              contract="Platform.WSLA.Contracts.Services.Querying.IQueryingService" />
    <endpoint address="mex"
              binding="mexHttpBinding"
              name="MetadataExchange"
              contract="IMetadataExchange" />

    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8004/Platform/wsla/querying" />
      </baseAddresses>
    </host>

  </service>

Thanks for your replies.

It's not forever, I didn't express myself correctly. After some time I get the following exception:

The maximum retry count has been exceeded with no response from the remote endpoint. The reliable session was faulted. This is often an indication that the remote endpoint is no longer available.

It's a singleton. This is part of the app.config:

<system.serviceModel>
    <bindings>
          <wsHttpBinding>
                <binding name="WSHttpBinding_QueryingService" closeTimeout="00:25:00"
                      openTimeout="00:25:00" receiveTimeout="00:25:00" sendTimeout="00:25:00"
                      bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                      maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647"
                      messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
                      allowCookies="false">
                      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
                            maxArrayLength="2147483647" maxBytesPerRead="2147483647"
                            maxNameTableCharCount="2147483647" />
                      <reliableSession ordered="true" inactivityTimeout="00:25:00"
                            enabled="true" />
                      <security>
                            <transport>
                                  <extendedProtectionPolicy policyEnforcement="Never" />
                            </transport>
                      </security>
                </binding>
...

On the provider side:

<wsHttpBinding>
    <binding name="wsHttpConfig" maxReceivedMessageSize="2147483647" receiveTimeout="00:25:00">
      <readerQuotas maxDepth="2147483647"
                    maxStringContentLength="2147483647"
                    maxArrayLength="2147483647"
                    maxBytesPerRead="2147483647"
                    maxNameTableCharCount="2147483647" />
      <reliableSession enabled="true" ordered="true" />
    </binding>
  </wsHttpBinding>

...

<service name="Platform.WSLA.Impl.Services.Querying.QueryingService"
           behaviorConfiguration="Default.Behavior">

    <endpoint address="http://localhost:8004/Platform/wsla/querying/QueryingService"
              binding="wsHttpBinding"
              bindingConfiguration="wsHttpConfig"
              contract="Platform.WSLA.Contracts.Services.Querying.IQueryingService" />
    <endpoint address="mex"
              binding="mexHttpBinding"
              name="MetadataExchange"
              contract="IMetadataExchange" />

    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8004/Platform/wsla/querying" />
      </baseAddresses>
    </host>

  </service>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文