操作' Ping'无法完成,因为会话通道超时等待接收消息错误

时间:2016-03-09 21:01:27

标签: c# wcf exception callback timeout

我有一个客户端 - 服务器应用程序,客户端访问wcf服务 我还有一个KeepAlive计时器。当计时器过去时 - WS发送客户端Callback.Ping请求,以确保客户端仍处于活动状态。
由于某种原因,当连接两个(或更多)客户端时,其中一个客户端在尝试执行Callback.Ping时会崩溃,并获得以下异常:

  

操作' Ping'由于会议无法完成   频道超时等待接收消息。要增加   timeout,要么在绑定中设置receive Timeout属性   你的配置文件,或者在上面设置ReceiveTimeout属性   直接绑定。

我提到客户端和WS配置文件都声明为receiveTimeout, sendTimeout, openTimeout and closeTimeout,设置为10:00:00分钟。

有人可以帮我解决我的问题吗?

修改
app.config(客户端):

<system.serviceModel>
<bindings>
  <wsDualHttpBinding>
    <binding name="WSDualHttpBinding_IRouterClient" receiveTimeout="10:00:00" sendTimeout="10:00:00" openTimeout="10:00:00" closeTimeout="10:00:00"/>
  </wsDualHttpBinding>
</bindings>
<client>
  <endpoint address="xxx.svc"
            binding="wsDualHttpBinding" bindingConfiguration="WSDualHttpBinding_IRouterClient"
            contract="Client.IRouterClient"
            name="WSDualHttpBinding_IRouterClient">
  </endpoint>
</client>
</system.serviceModel>

Web.config(服务器):

<system.serviceModel>
<behaviors>
  <serviceBehaviors>
    <behavior name="">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />


<services>
  <service name="xxx.WS.RouterClient">
    <endpoint address="" binding="wsDualHttpBinding" contract="xxx.WS.IRouterClient" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
  </service>
</services>

<bindings>
  <wsDualHttpBinding>
    <binding openTimeout="00:00:20" closeTimeout="00:00:20" sendTimeout="00:00:10" receiveTimeout="00:05:00"/>
  </wsDualHttpBinding>
</bindings> 
</system.serviceModel>

当计时器结束时,服务会调用Ping:

public class SubscribedCustomer
{
    public IServerCallback Callback;

    public SubscribedCustomer(IServerCallback callback)
    {
        Callback = callback;
    }

    public void Ping(List<int> itemIds, IServerCallback serverCallback = null)
    {
    try
    {
        Callback.Ping(itemIds);
    }
    catch (Exception ex)
    {
        if (serverCallback != null)
            {
                Callback = serverCallback;
                //recursive call with the new servercallback set
                Ping(itemIds);
            }
            else
            {
                SetClientNotRunning("No reply from client");
            }
        }
    }
}

服务器合同:

public interface IServerCallback
{
    [OperationContract(IsOneWay = true)]
    void Ping(List<int> itemIds);
}

谢谢!

0 个答案:

没有答案