我尝试使用本文使用 TCP 在 Windows 服务中托管 WCF:
http://msdn.microsoft.com/en-us/library/ff649818.aspx
在所有步骤成功通过后,包括运行服务,我尝试向客户端添加 WCF 服务引用,因此我创建了控制台应用程序项目,并在尝试添加对我的服务的引用后出现此错误:
The URI prefix is not recognized.
Metadata contains a reference that cannot be resolved: 'net.tcp://localhost:8523/Service1'.
Could not connect to net.tcp://localhost:8523/Service1. The connection attempt lasted for a time span of 00:00:02.0072566. TCP error code 10061: No connection could be made because the target machine actively refused it 127.0.0.1:8523.
No connection could be made because the target machine actively refused it 127.0.0.1:8523
If the service is defined in the current solution, try building the solution and adding the service reference again.
这是我的 app.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<compilation debug="true" />
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<services>
<service name="WcfServiceLibrary1.Service1">
<endpoint address="" binding="netTcpBinding" bindingConfiguration=""
contract="WcfServiceLibrary1.IService1">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexTcpBinding" bindingConfiguration=""
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8523/Service1" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
我也尝试netstat -ap tcp
并找不到我的服务连接