问题描述
我正在尝试从 IIS 中运行两个 WCF 服务,一个是 Web 服务,一个是 Net TCP 绑定服务.
I'm trying to run two WCF services from within IIS one is a web service and one is a Net TCP Binding Service.
这是我的 Web.config 的模拟(我已经匿名了服务名称):
Here is a simulcrum of my Web.config (I've anonymized the service name):
<?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(注意端口不同).我似乎无法通过更改为我在 webconfig 文件 (8523) 中指定的端口来获取 WSDL.
When I run this in the IDE it opens a page running on port 51953 and I can get the WSDL for the webservice by browsing to http://localhost:51953/WebService.svc?wsdl (Note the port is different).I can't seem to get the WSDL by changing to port to what I've specified in the webconfig file (8523).
当我将 WcfTestClient 应用程序指向net.tcp://localhost:8523/ServerService 时,它给了我一个错误,说它无法访问元数据,据我所知,我已经配置了(服务中的第二个端点).
When I point the WcfTestClient app at "net.tcp://localhost:8523/ServerService and it gives me an error saying that it can't access the meta data, which as far as I can see I've configured (the second end point in the service).
我在这里做错了什么?
更新:
我已经尝试将项目属性上的端口号更改为 8523,这似乎不起作用,我还尝试将 mex 端点的地址更改为ServerService\mex",测试客户端花费了一些时间搅动,但随后抛出以下错误:
I've tried changing the port number on the project properties to 8523 as suggested that didn't seem to work, I've also tried changint the address of the mex endpoint to "ServerService\mex" the test client spent some time churning but then it threw the following error:
错误:无法从net.tcp://localhost:8523/ServerService 如果这是 Windows (R)您可以访问的通信基础服务,请检查您是否已在指定的位置启用元数据发布地址.有关启用元数据发布的帮助,请参阅MSDN 文档位于http://go.microsoft.com/fwlink/?LinkId=65455.WS-元数据交换错误 URI:net.tcp://localhost:8523/ServerService 元数据包含无法解析的引用:'net.tcp://localhost:8523/ServerService'.您已尝试创建不支持 .Net 框架的服务的渠道.这是您可能遇到了 HTTP 端点.预期的记录类型PreambleAck",找到72".
我会继续挖掘,但我很感激任何帮助.
I'm going to keep digging but I'd appreciate any help.
更新 2:
我已将 mex 端点更改为 mexTcpBinding:这是服务标签:
I've changed the mex endpoint to a mexTcpBinding:Here is the service tag:
<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>
仍然没有运气.只是为了确保我在测试器中输入了正确的网址,我使用的网址是:
Still no luck. Just to be sure I am entering the correct url into the tester the Url I am using is:
net.tcp://localhost:8523/ServerService
我也试过:
net.tcp://localhost:8523/mex
和
net.tcp://localhost:8523/
所有这些都给了我以下错误的一些变化:
All of which give me some variation of the following error:
错误:无法从net.tcp://localhost:8523/ServerService 如果这是 Windows (R)您可以访问的通信基础服务,请检查您是否已在指定的位置启用元数据发布地址.有关启用元数据发布的帮助,请参阅MSDN 文档位于http://go.microsoft.com/fwlink/?LinkId=65455.WS-元数据交换错误 URI:net.tcp://localhost:8523/ServerService 元数据包含无法解析的引用:'net.tcp://localhost:8523/ServerService'.您已尝试创建不支持 .Net 框架的服务的渠道.这是您可能遇到了 HTTP 端点.预期的记录类型PreambleAck",找到72".
更新 3
FWIW 我认为我的 WEB.config 可能存在更大的问题这是它目前的样子:
FWIW I think there might be a bigger problem with my WEb.config Here is what it currently looks like:
<?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 测试器,它也会引发错误.
I can browse to the Webservice and that allows me to get the WSDL using ?wsdl but if I put the Adddress http://localhost:8523/MyWebService into the WCF tester it throws an error too.
错误:无法从 http://localhost:8523/MyWebService 获取元数据如果这是 Windows (R) Communication Foundation 服务,您有访问权限,请检查您是否已启用元数据发布指定的地址.如需启用元数据发布的帮助,请请参阅 MSDN 文档,网址为http://go.microsoft.com/fwlink/?LinkId=65455.WS-元数据交换错误 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 放入测试应用程序中.或者我还没有正确配置元数据.
I think the issue is either something to do with paths or I'm just putting the wrong URL into the test application. Either that or I've still not configured the meta data correctly.
推荐答案
对于 HTTP 端点,您需要 重新配置项目属性,以便它在端口 8523 启动您的 web.config 定义的端点.使用特定端口 (8523) 而不是自动分配的端口 (51953).
For the HTTP endpoint, you need to reconfigure the Project Properties so that it starts your web.config defined endpoint at port 8523 if hosted using IIS Express. Use specific port (8523) instead of auto-assigned port (51953).
对于 TCP 元数据,您需要支持启用 TCP 的 mex 端点(mexTcpBinding
).
For the TCP metadata, you need to support a TCP-enabled mex endpoint (mexTcpBinding
).
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
这篇关于无法从 WCF 测试客户端访问 Net TCP 服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!