1

给定一个有效的 Binding 和 EndpointAddress,我有一个 WCF Duplex ChannelFactory,如下所示:

NetTcpBinding svcBinding = new NetTcpBinding();
svcBinding.ReliableSession.Enabled = true;
EndpointAddress svcEndpointAddress = new EndpointAddress(new Uri("net.tcp:// + ServiceAddress + "/Service"), EndpointIdentity.CreateDnsIdentity(UserPrincipalName));

DuplexChannelFactory dcf = new DuplexChannelFactory<IService>(new InstanceContext(this), svcBinding);
dcf.Opened += OnCommunicationOpened;
dcf.Faulted += OnCommuicationFaulted;
IService svc = dcf.CreateChannel(svcEndpointAddress);

public void OnCommunicationOpened(object sender, EventArgs e)
{
    // do something . . .
}

public void OnCommunicationFaulted(object sender, EventArgs e)
{
    // do something else . . .
}

打开的事件触发没有问题,但是当我关闭我的服务时,错误的事件没有触发。如何让 Faulted 事件触发?

4

0 回答 0