【发布时间】:2012-05-06 04:25:39
【问题描述】:
我正在尝试从 IIS 中运行两个 WCF 服务,一个是 Web 服务,一个是 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">
<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>
当我在 IDE 中运行它时,它会打开一个在端口 51953 上运行的页面,我可以通过浏览到 http://localhost:51953/WebService.svc?wsdl 来获取 Web 服务的 WSDL(注意端口不同)。 我似乎无法通过将端口更改为我在 webconfig 文件 (8523) 中指定的端口来获取 WSDL。
当我将 WcfTestClient 应用程序指向“net.tcp://localhost:8523/ServerService”时,它给了我一个错误,说它无法访问元数据,据我所知,我已经配置了(服务中的第二个端点)。
我在这里做错了什么?
更新:
我已尝试按照建议将项目属性上的端口号更改为 8523,但这似乎不起作用,我还尝试将 mex 端点的地址更改为“ServerService\mex”,测试客户端花了一些时间时间搅动,但随后引发以下错误:
错误:无法从 net.tcp://localhost:8523/ServerService 如果这是 Windows (R) 请访问您有权访问的通信基础服务 检查您是否已在指定位置启用元数据发布 地址。有关启用元数据发布的帮助,请参阅 MSDN 文档位于 http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata交流 错误 URI:net.tcp://localhost:8523/ServerService 元数据 包含无法解析的引用: 'net.tcp://localhost:8523/ServerService'。您尝试创建 不支持 .Net 框架的服务的通道。它是 您可能会遇到 HTTP 端点。预期的 记录类型“PreambleAck”,找到“72”。
我会继续挖掘,但如果有任何帮助,我将不胜感激。
更新 2:
我已将 mex 端点更改为 mexTcpBinding: 这是服务标签:
<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>
仍然没有运气。只是为了确保我在测试仪中输入了正确的 url,我使用的 Url 是:
net.tcp://localhost:8523/ServerService
我也试过了:
net.tcp://localhost:8523/mex
和
net.tcp://localhost:8523/
所有这些都给了我以下错误的一些变化:
错误:无法从 net.tcp://localhost:8523/ServerService 如果这是 Windows (R) 请访问您有权访问的通信基础服务 检查您是否已在指定位置启用元数据发布 地址。有关启用元数据发布的帮助,请参阅 MSDN 文档位于 http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata交流 错误 URI:net.tcp://localhost:8523/ServerService 元数据 包含无法解析的引用: 'net.tcp://localhost:8523/ServerService'。您尝试创建 不支持 .Net 框架的服务的通道。它是 您可能会遇到 HTTP 端点。预期的 记录类型“PreambleAck”,找到“72”。
更新 3
FWIW 我认为我的 WEB.config 可能存在更大的问题 以下是它目前的样子:
<?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>
我可以浏览到 Web 服务,这允许我使用 ?wsdl 获取 WSDL,但如果我将地址 http://localhost:8523/MyWebService 放入 WCF 测试器,它也会引发错误。
错误:无法从http://localhost:8523/MyWebService 获取元数据 如果这是您使用的 Windows (R) Communication Foundation 服务 有访问权限,请检查您是否已在以下位置启用元数据发布 指定的地址。如需帮助启用元数据发布,请 请参阅 MSDN 文档 http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata交流 错误 URI:http://localhost:8523/MyWebService 元数据包含 无法解析的引用: 'http://localhost:8523/MyWebService'。时发生错误 接收到http://localhost:8523/MyWebService 的 HTTP 响应。 这可能是由于服务端点绑定未使用 HTTP 协议。这也可能是由于 HTTP 请求上下文 被服务器中止(可能是由于服务关闭)。看 服务器日志以获取更多详细信息。底层连接已关闭: 接收时发生意外错误。无法从中读取数据 传输连接:现有连接被强行关闭 由远程主机。现有连接被强行关闭 远程主机 HTTP GET 错误 URI: http://localhost:8523/MyWebService下载时出错 'http://localhost:8523/MyWebService'。 HTTP 请求失败 状态 404:未找到。
我认为问题要么与路径有关,要么我只是将错误的 URL 放入测试应用程序中。要么那个,要么我还没有正确配置元数据。
【问题讨论】:
-
请注意,第二个基地址是我试图将相同的服务公开为 Web 服务的结果,我已经尝试过,但它仍然不起作用。
-
<add baseAddress="htt://localhost:8523/"/>有一个协议 (HTTP) 错字 -
这会阻止 net.tcp 服务工作还是被元数据交换使用?
标签: wcf nettcpbinding