gpt4 book ai didi

wcf - 无法从 WCF 测试客户端访问 Net TCP 服务

转载 作者:行者123 更新时间:2023-12-03 12:13:47 35 4
gpt4 key购买 nike

我正在尝试从 IIS 中运行两个 WCF 服务,一个是 Web 服务,一个是 Net TCP 绑定(bind)服务。

这是我的 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”,测试客户端花了一些时间时间搅动但随后引发以下错误:

Error: Cannot obtain Metadata from net.tcp://localhost:8523/ServerService If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address. For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error URI: net.tcp://localhost:8523/ServerService Metadata contains a reference that cannot be resolved: 'net.tcp://localhost:8523/ServerService'. You have tried to create a channel to a service that does not support .Net Framing. It is possible that you are encountering an HTTP endpoint. Expected record type 'PreambleAck', found '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

net.tcp://localhost:8523/

所有这些都给我以下错误的一些变体:

Error: Cannot obtain Metadata from net.tcp://localhost:8523/ServerService If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address. For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error URI: net.tcp://localhost:8523/ServerService Metadata contains a reference that cannot be resolved: 'net.tcp://localhost:8523/ServerService'. You have tried to create a channel to a service that does not support .Net Framing. It is possible that you are encountering an HTTP endpoint. Expected record type 'PreambleAck', found '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 测试器时它也会抛出错误。

Error: Cannot obtain Metadata from http://localhost:8523/MyWebService If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address. For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error URI: http://localhost:8523/MyWebService Metadata contains a reference that cannot be resolved: 'http://localhost:8523/MyWebService'. An error occurred while receiving the HTTP response to http://localhost:8523/MyWebService. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details. The underlying connection was closed: An unexpected error occurred on a receive. Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. An existing connection was forcibly closed by the remote hostHTTP GET Error URI: http://localhost:8523/MyWebService There was an error downloading 'http://localhost:8523/MyWebService'. The request failed with HTTP status 404: Not Found.

我认为问题要么与路径有关,要么我只是将错误的 URL 放入了测试应用程序。或者我还没有正确配置元数据。

最佳答案

对于 HTTP 端点,您需要 reconfigure the Project Properties如果使用 IIS Express 托管,它会在端口 8523 启动您的 web.config 定义的端点。使用特定端口 (8523) 而不是自动分配的端口 (51953)。

对于 TCP 元数据,您需要支持支持 TCP 的 mex 端点 ( mexTcpBinding )。

<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />

关于wcf - 无法从 WCF 测试客户端访问 Net TCP 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10316457/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com