Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hosting a WCF service with Net.TCP

I am totally new to this and trying to host the simplest WCF service with a net.tcp binding I have Windows 7 Professional and IIS7 and have enabled NON http activation.

  • I start a new WCF Service application project in vs2010 and compile it. NOHTING ELSE!
  • I delete all my IIS Websites and add a new called WCFHost
  • I open up WcfTestClient.exe and adds http://localhost/Service1.svc the application finds it

The Web.config looks like this (untouched)

 <system.serviceModel>
    <services>
      <service name="WcfService2.Service1" behaviorConfiguration="WcfService2.Service1Behavior">
        <endpoint address="" binding="wsHttpBinding" contract="WcfService2.IService1">
          <!-- 
              Upon deployment, the following identity element should be removed or replaced to reflect the 
              identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
              automatically.
          -->
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="WcfService2.Service1Behavior">
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

So far, so good. But what about that net.tcp binding. I add the "enabledProtocols" attribute so my applicationHost.config looks like this

       <site name="WCFHOST" id="3">
            <application path="/" applicationPool="WCFHOST" enabledProtocols="http,net.tcp,net.pipe,net.msmq">
                <virtualDirectory path="/" physicalPath="C:\Prosjekter\temp\TestService\TestService" />
            </application>
            <bindings>
                <binding protocol="net.tcp" bindingInformation="808:*" />
                <binding protocol="http" bindingInformation="*:80:" />
            </bindings>
        </site>

Then I go to the IIS WCFHost website and add binding net.tcp 808:* And then I modify my web.config for the WCF Service to look like this. (just changed the binding on the endpoints)

<system.serviceModel>
    <services>
      <service name="WcfService2.Service1" behaviorConfiguration="WcfService2.Service1Behavior">
        <!-- Service Endpoints -->
        <endpoint address="" binding="netTcpBinding" contract="WcfService2.IService1">
          <!-- 
              Upon deployment, the following identity element should be removed or replaced to reflect the 
              identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
              automatically.
          -->
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="WcfService2.Service1Behavior">
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
 </system.serviceModel>

When I now try to add the service net.tcp://localhost:808/Service1.svc in my WcfTestClient.exe I get the error

Error: Cannot obtain Metadata from net.tcp://localhost/Service1.svc TCP-errorcode 10061: No connection could be made because the target machine actively refused it.... 127.0.0.1:808

My firewall is turned off. I have seen one thing, though.. when using netstat -a the 808 port is not listed there.. should it?

Can someone help me just creating my first WCF service with nettcp binding?

like image 642
Martin Avatar asked Jul 08 '11 16:07

Martin


2 Answers

As Tocco says, check that the service is running. You can do this by checking:

netstat /an | find /i "808 "

And it should show:

TCP 0.0.0.0:808 0.0.0.0:0 LISTENING
TCP [::]:808 [::]:0 LISTENING

if the service is running correctly.

To get it to start if it's not already working, you can issue:

sc start NetTcpActivator

from the command line to ttry to start it.

Even before that, make sure that the non-HTTP activation windows components are installed.

Also check that the services are actually running. I had a problem where they would not necessarily start after a reboot.

like image 197
Peter K. Avatar answered Sep 28 '22 22:09

Peter K.


The net.tcp bindings are enabled on IIS for requests on 808? Check it on IIS manager / bindings.

See it

like image 41
Tocco Avatar answered Sep 28 '22 22:09

Tocco