我在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()
方法。有没有其他方法可以创建连接到一个服务实例的两个频道而不将InstanceContextMode
设置为InstanceContextMode.Single
?
答案 0 :(得分:1)
IClientChannel.ResolveInstance方法已替换为新的可扩展性点System.ServiceModel.Dispatcher.IInstanceContextProvider接口。
此处描述了更改:http://blogs.msdn.com/b/mahjayar/archive/2006/07/08/660176.aspx - 也许您可以实现该接口以获得您想要实现的目标。