【发布时间】:2011-12-10 03:56:46
【问题描述】:
我目前正在开发一个 wcf 发布订阅服务。在我的 Windows 窗体应用程序中,我有一个尝试订阅该服务的连接按钮。代码如下
WSDualHttpBinding binding = (WSDualHttpBinding)client.Endpoint.Binding;
string clientcallbackaddress = binding.ClientBaseAddress.AbsoluteUri;
clientcallbackaddress += Guid.NewGuid().ToString();
binding.ClientBaseAddress = new Uri(clientcallbackaddress);
InstanceContext site = new InstanceContext(null, new mainForm(backgroundFormObject));
PostingContractClient client = new PostingContractClient(site);
client.Subscribe();
MessageBox.Show("Service has been connected!", "Connected");
至于异常处理,这是我做的,
try
{
//refer to codes above
}
catch (EndpointNotFoundException)
{
MessageBox.Show("WCF Service has not been started.", "Error");
}
catch (CommunicationException)
{
MessageBox.Show("Error");
}
如果我的服务未激活,单击连接按钮后,它将加载一段时间,然后发送第一个错误“WCF 服务尚未启动”。 ,然后我激活服务,单击连接按钮会显示第二个错误,即 CommunicationException,尽管我的服务已打开。
知道如何解决这个问题吗?
错误的错误信息
通信对象 System.ServiceModel.Channels.ServiceChannel 无法用于通信,因为它处于故障状态。
【问题讨论】:
-
CommunicationException 的错误信息是什么意思,是否存在内部异常?
-
嗨。用错误消息更新了我上面的帖子。谢谢
标签: wcf exception exception-handling