需要一种方法让知名端点上的服务返回相对地址的字符串。然后客户端可以使用这些相对地址连接到端点。显然,这在某些方面类似于 REST,但在这种情况下,使用 NetNamedPipeBinding for IPC 运行 Windows 服务,因此不需要 HTTP。
不想提前创建端点,因为可能会有大量的相对地址,只有其中一些是客户感兴趣的。
所有合同都是事先知道的。
尝试使用AddressFilterMode找到解决方案,但不确定如何设置新的 Binding 以便客户端连接到UriTemplate但不想使用 HTTP 框架。由于受限于 .Net 3.5,因此尚未研究RoutingService 。
客户端的伪代码如下所示...
namespace Testing
{
class RunTest
{
static void Test()
{
NetNamedPipeBinding namedpipe = new NetNamedPipeBinding();
ChannelFactory<Contracts.IRoot> factoryRoot =
new ChannelFactory<Contracts.IRoot>(
namedpipe
, new EndpointAddress("net.pipe://localhost/root");
);
Contracts.IRoot root = factoryRoot.CreateChannel();
ICommunicationObject commsRoot = root as ICommunicationObject;
commsRoot.Open();
// Service examines address and creates Endpoint dynamically.
string address = root.SomeFunctionWhichGetsARelativeAddress();
// IBar service routes endpoint requests internally based on
// "address" variable.
ChannelFactory<Contracts.IBar> factoryBar =
new ChannelFactory<Contracts.IBar>(
namedpipe
, new EndpointAddress("net.pipe://localhost/root/IBar/" +
address)
);
Contracts.IBar bar = factoryBar.CreateChannel();
bar.DoSomething();
}
} // Ends class RunTest
} // Ends namespace Testing