这是此问题的后续内容,我已将在 IIS 中运行的 WCF 服务(从 Visual Studio 2010 中)配置为运行一个 Web 服务和一个 net.tcp 服务。经过大量黑客攻击后,我设法将 Web 服务加载到 WCF 测试客户端中,但我无法将 Net.Tcp 服务加载到测试客户端中。
这是我的 Web.config:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service name="ServerService" behaviorConfiguration="ServerServiceBehaviour">
<endpoint address="ServerService.svc"
binding="netTcpBinding"
bindingConfiguration="DefaultNetTcpBindingConfig"
name="NetTcpEndPoint"
contract="IServerService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex"
binding="mexTcpBinding"
contract="IMetadataExchange"
bindingConfiguration="mexTcpBinding"/>
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8523/"/>
</baseAddresses>
</host>
</service>
<service name="MyWebService" behaviorConfiguration="WebServiceBehaviour">
<endpoint address="MyWebService.svc"
binding="wsHttpBinding"
bindingConfiguration="DefaultWSBinding"
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/"/>
</baseAddresses>
</host>
</service>
</services>
<bindings>
<netTcpBinding>
<binding name="DefaultNetTcpBindingConfig"
maxConnections="5"
portSharingEnabled="true" >
</binding>
<!--<binding name="mexBinding"
portSharingEnabled="true">
<security mode="None"></security>
</binding>-->
</netTcpBinding>
<wsHttpBinding>
<binding name="DefaultWSBinding"/>
</wsHttpBinding>
<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>
<behavior name="WebServiceBehaviour">
<!-- 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>
当我运行 Visual Studio 调试器来发布服务时,我可以通过在 WCF 测试应用程序中输入以下 url 来访问 Web 服务:
但是,如果我将以下 URL 输入到 WCF 测试应用程序中,则会出现错误:
net.tcp://localhost:8523/ServerService.svc
这是我看到的错误:
错误:无法从 net.tcp://localhost:8523/ServerService.svc 获取元数据 如果这是您有权访问的 Windows (R) Communication Foundation 服务,请检查您是否已在指定地址启用元数据发布。有关启用元数据发布的帮助,请参阅位于 http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error URI: net.tcp://localhost:8523/ServerService.svc的 MSDN 文档元数据包含无法解析的引用:“net.tcp://localhost:8523/ServerService.svc”。您尝试为不支持 .Net 框架的服务创建通道。您可能会遇到 HTTP 端点。预期的记录类型“PreambleAck”,发现“72”。
阅读此问题后,VS 2010 中的网络服务器是否可能不支持 net.tcp 绑定?