У меня есть следующие сомнения: Рассмотрим следующее:
/* My service is formed by several subservices
(subfunctionalities). Here is functionality 1 */
[ServiceContract]
public interface IMySubService1 {
[OperationContract]
int MyOp11(string opnd);
[OperationContract]
int MyOp12(stirng opnd);
}
/* My service is formed by several subservices
(subfunctionalities). Here is functionality 2 */
[ServiceContract]
public interface IMySubService2 {
[OperationContract]
int MyOp21(string opnd);
[OperationContract]
int MyOp22(stirng opnd);
}
/* My service is formed by several subservices
(subfunctionalities). Here is functionality 3 */
[ServiceContract]
public interface IMySubService3 {
[OperationContract]
int MyOp31(string opnd);
[OperationContract]
int MyOp32(stirng opnd);
}
И следующее:
/* My server will implement a complex great
service made of the previously introduced subservices. */
[ServiceContract]
public interface IMyService : IMySubService1, IMySubService2, IMySubService3 {
}
Хорошо, я реализую свой сервис:
// Implementing the service
public class MyService : IMyService {
...
}
OK!До сих пор ничего странного!Мой сервис будет размещен на сервере, и я счастлив :) Сервис размещен (как пример) в файле svc, но помните, что сервис IMyService
.
Теперь давайте перейдем к вопросу: Вмой клиент Я хотел бы создать клиента, чтобы получить доступ ТОЛЬКО К ПОДУШКЕ моей услуги.Учитывая, что мой сервис состоит из трех вспомогательных служб, я хотел бы получить доступ только к одному вспомогательному обслуживанию.
Например, мой клиент интересуется IMySubService1
Могу ли я сделать следующее?
ServiceEndpoint httpEndpoint = new ServiceEndpoint(
ContractDescription.GetContract(typeof(IMySubService1)),
new BasicHttpBinding(),
new EndpointAddress("http://tempuri.org/MyService.svc/ServiceCall")
);
ChannelFactory<IMySubService1> channelFactory =
new ChannelFactory<IMySubService1>(httpEndpoint);
IMySubService1svc = channelFactory.CreateChannel();
/* Calling methods in IMySubService1 */
int i1 = svc.MyOp11("A string");
int i2 = svc.MyOp12("Another string");
int i3 = svc.MyOp11("And another string");
int i4 = svc.MyOp12("In the end a string");
int i5 = svc.MyOp11("The final string");
Возможно ли это?