开发者

WCF inter server code does not trigger TCP timeouts and Faults

开发者 https://www.devze.com 2023-03-27 11:13 出处:网络
I\'ve tried to make an inter-server communication protocol with WCF. But for some reason, when a server disconnects, the Faulted neither the Closed events are called. This is really annoying but I hav

I've tried to make an inter-server communication protocol with WCF. But for some reason, when a server disconnects, the Faulted neither the Closed events are called. This is really annoying but I haven't found a solution to it.

private static ServiceHost loginService;
static void Load() {
    login开发者_JS百科Service = new ServiceHost(typeof(LoginService), new Uri[] { new Uri(Settings.Instance.LoginServiceURI) });
    loginService.AddServiceEndpoint(typeof(ILoginService), ServiceHelpers.GetBinding(new Uri(Settings.Instance.LoginServiceURI)), Settings.Instance.LoginServiceURI);
    loginService.Faulted += new EventHandler(loginService_Faulted);
    loginService.Open();
}

static void loginService_Faulted(object sender, EventArgs e)
{
    Log.WriteLine(LogLevel.Error, "LoginWCF Faulted. Restarting.");
    loginService.Close();
    Load();
}

The stupid thing is that only the functions inside the ILoginService interface will throw an exception when the connection died. I thought that TCP had a keep-alive of it's own?


As of now, I haven't find a way to determine whether the channel is faulted or closed until it makes a call and gets the exception. Only when it causes an exception, the status is set to Faulted, because this status is set in CommunicationObject.Fault method that is invoked when there is exception.

The Closed event will be fired out when CommunicationObject.Close is invoked.


Not all, but some wcf bindings (WsHttp & NetTcp for example) support reliable sessions, check http://msdn.microsoft.com/en-us/library/ms733136.aspx. It can be used to detect when the service is going down

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号