An error in the MSDN walk-through - “How to: Host WCF in a Windows Service Using TCP”

旧城冷巷雨未停 提交于 2020-01-01 19:52:47

问题


I've been banging my head against a brick-wall the past 2 days trying to successfully use this example on MSDN:

How to: Host WCF in a Windows Service Using TCP

If you follow the example through and place the Consumer application within the same solution then it runs successfully - even if the service is turned off !

If the service is switched on and the consumer application is published to say a different network drive then it will not run because the WCF is not listening.

The following piece of code in the walk-through is the culprit:

protected override void OnStart(string[] args)
{
   if (myServiceHost != null)
   {
       myServiceHost.Close();
   }
   myServiceHost = new ServiceHost(typeof(Service1));
   myServiceHost.Open();
}

My friend noticed that if we change new ServiceHost(typeof(Service1)); to new ServiceHost(typeof(WcfServiceLibrary1.Service1)); then the WCF will actually start to listen!

Easy to see it's confusion as there is a class called Service1 within the windows service project aswell as the WCF project so the full qualification is required.

Did anyone else encounter this?


回答1:


I had the same issue (as you know from the original post in stackoverflow).

Alternatively, you can rename the class Service1 in the namespace WcfServiceLibrary1 to avoid conflicts.




回答2:


you have to put using WcfServiceLibrary1; at the top




回答3:


I also found that the the article references the wrong Service Name. When I tried it I had to use:

net.tcp://localhost:8526/Service1/mex

in step 8 instead of what was listed.

net.tcp://localhost:8526/Service1


来源:https://stackoverflow.com/questions/12761107/an-error-in-the-msdn-walk-through-how-to-host-wcf-in-a-windows-service-using

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!