Windows 服务托管 TCP WCF 服务 [英] Windows Service Hosted TCP WCF Service

查看:28
本文介绍了Windows 服务托管 TCP WCF 服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 WCF 服务作为 Windows 服务托管在 Windows 2008 R2 服务器上.我遵循了 msdn 提供的说明(在这里找到).只要一切都是visual studio中相同解决方案的一部分,一切都可以正常工作.但是,我尝试在不同的解决方案中(在同一台机器上)创建一个客户端,但它找不到该服务.我收到如下所示的添加服务引用错误".

I am trying to host a WCF service on a windows 2008 R2 server as a windows service. I followed the directions provided by msdn (found here). Everything works fine as long as everything is part of the same solution in visual studio. However, I tried creating a client in a different solution (on the same machine) and it can't find the service. I get an 'Add Service Reference Error' shown below.

我的目标是能够远程访问 wcf 服务,但我似乎甚至无法在本地访问它,除非客户端是在同一个客户端中创建的.是否有任何人可以提供任何指南、教程或有用的提示来让我使用它?

My goal is to be able to access the wcf service remotely, but I can't seem to even access it locally unless the client was created within the same client. Is there any guides, tutorials, or helpful hints that anyone can give me to get this to work?

更新:似乎即使 Windows 服务正在运行,WCF 服务似乎也没有侦听任何端口.这表明它没有运行.这也解释了为什么每个人首先认为我没有运行该服务.我曾假设,由于 Windows 服务正在运行并且相同的解决方案客户端在运行,因此 WCF 服务也在运行.事实证明,每当我运行相同的解决方案客户端时,Visual Studio 就会启动 WCF 服务.

Update: It seems that even though the windows service is running, the WCF service doesn't seem to be listening to any ports. Which would suggest that it isn't running. This also explains why everyone's first thought I didn't have the service running. I had assumed that since the windows service was running and that the same solution client worked, that the WCF service was working as well. Turns out that Visual Studio was starting up a WCF service whenever I ran the same solution client.

那么,为什么windows服务不启动WCF服务呢?有什么想法吗?

So, why isn't the windows service starting the WCF service? Any ideas?

推荐答案

原来是MSDN提供的教程(在上面的问题中提供)有问题.他们将 Windows 服务和 WCF 服务命名为 Service1,这是它们的默认名称.

It turns out that there was a problem with the tutorial provided by MSDN (provided in the question above). They named both the windows service and the WCF service Service1 which is the default name for both of them.

Windows 服务本应启动 WCF 服务,但实际上它试图重新启动自己,因为这两个服务的名称相同.

The windows service was suppose to start the WCF service, however, it was actually trying to start itself again because both services had the same name.

myServiceHost = new ServiceHost(typeof(Service1));

要解决此问题,您可以重命名其中一个服务或在 Windows 服务中引用时完全限定 WCF 服务.

To fix this problem, you can rename one of the services or fully qualify the WCF service when referenced in the windows service.

myServiceHost = new ServiceHost(typeof(WcfServiceLibrary1.Service1));

有趣的是,提供的代码看起来仍然有效,因为 Visual Studio 足够聪明,可以注意到 WCF 服务没有运行,而是在后台启动了一个实例.

The funny thing is that the code provided still looks like it works because Visual Studio is smart enough to notice that the WCF service isn't running and it starts an instance up behind the scenes.

这是一个需要修复的简单错误,但由于 Visual Studio 对我隐藏了问题,我认为如果没有 Espen Burud 的帮助,我不会发现它.

It was a simple bug to fix, but because Visual Studio was hiding the problem from me, I don't think I would have found it without the help from Espen Burud.

这篇关于Windows 服务托管 TCP WCF 服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆