Enabling NetTcpBinding for Performance gains and binary serialization

I have a web simple web service which as just basic http binding, below are the steps to steps to enable netTcpBinding

<services>
      <service name="TestWcfWebService.Service.PersonService">
        <endpoint address="basic" binding="basicHttpBinding" bindingConfiguration="" 
          contract="TestWcfWebService.Contracts.IPerson" />
</service>

My webservice is at http://localhost/TestWcfWebService-Server/Service.svc?wsdl

Below you can see the methods when you add reference to this service using wcfTestclient

All the methods work fine.

Let us add another endpoint with netTcpBinding

 <services>
      <service name="TestWcfWebService.Service.PersonService">
        <endpoint address="basic" binding="basicHttpBinding" bindingConfiguration="" 
          contract="TestWcfWebService.Contracts.IPerson" />
        <endpoint address="tc" binding="netTcpBinding" bindingConfiguration="" 
                  contract="TestWcfWebService.Contracts.IPerson" />
          </service>
    </services>

When you browse to the svc file you will get an error

Could not find a base address that matches scheme net.tcp for the endpoint with binding NetTcpBinding. Registered base address schemes are [http].

I am using Windows7 , IIS7, App pool 4.0 Integrated. What the error is telling is you have not enabled the net.tcp binding protocol on you website. Go to your application, right click, manage application, and advance setting

Add net.tcp to the Enabled Protocol

Now browse to the svc file.

Now let us try to add reference to this service using wcfTestClient

You can see now we have the net Tcp endpoint, http binding still works fine, when you try to invoke addPerson you get error

Could not connect to net.tcp://localhost/TestWcfWebService-Server/Service.svc/tc. The connection attempt lasted for a time span of 00:00:02.0112011. TCP error code 10061:

The reason for this error is because your Net.Tcp Listener Adapter Service is not started.

When you try to start Net.Tcp Listener Adapter Service you may get the below error

Windows could not start the Net.Tcp Listener Adapter service on Local Computer.
Error 1068: The dependency service or group failed to start.
This error is because Net TCP depends on Net.Tcp Port Sharing and Windows Process Activation Service, make sure these services are started as well.

After these services are started Net TCP Binding is all set.

Below is the code in VB when you need to invoke a specific end point after adding service reference, first look at the wsdl on the client after adding reference, you will find the endpoint name BasicHttpBinding_IPerson and NetTcpBinding_IPerson

My WSDL

<wsdl:service name="PersonService">
    <wsdl:port name="BasicHttpBinding_IPerson" binding="tns:BasicHttpBinding_IPerson">
      <soap:address location="http://localhost/TestWcfWebService-Server/Service.svc/basic" />
    </wsdl:port>
    <wsdl:port name="NetTcpBinding_IPerson" binding="tns:NetTcpBinding_IPerson">
      <soap12:address location="net.tcp://localhost/TestWcfWebService-Server/Service.svc/tc" />
      <wsa10:EndpointReference> 

Here I am invoking net tcp binding endpoint.

    Private Sub Form1_Load(ByVal sender As System.ObjectByVal e As System.EventArgsHandles MyBase.Load 
        client = New PersonClient("NetTcpBinding_IPerson") 
    End Sub 

Possible other errors you may encounter

I am using NetworkService as the Identity of the application pool running this WCF service application.

When I try to add reference I get the below error

The document was understood, but it could not be processed.

– The WSDL document contains links that could not be resolved.

– There was an error downloading ‘http://localhost/TestWcfWebService-Server/Service.svc?xsd=xsd0&#8217;.

– The underlying connection was closed: An unexpected error occurred on a receive.

– Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.

– An existing connection was forcibly closed by the remote host

Metadata contains a reference that cannot be resolved: ‘http://localhost/TestWcfWebService-Server/Service.svc?wsdl&#8217;.

There was no endpoint listening at http://localhost/TestWcfWebService-Server/Service.svc?wsdl that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.

The remote server returned an error: (404) Not Found.

If the service is defined in the current solution, try building the solution and adding the service reference again.

This error is because of the pool identity does not have the right privileges to C:\windows\Temp, when I ran the pool with identity as myself no problem,

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s