Question

Using the example from github, setting up a simple wcf service hosted in a windows service works fine. However, when I add another servicecontract implementation, I'm not able to host this under the same baseAddress, i.e from app.config:

<service name="ContractService" behaviorConfiguration="WebServicesBehavior">
  <host>
    <baseAddresses >
      <add baseAddress="baseUri"/>
    </baseAddresses>
  </host>
  <endpoint address="addr1" binding="wsHttpBinding" contract="IContract1"/>
  <endpoint address="addr2" binding="wsHttpBinding" contract="IContract2"/>
  <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"  />
</service>

I'm able to host 2 services, using this example, however I would like to achieve to have multiple service contracts hosted within the same baseAddress and possible multiple endpoints, but my search for solutions to this have left me stranded.

This setup works:

<services>
  <service name="ContractService1" behaviorConfiguration="WebServicesBehavior">
    <host>
      <baseAddresses >
        <add baseAddress="http://localhost:8082/Services/"/>
      </baseAddresses>
    </host>
    <endpoint address="addr1" binding="wsHttpBinding" contract="IContract1"/>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"  />
  </service>
  <service name="ContractService2" behaviorConfiguration="WebServicesBehavior">
    <host>
      <baseAddresses >
        <add baseAddress="http://localhost:8083/Services/"/>
      </baseAddresses>
    </host>
    <endpoint address="addr2" binding="wsHttpBinding" contract="IContract2"/>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"  />
  </service>
</services>

The wireup using ninject is the same as in the github example.

Is there a way to achieve multiple endpoint using selfhost wcf with ninject?

Was it helpful?

Solution

You can have multiple services on the same port by specifying different baseAddresses for the same port.

Append the address from the endpoint definition to the base address for each of the services like so:

<add baseAddress="http://localhost:8083/Services/addr1"/>

<endpoint address="" binding="wsHttpBinding" contract="IContract1"/>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top