gpt4 book ai didi

c# - 网络 TCP 绑定(bind) : The URI prefix is not recognized

转载 作者:太空狗 更新时间:2023-10-29 21:22:49 25 4
gpt4 key购买 nike

这真的让我困扰了几个小时。我使用 TCP 绑定(bind)创建了最简单的 WCF 服务。

namespace WcfTcpService
{
public class TestTcpService : ITestTcpService
{
public string Hello(string name)
{
return "Hello, " + name + "!";
}
}
}

namespace WcfTcpService
{
[ServiceContract]
public interface ITestTcpService
{
[OperationContract]
string Hello(string name);
}
}

Web.config 文件包含以下部分:

  <system.serviceModel>
<services>
<service name="WcfTcpService.TestTcpService" behaviorConfiguration="TestServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:808/WcfTcpService.TestTcpService" />
</baseAddresses>
</host>
<endpoint address="" binding="netTcpBinding" bindingConfiguration="tcpBinding" contract="WcfTcpService.ITestTcpService"></endpoint>
<endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="" contract="IMetadataExchange"></endpoint>
</service>
</services>
<bindings>
<netTcpBinding>
<binding name="tcpBinding" portSharingEnabled="true">
<security mode="None"></security>
</binding>
</netTcpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="TestServiceBehavior">
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="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>
<!--<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
<add binding="netTcpBinding" scheme="net.tcp" />
</protocolMapping>-->
<!--<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />-->
</system.serviceModel>

此服务托管在 IIS 中:

detailed settings

现在,当尝试从客户端应用程序添加对 net.tcp://localhost:808/WcfTcpService.TestTcpService 的引用时,我不断收到错误消息:

The URI prefix is not recognized.
Metadata contains a reference that cannot be resolved: 'net.tcp://localhost/WcfTcpService.TestTcpService'.
The message could not be dispatched because the service at the endpoint address 'net.tcp://localhost/WcfTcpService.TestTcpService' is unavailable for the protocol of the address.
If the service is defined in the current solution, try building the solution and adding the service reference again.

net.tcp 服务正在运行,我收到与 WcfTestClient.exe 相同的错误。我可以成功运行 http://localhost/WcfTcpService/TestTcpService.svc

我已经用谷歌搜索了,但没有找到任何结果。

谢谢!

编辑:

顺便说一句,“默认网站”的绑定(bind)屏幕看起来像这样:

bindings

最佳答案

当您创建使用 netTcpBinding 的服务并且您想要在 Visual Studio 中添加服务引用时,您应该使用 http 地址 (httpGetEnabled) 而不是服务监听的实际 tcp 地址。所以解决方案是在添加服务引用对话框中将 localhost/WcfTcpService/TestTcpService.svc 设置为 url。

关于c# - 网络 TCP 绑定(bind) : The URI prefix is not recognized,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17886007/

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