开发者

Is it possible sccessing a subset of a WCF service operations

I have the following doubt: Consider the following:

/* 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);
}

And the following:

/* My server will implement a complex great 
   service made of the previously introduced subservices. */
[ServiceContract]
public interface IMyService : IMySubService1, IMySubService2, IMySubService3 {
}

well, I will implement my service:

// Implementing the service
public class MyService : IMyService {
   ...
}

OK! Up until now, nothing strange! My service will be hosted on a server and I am happy :) The service is hosted (as example) on a svc file, but remember the service is IMyService.

Now let's get to the point: In my client I would like to create a client in order to get access JUST TO A SUBSET of my service. Given that my service is the usion of three subservices, I would like to access only one subservice.

For example, my client is interested in IMySubService1 Can I do the following?

ServiceEndpoint httpEndpoint = new ServiceEndpoint(
   ContractDescription.GetContract(typeof(IMySubService1)), 
   new BasicHttpBinding(), 
   new EndpointAddress("http://tempuri.org/MyService.svc/ServiceCall")
   );
ChannelFacto开发者_如何学Pythonry<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");

Is this possible???


OK! Finally I tried it!

IT CAN BE DONE!!! Exactly in the same manner as I showed in my question.


Hm, interesting. Off the top of my head it looks like it should work as along as the ServiceContract attribute's Name and Namespace properties are set on the smaller sub-contracts. The values should match whatever the service is expecting for the composed contract.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜