次の状況を考慮してください。
、、などの複数のインターフェースがあります...すべてのインターフェースはIService1
、単一のクラスによって実装されます。IService2
IService3
MainService
NetTcpBinding binding = new NetTcpBinding(SecurityMode.None, reliableSessionEnabled: true);
string address1 = "net.tcp://localhost:9000/ep1";
// create other addresses with ep2, ep3 and so on...
ServiceHost serviceHost = new ServiceHost(typeof(ServiceLibrary.MainService));
serviceHost.AddServiceEndpoint(typeof(IService1), binding, address1);
serviceHost.AddServiceEndpoint(typeof(IService2), binding, address2);
serviceHost.AddServiceEndpoint(typeof(IService3), binding, address3);
// and so on...
serviceHost.Open();
Console.WriteLine("Running...");
Console.ReadLine();
この時点で、このサービス ホスト インスタンスのエンドポイントが複数あります。クライアント インスタンスを作成するには、次のようにします --
NetTcpBinding binding = new NetTcpBinding(SecurityMode.None, reliableSessionEnabled: true);
string address = "net.tcp://...:9000/ep1";
ChannelFactory<ServiceLibrary.IService1> channelFactory = new ChannelFactory<IService1>(binding, address);
IService1 channel1 = channelFactory.CreateChannel();
// create other channel factories and other channels and now we have channel1, channel2, channel3
これらのチャネルは基本的に、関数を呼び出すことができるプロキシです。ただし、これらのプロキシはインターフェイス固有です。channel1
で定義されているメソッド以外のメソッドは呼び出されませんIService1
。
私が必要としているのは、任意のインターフェースで定義された任意のメソッドを呼び出すことができるスーパープロキシIService1
です。IService2
IService3
何か案は?
EDIT:単一のインターフェースが他のすべてのインターフェースを継承することは不可能です。サービスはすでに開発されており、私にできることはサービス ホストとチャネルの作成をいじることだけだと仮定しましょう。