2

我对 WCF 服务实例有一些问题。

ChannelFactory<IMyInterface> factory = new ChannelFactory<IMyInterface>(new NetTcpBinding(), new EndpointAddress("net.tcp://localhost:8000"));

IMyInterface iFirst = firstFactory.CreateChannel();
iFirst.firstMethod();

IMyInterface iSecond = firstFactory.CreateChannel();
iSecond.secondMethod();

它工作正常,但在服务器端创建了两个服务类实例。 InstanceContextMode设置为InstanceContextMode.PerSession,我想保持这种状态。我找到了这篇文章:

http://msdn.microsoft.com/en-us/magazine/cc163590.aspx#S4

部分Duplicating a Proxy是图 5 复制代理。我似乎是完美的解决方案,但IClientChannel不再包含ResolveInstance()方法。有没有其他方法可以创建连接到一个服务实例的两个通道而不设置InstanceContextModeInstanceContextMode.Single

4

1 回答 1

1

IClientChannel.ResolveInstance 方法已替换为新的扩展点 System.ServiceModel.Dispatcher.IInstanceContextProvider 接口。

此处描述了更改:http: //blogs.msdn.com/b/mahjayar/archive/2006/07/08/660176.aspx - 也许您可以实现该接口以获得您想要实现的目标。

于 2011-12-22T08:12:06.567 回答