tags:

views:

28

answers:

2

I have a MyService class implementing IService1 and IService2 interfaces. I would like to expose these two contracts on two separate endpoints, like:

  • IService1 exposed on /Service/S1
  • IService2 exposed on /Service/S2

How would such a config look like?

+2  A: 

Try this....

<services>      
  <service name="Service">
    <endpoint address="http://localhost:8080/Service/S1"
              binding="basicHttpBinding"
              contract="IService1"

     />

    <endpoint address="http://localhost:8080/Service/S2"
              binding="basicHttpBinding"
              contract="IService2 "

     />
  </service>
</services>
Nix
That doesn't seem to be what I'm looking for. MyService class is a class that implements both of the interfaces: IService1 and IService2. According to http://msdn.microsoft.com/en-us/library/ms731303.aspx service.name attribute has to map to a type name. If MyService is the only type implementing the contracts, it can't be used twice in the config.
Marcin Seredynski
@Marcin Seredynski: you're right - the service **class** cannot be used twice in the config - only one <service name="service"> possible. **BUT:** you can still define **TWO SEPARATE ENDPOINTS** on two separate addresses, one for each of the **CONTRACTS** that the service class implements - that's what you're looking for, no??
marc_s
+1  A: 

You can just use a service with two endpoints, like this:

<services>      
  <service name="MyNamespace.MyService">
    <endpoint address="/Service/S1"
              binding="basicHttpBinding"
              contract="IService1" />
    <endpoint address="/Service/S2"
              binding="basicHttpBinding"
              contract="IService2 " />
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8080/"/&gt;
      </baseAddresses>
    </host>
  </service>
</services>

EDIT: Added base address

Johann Blais
For some reason this approach doesn't want to work: Service cannot be started. System.InvalidOperationException: Could not find a base address that matches scheme http for the endpoint with binding BasicHttpBinding. Registered base address schemes are [].
Marcin Seredynski
Just a note, I'm instantiating ServiceHost by passing it an instance of the service and an endpoint Uri.
Marcin Seredynski
True, I have updated my answer accordingly.
Johann Blais