Rishabh Verma
Rishabh Verma

Reputation: 117

How to expose a single WCF service with multiple service behaviours?

I have a WCF service which needs to meet the following requirement:

  1. Endpoint1 : It should use netTCP binding with windows authentication.
  2. Endpoint2 : It should use netTCP binding with Custom User name and password validation.

I was able to do both of these individually by creating two service behaviors, one for Windows authentication and one for user name and password, but this way I have to expose 2 service instead of 1 for the above functionality. I am looking for a way by which I could expose only one service and by different end point configuration, I am able to fulfill the requirement.

Code snippet and configuration would be helpful.

Upvotes: 4

Views: 2601

Answers (1)

Shiraz Bhaiji
Shiraz Bhaiji

Reputation: 65461

This is one of the scenarios that WCF supports, a single interface exposed as 2 different endpoints.

They will have two different addresses, but will point to the same code.

<service 
    name="Microsoft.ServiceModel.Samples.CalculatorService"
    behaviorConfiguration="CalculatorServiceBehavior">
    <!-- This endpoint is exposed at the base address provided by host:       http://localhost/servicemodelsamples/service.svc  -->
   <endpoint address=""
        binding="basicHttpBinding"
        contract="Microsoft.ServiceModel.Samples.ICalculator" />
   <!-- secure endpoint exposed at {base address}/secure:       http://localhost/servicemodelsamples/service.svc/secure -->
  <endpoint address="secure"
        binding="wsHttpBinding"
        contract="Microsoft.ServiceModel.Samples.ICalculator" />
  ...
</service>

See: http://msdn.microsoft.com/en-us/library/ms751515.aspx

Upvotes: 2

Related Questions