多个IP地址的WCF自托管ServiceHost错误

时间:2015-02-27 15:49:03

标签: web-services wcf self-hosting servicehost

我使用WCF自托管Web服务。主机有多个以太网端口,因此我创建了具有多个URI的ServiceHost。当我创建服务主机时,出现以下错误:

“此集合已包含带有方案http的地址。此集合中每个方案最多只能有一个地址。 参数名称:item“

以下是代码:

Uri[] uriSet = new Uri[ipList.Count];
for (int i=0; i<ipList.Count; i++)
{
    string baseAddress = string.Format("http://{0}:{1}/mynamespace", ipList[i], myport);
    uriSet[i] = new Uri(baseAddress);
}

host = new ServiceHost(webServiceType, uriSet);

ipList包含主机的IP地址列表。

1 个答案:

答案 0 :(得分:1)

您可以使用特殊IP地址0.0.0.0或仅使用localhost来匹配本地计算机的任何IP地址。因此,您只需要一个基地址URI,其中包含localhost0.0.0.0

host = new ServiceHost(webServiceType, new Uri[] { new Uri("http://localhost:80/mynamespace") });

host = new ServiceHost(webServiceType, new Uri[] { new Uri("http://0.0.0.0:80/mynamespace") });

*其中80是端口。

https://msdn.microsoft.com/en-us/library/ms733768%28v=vs.110%29.aspx

相关问题