0

one guy said that it is possible " concrete class (which might even implement multiple service contracts)"

the link is here WCF: Why is Contract on Endpoint and not on Service?

i knew that we can have only one service contract for a single service but never heard that multiple service contract implementation with single service class. just tell me is it possible ? if yes can anyone redirect me to a complete sample code from where i can see multiple service contract implementation with single service class. thanks

Community
  • 1
  • 1
Thomas
  • 33,544
  • 126
  • 357
  • 626

2 Answers2

1

Agree with previous answer, this is the way how to implement two contracts. It can be used for security purpose, restricting responsibility zone for each endpoint, sharing resources for different endpoints.. Following the links you can find detailed descriptions:

Host multiple contracts in one WCF service

Run WCF ServiceHost with multiple contracts

WCF how to bind multiple service contracts?

Example with configuration from MSDN:

http://msdn.microsoft.com/en-us/library/ms751424(v=vs.110).aspx

Community
  • 1
  • 1
Igor Tkachenko
  • 1,120
  • 7
  • 17
  • i knew that only one contract is possible for a single service...was it wrong? when & why people would write multiple service contract for a single service. please discuss the situation. thanks – Thomas Apr 11 '14 at 13:46
  • There is no requirement that you can implement only one interface. Moreover, there is a situation when you need to implement few interfaces. 1. It can be done for visioning. If you want to extend your current service, it's not recommended to change the interface. The better option is to add new one. http://msdn.microsoft.com/en-us/library/ff384251.aspx

    http://msdn.microsoft.com/en-us/library/ms731060(v=vs.110).aspx (Appendix section)

    – Igor Tkachenko Apr 11 '14 at 14:38
  • 2. You have logically the same operation. Let's say something related to order. But you want to expose to the first client operation1, operation2, and for client2 you want to expose operation3, operation4. Implementing few interfaces will allow you to declare an endpoint for each interface. – Igor Tkachenko Apr 11 '14 at 14:46
  • 3. You have unique resource with one point of control. Let's say you have a Cache, instantiating type for your service is singleton (or more production version is you have a factory for creating instance and it injects singleton cache instance). In that case you will have access to this unique resource from implementation of both interfaces. – Igor Tkachenko Apr 11 '14 at 14:51
0

Yes it is possible, here is an example from excellent Programming WCF services book:

[ServiceContract]
interface IMyContract
{
   [OperationContract]
   string MyMethod();
}
[ServiceContract]
interface IMyOtherContract
{
   [OperationContract]
   void MyOtherMethod();
}

class MyService : IMyContract,IMyOtherContract
{
   public string MyMethod()
   {...}
   public void MyOtherMethod()
   {...}
}
Konrad Kokosa
  • 16,563
  • 2
  • 36
  • 58
  • then how config file would look like because in config file we always mention contract name.give me a valid config entry for my scenario. – Thomas Apr 11 '14 at 12:50