Wcf – Can’t Access Net TCP service From WCF Test Client

nettcpbindingwcf

I'm trying to run two WCF services from within IIS one is a web service and one is a Net TCP Binding Service.

Here is a simulcrum of my Web.config (I've anonymized the service name):

<?xml version="1.0"?>
<configuration>

  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <services>
      <service name="ServerService">
        <endpoint address="ServerService" 
                  binding="netTcpBinding" 
                  bindingConfiguration="" 
                  name="NetTcpEndPoint" 
                  contract="IServerService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex"
                  binding="mexHttpBinding"
                  contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="net.tcp://localhost:8523/"/>
            <add baseAddress="htt://localhost:8523/"/>
          </baseAddresses>
        </host>
      </service>

      <service name="MyWebService">
        <endpoint address=""
                  binding="wsHttpBinding"
                  bindingConfiguration=""
                  name="AACCWSEndPoint"
                  contract="IMyWebService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8523/IMyWebService"/>
          </baseAddresses>
        </host>
      </service>

    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- 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>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

</configuration>

When I run this in the IDE it opens a page running on port 51953 and I can get the WSDL for the webservice by browsing to http://localhost:51953/WebService.svc?wsdl (Note the port is different).
I can't seem to get the WSDL by changing to port to what I've specified in the webconfig file (8523).

When I point the WcfTestClient app at "net.tcp://localhost:8523/ServerService and it gives me an error saying that it can't access the meta data, which as far as I can see I've configured (the second end point in the service).

What am I doing wrong here?

UPDATE:

I've tried changing the port number on the project properties to 8523 as suggested that didn't seem to work, I've also tried changint the address of the mex endpoint to "ServerService\mex" the test client spent some time churning but then it threw the following error:

Error: Cannot obtain Metadata from
net.tcp://localhost:8523/ServerService If this is a Windows (R)
Communication Foundation service to which you have access, please
check that you have enabled metadata publishing at the specified
address. For help enabling metadata publishing, please refer to the
MSDN documentation at
http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange
Error URI: net.tcp://localhost:8523/ServerService Metadata
contains a reference that cannot be resolved:
'net.tcp://localhost:8523/ServerService'. You have tried to create
a channel to a service that does not support .Net Framing. It is
possible that you are encountering an HTTP endpoint. Expected
record type 'PreambleAck', found '72'.

I'm going to keep digging but I'd appreciate any help.

UPDATE 2:

I've changed the mex endpoint to a mexTcpBinding:
Here is the service tag:

    <endpoint address="ServerServiceWS"
              binding="wsHttpBinding"
              bindingConfiguration=""
              name="WSEndPoint"
              contract="IServerService">
      <identity>
        <dns value="localhost" />
      </identity>
    </endpoint>
    <endpoint address="mex"
              binding="mexTcpBinding"
              contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="net.tcp://localhost:8523/"/>
        <add baseAddress="http://localhost:8523/"/>
      </baseAddresses>
    </host>
  </service>

Still no luck. Just to be sure I am entering the correct url into the tester the Url I am using is:

net.tcp://localhost:8523/ServerService

I've also Tried:

net.tcp://localhost:8523/mex

and

net.tcp://localhost:8523/

All of which give me some variation of the following error:

Error: Cannot obtain Metadata from
net.tcp://localhost:8523/ServerService If this is a Windows (R)
Communication Foundation service to which you have access, please
check that you have enabled metadata publishing at the specified
address. For help enabling metadata publishing, please refer to the
MSDN documentation at
http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange
Error URI: net.tcp://localhost:8523/ServerService Metadata
contains a reference that cannot be resolved:
'net.tcp://localhost:8523/ServerService'. You have tried to create
a channel to a service that does not support .Net Framing. It is
possible that you are encountering an HTTP endpoint. Expected
record type 'PreambleAck', found '72'.

UPDATE 3

FWIW I think there might be a bigger problem with my WEb.config Here is what it currently looks like:

<?xml version="1.0"?>
<configuration>

  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <services>
      <service name="ServerService">
        <endpoint address="" 
                  binding="netTcpBinding" 
                  bindingConfiguration="DefaultBindingConfig" 
                  name="NetTcpEndPoint" 
                  contract="IServerService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>

        <endpoint address="mex"
                  binding="mexTcpBinding"
                  contract="IMetadataExchange" 
                  bindingConfiguration="mexBinding"/>
        <host>
          <baseAddresses>
            <add baseAddress="net.tcp://localhost:8523/"/>
          </baseAddresses>
        </host>
      </service>

      <service name="MyWebService">
        <endpoint address=""
                  binding="wsHttpBinding"
                  bindingConfiguration=""
                  name="MyWSEndPoint"
                  contract="IMyWebService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex"
                  binding="mexHttpBinding"
                  contract="IMetadataExchange"
                  bindingConfiguration="mexHttpBinding"/>
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8523/MyWebService"/>
          </baseAddresses>
        </host>
      </service>

    </services>
    <bindings>
      <netTcpBinding>
        <binding name="DefaultBindingConfig"
                 maxConnections="5"
                 portSharingEnabled="true" >
        </binding>
        <binding name="mexBinding"
                 portSharingEnabled="true">
          <security mode="None"></security>
        </binding>
      </netTcpBinding>
      <mexTcpBinding>
        <binding name="mexTcpBinding"/>
      </mexTcpBinding>
      <mexHttpBinding>
        <binding name="mexHttpBinding"/>
      </mexHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ServerServiceBehaviour">
          <!-- 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>
        <behavior name="MexBehaviour">
          <serviceMetadata httpGetEnabled="true" policyVersion="Policy15"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

</configuration>

I can browse to the Webservice and that allows me to get the WSDL using ?wsdl but if I put the Adddress http://localhost:8523/MyWebService into the WCF tester it throws an error too.

Error: Cannot obtain Metadata from http://localhost:8523/MyWebService
If this is a Windows (R) Communication Foundation service to which you
have access, please check that you have enabled metadata publishing at
the specified address. For help enabling metadata publishing, please
refer to the MSDN documentation at
http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange
Error URI: http://localhost:8523/MyWebService Metadata contains
a reference that cannot be resolved:
'http://localhost:8523/MyWebService'. An error occurred while
receiving the HTTP response to http://localhost:8523/MyWebService.
This could be due to the service endpoint binding not using the HTTP
protocol. This could also be due to an HTTP request context being
aborted by the server (possibly due to the service shutting down). See
server logs for more details. 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 hostHTTP GET Error URI:
http://localhost:8523/MyWebService There was an error downloading
'http://localhost:8523/MyWebService'. The request failed with HTTP
status 404: Not Found.

I think the issue is either something to do with paths or I'm just putting the wrong URL into the test application. Either that or I've still not configured the meta data correctly.

Best Answer

For the HTTP endpoint, you need to reconfigure the Project Properties so that it starts your web.config defined endpoint at port 8523 if hosted using IIS Express. Use specific port (8523) instead of auto-assigned port (51953).

For the TCP metadata, you need to support a TCP-enabled mex endpoint (mexTcpBinding).

<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
Related Topic