我使用WCF在Windows服务(客户端)和Winforms应用程序(服务主机)之间来回发送消息。直到最近这个工作。现在,当客户端尝试通信时,我收到以下错误消息:WCF错误 - 没有端点侦听
“没有端点侦听到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:
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();
:在主机侧
<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#代码
请注意,所有的代码编译和服务都会按照“您已经创建了服务”页面证明的那样运行n基地址被输入到网页浏览器中。我忽略了什么?
您可以共享整个columbineWCFServiceClient代码,而不仅仅是那么小的一部分吗?我认为AreYouThere()方法定义有问题。另外,您是否尝试过使用WCF测试客户端来联系该方法? Visual Studio有一个客户端可以用来联系它。 – Nzall 2014-09-25 21:28:33
不知道是否可以解释它,但客户端的app.config中的“http:// localhost:8000/ColumbineWCFService/ColumbineWCFService”与主机中的“http:// localhost:8000/ColumbineWCFService”之间似乎有差异。 – 2014-09-25 21:53:25