在MSDN步行通过一个错误 - "如何:使用在Windows服务主机WCF TCP" [英] An error in the MSDN walk-through - "How to: Host WCF in a Windows Service Using TCP"
问题描述
我一直在敲打我的头靠在一个砖墙的近2天尝试成功地使用MSDN上的这个例子:
如果您按照例如,通过并放置在同一个解决方案中的消费者应用程序,然后运行成功! - 即使服务被关闭
如果服务接通和消费者的应用程序发布到说一个不同的网络驱动器,那么它将无法运行,因为WCF是不听。
下面这段在步行通过代码是罪魁祸首:
保护覆盖无效的OnStart(字串[] args)
{
如果(myServiceHost!= NULL)
{
myServiceHost.Close();
}
myServiceHost =新的ServiceHost(typeof运算(服务1));
myServiceHost.Open();
}
我的朋友注意到,如果我们改变新的ServiceHost( typeof运算(服务1));
到新的ServiceHost(typeof运算(WcfServiceLibrary1.Service1));
则WCF将真正开始听
容易看到它的混乱,因为有一个Windows服务项目藏汉为WCF项目,以便在需要完整的资质中调用Service1类。
有没有其他人碰到这个?
我有同样的问题(如你知道<一个HREF =http://stackoverflow.com/questions/12750413/consuming-a-wcf-service-that-is-hosted-in-a-windows-service-from-outside-solutio/12800645#12800645>原帖在计算器)。
另外,你可以重命名的命名空间WcfServiceLibrary1以避免冲突的类服务。
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?
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.
这篇关于在MSDN步行通过一个错误 - "如何:使用在Windows服务主机WCF TCP"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!