WCF服务中未找到端点异常

时间:2016-11-14 09:58:16

标签: c# wcf wcf-endpoint

我正在接近WCF服务,从Microsoft提供的教程开始。我创建了一个非常简单的WCF服务(CalculatorService),我对这项服务的EndpointAddress有些怀疑。

当我创建WCF主机时,我将端点设置为:

Uri baseAddress = new Uri("http://localhost:8000/GettingStarted/");
// Step 2 Create a ServiceHost instance
ServiceHost selfHost = new ServiceHost(typeof(Service1), baseAddress);
// Step 3 Add a service endpoint.
selfHost.AddServiceEndpoint(typeof(IService1), new WSHttpBinding(), "CalculatorService");

如果我调试整个解决方案,一切正常,但是,如果我启动WCFHost执行其.exe文件,启动客户端的应用程序会给我以下异常:

System.ServiceModel.EndpointNotFoundException: No endpoint listening in http://localhost:8732/Design_Time_Address/WcfServiceLibrary/Service1/.

事实是,如果我尝试打开浏览器并搜索地址http://localhost:8000/GettingStarted/,我会正确获取服务页面。我认为服务托管在一个地址,客户端尝试通过另一个地址访问它。

有人可以帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

如果您在客户端代码中对此地址http://localhost:8732进行了硬编码,请在此处进行更改。但是,您的客户可能(您没有在您的问题中放置该信息)自动生成。在这种情况下,客户端配置在App.config文件中(如果我们正在讨论您的解决方案),并在构建项目时在.exe文件的配置文件中。您应该查看[ClientApplicationName] .exe.config文件并将端点地址更新为端口8000.