Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How many ServiceContracts can a WCF service have?

How many ServiceContracts can a WCF service have?

Specifically, since a ServiceContract is an attribute to an interface, how many interfaces can I code into one WCF web service? Is it a one-to-one?

Does it make sense to separate the contracts across multiple web services?

like image 720
jdiaz Avatar asked Aug 28 '08 07:08

jdiaz


Video Answer


1 Answers

WCF services can have multiple endpoints, each of which can implement a different service contract.

For example, you could have a service declared as follows:

[ServiceBehavior(Namespace = "DemoService")]
public class DemoService : IDemoService, IDoNothingService

Which would have configuration along these lines:

<service name="DemoService" behaviorConfiguration="Debugging">
  <host>
    <baseAddresses>
      <add baseAddress = "http://localhost/DemoService.svc" />
    </baseAddresses>
  </host>
  <endpoint 
    address =""
    binding="customBinding"
    bindingConfiguration="InsecureCustom"
    bindingNamespace="http://schemas.com/Demo" contract="IDemoService"/>
  <endpoint 
    address =""
    binding="customBinding"
    bindingConfiguration="InsecureCustom"
    bindingNamespace="http://schemas.com/Demo" contract="IDoNothingService"/>
</service>      

Hope that helps, but if you were after the theoretical maximum interfaces you can have for a service I suspect it's some crazily large multiple of 2.

like image 134
Ubiguchi Avatar answered Oct 14 '22 09:10

Ubiguchi