Lijo
Lijo

Reputation: 375

WCF: Using multiple bindings for a single service

I have a WCF service (in 3.0) which is running fine with wsHttpBinding. I want to add netTcpBinding binding also to the same service. But the challenge that I am facing is in adding behaviorConfiguration.

How should I modify the following code to enable the service for both the bindings? Please help…

  <service name="Lijo.Samples.WeatherService"
           behaviorConfiguration="WeatherServiceBehavior">

    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8000/ServiceModelSamples/FreeServiceWorld"/>
        <add baseAddress="net.tcp://localhost:8052/ServiceModelSamples/FreeServiceWorld"/>
        <!-- added new baseaddress for TCP-->
      </baseAddresses>
    </host>

    <endpoint address=""
              binding="wsHttpBinding"
              contract="Lijo.Samples.IWeather" />

    <endpoint address=""
              binding="netTcpBinding"
              contract="Lijo.Samples.IWeather" />
    <!-- added new end point-->

    <endpoint address="mex"
              binding="mexHttpBinding"
              contract="IMetadataExchange" />

  </service>


</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="WeatherServiceBehavior">
      <serviceMetadata httpGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="False"/>
    </behavior>
  </serviceBehaviors>
</behaviors>

Please see the following to see further details WCF using windows service

Thanks

Lijo

Upvotes: 1

Views: 1015

Answers (2)

marc_s
marc_s

Reputation: 754478

I don't completely understand what your problem or issue is - from what I'm understanding, you're unsure how to apply service behaviors?

Two things you need to consider:

  • a service behavior can be applied to the entire <service> tag - so these things like metadata support etc. will affect the service per se - regardless of which endpoint you connect to

  • an endpoint behavior can be applied to an endpoint, so that will affect only those endpoints that this behavior is applied to (and not others)

So in your case, the WeatherServiceBehavior will be applied to the service and thus affect all endpoints (e.g. no matter which endpoint your client connects to, it will have metadata support and debug details turned off).

So again: what exactly is your issue? Where are you "blocked" or what are you trying to do that doesn't work??

Upvotes: 1

Shiraz Bhaiji
Shiraz Bhaiji

Reputation: 65391

You should specify the address of the net tcp endpoint, at the endpoint level, not as a base address.

Also test if first with just nettcp binding to make sure that that works, before you try to configure for both.

Upvotes: 0

Related Questions