我正在尝试从 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 上运行的页面,我可以通过浏览来获取 Web 服务的 WSDLhttp://localhost:51953/WebService.svc?wsdl http://localhost:51953/WebService.svc?wsdl(注意端口不同)。
我似乎无法通过将端口更改为我在 webconfig 文件 (8523) 中指定的端口来获取 WSDL。
当我将 WcfTestClient 应用程序指向“net.tcp://localhost:8523/ServerService 时,它给我一个错误,指出它无法访问元数据,据我所知,我已经配置了元数据(第二个服务中的端点)。
我在这里做错了什么?
UPDATE:
我尝试按照建议将项目属性上的端口号更改为 8523,但这似乎不起作用,我还尝试将 mex 端点的地址更改为“ServerService\mex”,测试客户端花了一些时间进行搅动,但是然后它抛出以下错误:
错误:无法从中获取元数据
net.tcp://localhost:8523/ServerService 如果这是 Windows (R)
请访问您有权访问的通信基础服务
检查您是否已在指定的位置启用元数据发布
地址。如需启用元数据发布的帮助,请参阅
MSDN 文档位于http://go.microsoft.com/fwlink/?LinkId=65455.WS-元数据 http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata交换
错误 URI:net.tcp://localhost:8523/ServerService 元数据
包含无法解析的引用:
'net.tcp://localhost:8523/ServerService'。您已尝试创建
不支持 .Net Framing 的服务的通道。这是
您可能遇到 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>
还是没有运气。为了确保我在测试器中输入正确的网址,我使用的网址是:
net.tcp://localhost:8523/ServerService
我也尝试过:
net.tcp://localhost:8523/mex
and
net.tcp://localhost:8523/
所有这些都给了我以下错误的一些变化:
错误:无法从中获取元数据
net.tcp://localhost:8523/ServerService 如果这是 Windows (R)
请访问您有权访问的通信基础服务
检查您是否已在指定的位置启用元数据发布
地址。如需启用元数据发布的帮助,请参阅
MSDN 文档位于http://go.microsoft.com/fwlink/?LinkId=65455.WS-元数据 http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata交换
错误 URI:net.tcp://localhost:8523/ServerService 元数据
包含无法解析的引用:
'net.tcp://localhost:8523/ServerService'。您已尝试创建
不支持 .Net Framing 的服务的通道。这是
您可能遇到 HTTP 端点。预期的
记录类型“PreambleAck”,找到“72”。
UPDATE 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 http://localhost:8523/MyWebService进入 WCF 测试器它也会引发错误。
错误:无法从中获取元数据http://localhost:8523/MyWebService http://localhost:8523/MyWebService如果这是您要访问的 Windows (R) Communication Foundation 服务
有访问权限,请检查您是否已启用元数据发布
指定的地址。如需启用元数据发布的帮助,请
请参阅 MSDN 文档:http://go.microsoft.com/fwlink/?LinkId=65455.WS-元数据 http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata交换
错误网址:http://localhost:8523/MyWebService http://localhost:8523/MyWebService元数据包含
无法解析的参考:
'http://localhost:8523/MyWebService'。发生错误
接收 HTTP 响应http://localhost:8523/MyWebService http://localhost:8523/MyWebService。
这可能是由于服务端点绑定未使用 HTTP
协议。这也可能是由于 HTTP 请求上下文
由服务器中止(可能是由于服务关闭)。看
服务器日志以获取更多详细信息。底层连接已关闭:
接收时发生意外错误。无法从中读取数据
传输连接:现有连接被强制关闭
由远程主机。现有连接被强行关闭
远程主机HTTP GET错误URI:http://localhost:8523/MyWebService http://localhost:8523/MyWebService下载时出现错误
'http://localhost:8523/MyWebService'。 HTTP 请求失败
状态 404:未找到。
我认为问题要么与路径有关,要么我只是将错误的 URL 放入测试应用程序中。要么是我仍然没有正确配置元数据。