0
votes

I follow this blog CONFIGURING WCF SERVICE WITH NETTCPBINDING step by step, when I add service reference from VS 2013, I got below error.

The URI prefix is not recognized.
Metadata contains a reference that cannot be resolved: 'net.tcp://localhost/WCFNetTcp/WCFNetTcpService.svc/mex'.
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'.  

My Service configure file is below:

  <system.serviceModel>
    <services>
      <service behaviorConfiguration="netTcpb" name="WCFNetTcp.WCFNetTcpService">
        <endpoint address="" binding="netTcpBinding" bindingConfiguration="portSharingBinding" contract="WCFNetTcp.IWCFNetTcpService" />
        <endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="" contract="IMetadataExchange" />
        <!--<endpoint address="mexHttp" binding="mexHttpBinding" contract="IMetadataExchange" />-->
        <host>
          <baseAddresses>
            <!--<add baseAddress="net.tcp://localhost:6666/WCFNetTcpService/"/>-->
            <add baseAddress="net.tcp://localhost:808/WCFNetTcp/WCFNetTcpService.svc" />
            <!--<add baseAddress="http://local/WCFNetTcp"/>-->
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="netTcpb">
          <serviceMetadata httpGetEnabled="false"/>
        <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <netTcpBinding>
        <binding name="portSharingBinding" portSharingEnabled="true"/>
      </netTcpBinding>
    </bindings>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true">
      <baseAddressPrefixFilters>
        <add prefix="net.tcp://localhost:808"/>
      </baseAddressPrefixFilters>
    </serviceHostingEnvironment>
  </system.serviceModel>

I tried any net.tcp URL what I could think out, but all of them do not work. It seems that basic address did not work when the service is hosted in IIS, it depends on the url in IIS. If I create a service which is hosted in console application with below configuration file, it works.

<system.serviceModel>
  <behaviors>
    <serviceBehaviors>
      <behavior>
        <serviceMetadata httpGetEnabled="false"/>
      </behavior>
    </serviceBehaviors>
  </behaviors>
    <services>
        <service name="WCFNETTCP.Service1">
            <endpoint address="" binding="netTcpBinding" contract="WCFNETTCP.IService1">
            </endpoint>
            <!--comment out after you add service reference-->
            <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
            <host>
                <baseAddresses>
                    <add baseAddress="net.tcp://xxx:6666/WCFNETTCP/" />
                    <add baseAddress="http://xxx:6667/WCFNETTCIP"/>
                </baseAddresses>
            </host>
        </service>
    </services>
</system.serviceModel>

It would be appreciated if you could share us how to make it work under IIS.

1
You are correct, the base address is ignored in IIS (it uses the url generated by IIS). Have you tried adding it via http?Tim
@Tim Yes, I tried, and the service reference is added, but when I run the service client by net.tcp URL, I got this error again.Edward

1 Answers

0
votes

It seems there is something wrong in my IIS. I resolved this issue by below steps.

  1. reinstall IIS
  2. reinstall WCF Non-HTTP Activation in Windows features
  3. reregister asp.net in iis by this command

C:\Windows\Microsoft.NET\Framework64\v4.0.30319>dism /online /enable-feature /featurename:IIS-ASPNET45

  1. Check the settings in IIS which there is no change at my side.
  2. Rebuild my WCF Service, and add service reference successfully.
    Hope it will be work for you.