我有几个内部wcf服务。我需要创建一个仅包含来自内部服务的选定操作的外部服务。我不想使用复制/粘贴技术。我找到sentinet,但我认为这是一个庞大而昂贵的解决方案。是否有便宜而简单的解决方案?
答案 0 :(得分:1)
您可以使用界面继承来构建内部服务,并重新安排外部服务的公共部分。
一个例子:
[ServiceContract()] public interface IInternalService1 : IInternalService1Public, IInternalService1Private { }
[ServiceContract()] public interface IInternalService1Public { }
[ServiceContract()] public interface IInternalService1Private { }
[ServiceContract()] public interface IInternalService2 : IInternalService2Public, IInternalService2Private { }
[ServiceContract()] public interface IInternalService2Public { }
[ServiceContract()] public interface IInternalService2Private { }
[ServiceContract()] public interface IPublicService : IInternalService1Public, IInternalService2Public { }
答案 1 :(得分:1)
public interface IService1 {
void Operation1();
void Operation2();
}
public class Service1 : IService1 {
public void Operation1() { }
public void Operation2() { }
}
public interface IService2 {
void Operation3(String s);
Int32 Operation4(Int32 n);
}
public class Service2 : IService2 {
public void Operation3(string s) {
}
public int Operation4(int n) {
return 0;
}
}
public interface IMyPublicInterface {
void Operation1();
Int32 Operation4(Int32 n);
}
public class MyPublicInterface : IMyPublicInterface {
public MyPublicInterface(IService1 service1, IService2 service2) {
_service1 = service1;
_service2 = service2;
}
private IService1 _service1;
private IService2 _service2;
public void Operation1() {
return _service1.Operation1();
}
public int Operation4(int n) {
return _service2.Operation4(n);
}
}