WCF代理关闭basicHttpBinding - 帮助解释行为

时间:2012-09-07 09:39:02

标签: .net wcf proxy basichttpbinding

我在WCF服务上有以下代码,我正在使用 basicHttpBinding

public class Service1 : IService1
{
        public string GetData(int value)
        {
            // Sleep for a minute
            System.Threading.Thread.Sleep(60000);
            return string.Format("You entered: {0}", value);
        }
}



我在客户端上有以下代码,客户端的“sendTimeout”只有1秒(我希望客户端在服务器响应之前超时)

Service1Client clientProxy = new Service1Client();
        try
        {

            Console.WriteLine(clientProxy.GetData(10));
            clientProxy.Close();
        }            
        catch (TimeoutException)
        {
            if (((ICommunicationObject)clientProxy).State == CommunicationState.Opened)
            {
                // In the case of TimeoutException the state is not faulted and 
                // "close" is invoked
                clientProxy.Close();
            }
        }        



我在IIS日志中看到的请求是:

  

2012-09-07 07:22:51 :: 1 POST /SimpleTimeWCF/Service1.svc - 80 - :: 1 -   200 0 64 60015

您可以观察到状态为200且sc-win32-status为64且时间为60015(大约一分钟)。

当WCF服务忙于处理请求时,客户端已调用clientProxy.Close。服务器上的预期行为是什么?

使用basicHttpBinding时,服务器上“客户端代理关闭”方法调用的预期行为是什么?

使用其他绑定时行为是否会发生变化?例如:Net TCP绑定?当我们使用net tcp绑定时,是否在代理上调用“close”结束与服务器建立的“tcp连接”?

PS:请注意,我已将IIS上的Enable HTTP Keep-alive设置为false

1 个答案:

答案 0 :(得分:1)

该服务将从客户端获取请求。它将处理请求,耗时60秒。客户端在同一时间“放弃”,但是使用HTTP,它无法通知服务不再需要先前的请求。

最后,服务:

相关问题