views:

150

answers:

3

Hi,

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"/&gt;
        <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 http://stackoverflow.com/questions/2887588/wcf-using-windows-service

Thanks

Lijo

A: 

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.

Shiraz Bhaiji
A: 

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??

marc_s
For TCP, what I understand is, we need to make httpGetEnabled="false". This is part of serviceBehaviors. And we can have only one serviceBehavior for one service. Then, how can we make the single service working for multiple bindings? Is there something like <endpointMetadata httpGetEnabled="false"/> ? If yes, does endPoint behavior override service behavior? Please help. [Please be patient even if my question is foolish since I am fresher in WCF] Thanks
Lijo
@Lijo: no, that httpGetEnabled setting is no a problem at all - just go for it! It wouldn't make sense to have this enabled if you had only netTcp endpoints - but it's not bothering netTcp at all. This setting just simply enables you to grab the service metadata using HTTP (by adding ?wsdl to your service URL) - it doesn't have any effect whatsoever on your netTcp endpoints.....
marc_s
A: 

Hi,

When I used the following config and started the service, I got an error stating that the service started and stopped. [I have put exe.config in the required place.] What should I change to to run the service? Please help..

“The LijosWindowsService service on Local Computer started and then stopped. Some services stop automatically if they have no work to do, for example, the Performance Logs and Alerts service”

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

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

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

    <endpoint address="mex"
              binding="mexTcpBinding"
              contract="IMetadataExchange" />  <!--mexTcpBinding-->

  </service>


</services>
<behaviors>

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

</behaviors>

Thanks

Lijo

Lijo