这是背景——我想自托管一个实现 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 中自我托管,如上所示?
谢谢。