我正在尝试从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>
Run Code Online (Sandbox Code Playgroud)
当我在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)Communication Foundation服务,请检查是否已在指定地址启用元数据发布。有关启用元数据发布的帮助,请参阅MSDN文档,网址为 http://go.microsoft.com/fwlink/?LinkId=65455。WS-MetadataExchange错误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>
Run Code Online (Sandbox Code Playgroud)
仍然没有运气。只是为了确保我在使用的网址是测试人员中输入了正确的网址:
net.tcp://localhost:8523/ServerService
Run Code Online (Sandbox Code Playgroud)
我也尝试过:
net.tcp://localhost:8523/mex
Run Code Online (Sandbox Code Playgroud)
和
net.tcp://localhost:8523/
Run Code Online (Sandbox Code Playgroud)
所有这些给了我以下错误的一些变化:
错误:无法从net.tcp:// localhost:8523 / ServerService获取元数据。如果这是您有权访问的Windows(R)Communication Foundation服务,请检查是否已在指定地址启用元数据发布。有关启用元数据发布的帮助,请参阅MSDN文档,网址为 http://go.microsoft.com/fwlink/?LinkId=65455。WS-MetadataExchange错误URI:net.tcp:// localhost:8523 / ServerService元数据包含无法解析的引用:“ net.tcp:// localhost:8523 / ServerService”。您试图为不支持.Net Framing的服务创建通道。您可能遇到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>
Run Code Online (Sandbox Code Playgroud)
我可以浏览到Web服务,这使我可以使用?wsdl获取WSDL,但如果将Adddress http:// localhost:8523 / MyWebService放入WCF测试器中,也会引发错误。
错误:无法从http:// localhost:8523 / MyWebService获取元数据 如果这是您有权访问的Windows(R)Communication Foundation服务,请检查是否已在指定的地址启用元数据发布。有关启用元数据发布的帮助,请参阅MSDN文档,网址为 http://go.microsoft.com/fwlink/?LinkId=65455。WS-MetadataExchange错误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。要么,要么我仍然没有正确配置元数据。
对于HTTP终结点,如果使用IIS Express进行托管,则需要重新配置项目属性,以便在端口8523处启动web.config定义的终结点。使用特定的端口(8523)而不是自动分配的端口(51953)。
对于TCP元数据,您需要支持启用TCP的mex端点(mexTcpBinding)。
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
Run Code Online (Sandbox Code Playgroud)