Search code examples
wcfwcf-endpointservicecontract

Multiple endpoint with multiple contracts in WCF


Hi I have 2 service contracts IService1 and IService2

I want different endpoints for each service contract also I want to use only basichttpbinding.

Suppose IService1 address is http://localhost:4040/MyApp/Service1.svc then

I want to access IService2 with address http://localhost:4040/MyApp/Service1.svc/service2 or with address other than IService1 address

Is it possible ?


Solution

  • Are you hosting this in IIS ?? If so: IIS dictates your addresses - they're defined as

    http://YourServer/YourVirtualDirectory/YourService.svc
    

    So if you want two separate addresses, you need two separate virtual directories....

    Or: self-host, then you have full freedom of addresses!

    If you self-host, you could definitely define a service (implementing both service interfaces in the same implementation class) that exposes two endpoints:

    <services>
       <service name="YourNamespace.ServiceImplementationClass">
          <host>
             <baseAddresses>
                <add baseAddress="http://localhost:4040/MyApp/Service1.svc" />
             </baseAddresses>
          </host>
          <endpoint name="Service1"
              address=""
              binding="basicHttpBinding"
              contract="YourNamespace.IService1" />
          <endpoint name="Service2"
              address="Service2"
              binding="basicHttpBinding"
              contract="YourNamespace.IService2" />
       </service>
    </services>
    

    So your service 1 would be accessible at the base address defined (http://localhost:4040/MyApp/Service1.svc), while your service 2 would be at http://localhost:4040/MyApp/Service1.svc/Service2. Is that what you're looking for??