Application_Start 中的自托管 netTcpBinding 服务

发布于 2024-11-29 05:38:36 字数 1067 浏览 2 评论 0原文

背景如下——我想自行托管一个实现 netTcpBinding 的 WCF 服务,并且它必须与 Windows Server 2003 / IIS6 兼容。

我正在尝试查看是否可以在 global.asax 中的 Application_Start 事件期间自行托管:

protected void Application_Start(object sender, EventArgs e)
{
        NetTcpBinding binding = new NetTcpBinding();

        binding.PortSharingEnabled = true;

        ServiceHost host = new ServiceHost(typeof(Svc), new Uri("net.tcp://xxx.x.xxx.xx:1100"));

        string address = "Tcp";

        host.AddServiceEndpoint(typeof(IService), binding, address);

        host.Open(); 
}

但是当我尝试调用服务时,我在客户端上收到此消息:

Could not connect to net.tcp://xxx.x.xxx.xx:1100/Tcp. The connection attempt lasted for a time span of 00:00:01.0630608. TCP error code 10061: No connection could be made because the target machine actively refused it xxx.x.xxx.xx:1100.

我的第一直觉是看看这是否是端口问题,所以我在客户端打开了相关端口但没有帮助,请问服务器端口有关系吗?否则我可以访问该端口。

或者,如果由于我使用 IIS6 而发生这种情况,我可以使用哪种使用自托管的解决方法来使其与 IIS6 一起工作?它是否必须通过控制台应用程序/Windows 服务进行自我托管,或者我可以在 global.asax 中进行自我托管,如上所示?

谢谢。

Heres the background -- I want to self-host a WCF service implementing netTcpBinding and it has to be compatible with Windows Server 2003 / IIS6.

I am trying to see if its possible to self-host during the Application_Start event in global.asax:

protected void Application_Start(object sender, EventArgs e)
{
        NetTcpBinding binding = new NetTcpBinding();

        binding.PortSharingEnabled = true;

        ServiceHost host = new ServiceHost(typeof(Svc), new Uri("net.tcp://xxx.x.xxx.xx:1100"));

        string address = "Tcp";

        host.AddServiceEndpoint(typeof(IService), binding, address);

        host.Open(); 
}

But I am receiving this on the client when trying to call the service:

Could not connect to net.tcp://xxx.x.xxx.xx:1100/Tcp. The connection attempt lasted for a time span of 00:00:01.0630608. TCP error code 10061: No connection could be made because the target machine actively refused it xxx.x.xxx.xx:1100.

My first instinct was to see if this was a port issue, so I opened the relevant port on the client but it didnt help, could the server port matter? I can access the port otherwise.

Or if this is occuring because I am using IIS6, what sort of work-around using self-hosting can I use to make this work with IIS6? Does it have to a self-host via console app / windows service or can I self host within global.asax as seen above?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜警司 2024-12-06 05:38:36

没有什么比这更容易的了。 使用 Windows 服务。 IIS 中的应用程序会在 IIS 需要时卸载,因此您永远不知道您的服务是否运行,并且还可能存在其他问题。

Windows 2003 + Net.Tcp = Windows 服务。其他任何事情都是错误的。

There is nothing easier. Use windows service. Application in IIS is unloaded when IIS wants to so you never know if your service runs or not and there can be other problems as well.

Windows 2003 + Net.Tcp = Windows service. Anything else is wrong.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文