Net TCP绑定:无法识别URI前缀
这真的让我困扰了几个小时。 我使用TCP绑定创建了最简单的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文件包含以下部分:
<!-- --> <!---->
此服务托管在IIS中:
现在,当尝试从客户端应用程序添加对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
。
我搜索谷歌但没有出现。
谢谢!
编辑:
“默认网站”的绑定屏幕看起来像这样:
当您创建使用netTcpBinding的服务并且要在Visual Studio中添加服务引用时,您应该使用http地址(httpGetEnabled)而不是服务侦听的实际tcp地址。 所以解决方案是在添加服务引用对话框中将localhost / WcfTcpService / TestTcpService.svc设置为url。
我有同样的问题,我改变了web.config如下: