ServiceHost是否不分离端点?无法从故障状态中恢复 [英] ServiceHost does not detach endpoints? Can't recover from a Faulted state

查看:99
本文介绍了ServiceHost是否不分离端点?无法从故障状态中恢复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的服务启动代码:

public void Start()
{
    try
    {

	var certificate = new X509Certificate2(certpath, "");

	String uri = "net.tcp://" + WCFAddress + "/CommunicationService";
	Uri baseaddress = new Uri(uri);

	if (WebService != null)
	{
	    if (WebService.State!= CommunicationState.Faulted)
		WebService.Close();
	    else
		WebService.Abort();
	    WebService = null;
	}

	WebService = new ServiceHost(MessageProvider, baseaddress);
	WebService.Credentials.ServiceCertificate.Certificate = certificate;
	WebService.Credentials.ClientCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;

	NetTcpBinding binding = new NetTcpBinding();
	binding.Security.Mode = SecurityMode.Message;
	binding.Security.Message.ClientCredentialType = MessageCredentialType.Certificate;
	binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Certificate;
	WebService.AddServiceEndpoint(typeof(IMessageService), binding, baseaddress);

	WebService.Open();
    }
    catch (Exception e)
    {
    	//Exception handling
    }
}

推荐答案

您好,您是说您正在调用一个不会退出的服务,该服务失败了,后来您调用了一个能够正常工作的服务但它也会失败吗?这应该不会发生...您能否确保在第一次调用正确的服务时也没有例外 被抛出?
Hello, do you mean you're calling a service that doesn't exit, which fails, later you call a service that used to work fine but it fails as well? This should not happen... Can you make sure the first time when you call the correct service, no exception is thrown?


这篇关于ServiceHost是否不分离端点?无法从故障状态中恢复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆