WCF错误-没有侦听终结点

本文关键字:结点 错误 WCF | 更新日期: 2023-09-27 18:24:26

我使用WCF在windows服务(客户端)和winforms应用程序(服务主机)之间来回发送消息。直到最近,这种方法一直有效。现在,当客户端尝试通信时,我收到以下错误消息:

"在http://localhost:8000/ColumbineWCFService上没有可以接受消息的侦听终结点。这通常是由不正确的地址或SOAP操作引起的。"

我花了一整天的时间在这个论坛上讨论类似的问题,但一直未能解决,希望如果我提供我项目的细节,答案会突然出现在某人身上。

以下是发生错误的代码片段(客户端):

var pingHost = new ColumbineWCFServiceReference.ColumbineWCFServiceClient();
pingHost.Open();
if (pingHost.AreYouThere() == true) return true; //<-- this is the line where the "no endpoint listening" error occurs

客户端app.config:

<system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="WSHttpBinding_IColumbineWCFService" />
      </wsHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:8000/ColumbineWCFService/ColumbineWCFService"
          binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IColumbineWCFService"
          contract="IColumbineWCFService" name="WSHttpBinding_IColumbineWCFService">
        <identity>
          <userPrincipalName value="Nathan-PC'Nathan" />
        </identity>
      </endpoint>
    </client>
  </system.serviceModel>

主机端C#代码:

ServiceHost selfHost = null;
Uri baseAddress = new Uri("http://localhost:8000/ColumbineWCFService");
selfHost = new ServiceHost(typeof(ColumbineWCFService), baseAddress);
selfHost.AddServiceEndpoint(typeof(IColumbineWCFService), new WSHttpBinding(), "ColumbineWCFService");
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
selfHost.Description.Behaviors.Add(smb);
selfHost.Open();

请注意,所有代码都会编译,服务确实会运行,这可以从"您已经创建了一个服务"页面中得到证明,当在web浏览器中键入基本地址时,就会出现该页面。我在俯瞰什么?

WCF错误-没有侦听终结点

在客户端端点配置的app.config中:

  1. 您的端点地址似乎没有指定承载端点代码的.svc文件。假设你的.svc文件名是ColumbineWCFService.svc,你的地址值应该是

    http://localhost:8000/ColumbineWCFService/ColumbineWCFService.svc

  2. 您的合同没有指定您的命名空间。假设你的命名空间是"ColumbineWCFService",你的合同将是"ColombineWCFService.IColumnineWCFServices"

  3. 没有名为"WSHttpBinding_IColumbineWCFService"的绑定配置,尽管该参数不应影响端点是否在侦听。

也就是说,对你的app.config尝试以下操作:

<endpoint address="http://localhost:8000/ColumbineWCFService/ColumbineWCFService.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IColumbineWCFService"
contract="ColumbineWCFService.IColumbineWCFService" name="WSHttpBinding_IColumbineWCFService">

如果这不起作用,请回来告诉我们您是否有WCF服务的web.config并发布它。