Pure TCP binding: URI prefix not recognized

It really bothers me for hours. I created the simplest WCF service using TCP binding.

namespace WcfTcpService { public class TestTcpService : ITestTcpService { public string Hello(string name) { return "Hello, " + name + "!"; } } } namespace WcfTcpService { [ServiceContract] public interface ITestTcpService { [OperationContract] string Hello(string name); } } 

The Web.config file has the following section:

  <system.serviceModel> <services> <service name="WcfTcpService.TestTcpService" behaviorConfiguration="TestServiceBehavior"> <host> <baseAddresses> <add baseAddress="net.tcp://localhost:808/WcfTcpService.TestTcpService" /> </baseAddresses> </host> <endpoint address="" binding="netTcpBinding" bindingConfiguration="tcpBinding" contract="WcfTcpService.ITestTcpService"></endpoint> <endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="" contract="IMetadataExchange"></endpoint> </service> </services> <bindings> <netTcpBinding> <binding name="tcpBinding" portSharingEnabled="true"> <security mode="None"></security> </binding> </netTcpBinding> </bindings> <behaviors> <serviceBehaviors> <behavior name="TestServiceBehavior"> <!-- To avoid disclosing metadata information, set the values below to false before deployment --> <serviceMetadata httpGetEnabled="true" httpsGetEnabled="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> <!--<protocolMapping> <add binding="basicHttpsBinding" scheme="https" /> <add binding="netTcpBinding" scheme="net.tcp" /> </protocolMapping>--> <!--<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />--> </system.serviceModel> 

This service is hosted on IIS:

detailed settings

Now, when you try to add a link to net.tcp://localhost:808/WcfTcpService.TestTcpService from the client application, I keep getting the error:

 The URI prefix is not recognized. Metadata contains a reference that cannot be resolved: 'net.tcp://localhost/WcfTcpService.TestTcpService'. The message could not be dispatched because the service at the endpoint address 'net.tcp://localhost/WcfTcpService.TestTcpService' is unavailable for the protocol of the address. If the service is defined in the current solution, try building the solution and adding the service reference again. 

The net.tcp service is running, I get the same error with WcfTestClient.exe. and I can successfully run http://localhost/WcfTcpService/TestTcpService.svc .

I searched google but nothing came up.

Thanks!

EDIT:

The default Web site bindings screen is as follows:

bindings

+6
source share
2 answers

When you create a service that uses netTcpBinding, and you want to add a link to the service in Visual Studio, you must use the HTTP address (httpGetEnabled), not the actual tcp address that the service is listening on. So the solution was to set localhost / WcfTcpService / TestTcpService.svc as the URL in the Add Service Link dialog box.

+8
source

I had the same problem and I changed web.config as shown below:

 <serviceHostingEnvironment multipleSiteBindingsEnabled="true"> <baseAddressPrefixFilters> <add prefix="net.tcp://YourBaseUrl"/> </baseAddressPrefixFilters> </serviceHostingEnvironment> 
0
source

Source: https://habr.com/ru/post/950371/


All Articles