2

我已经阅读了很多文章来解决这个问题,但我无法解决它。

场景 我有一个网站,它有一个 WCF 服务和 2 个主机头

  1. 自旋本地主机
  2. spin-localhost.worldwide.co.uk(更改为 spin-localhost2)

但是使用相同的端口44001我可以访问 spin-localhost 服务,但无法访问 spin-localhost.worldwide.co.uk(现在是 spin-localhost2)。

编码

 <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="Bbc.Ww.SalesProjections.UI.Services.CilsDataReceiveBehavior">
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <basicHttpBinding>
        <binding name="WindowsAuth" maxReceivedMessageSize="2097152">
          <security mode="TransportCredentialOnly">
            <transport clientCredentialType="Windows" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <services>
      <service behaviorConfiguration="Bbc.Ww.SalesProjections.UI.Services.CilsDataReceiveBehavior" name="Bbc.Ww.SalesProjections.UI.Services.CilsDataReceive">
        <endpoint address="http://spin-localhost:44001/Services/CilsDataReceive.svc" binding="basicHttpBinding" name="BasicHttpEndpoint" bindingConfiguration="WindowsAuth" contract="Bbc.Ww.SalesProjections.UI.Services.ICilsDataReceive" />
        <endpoint address="http://spin-localhost.worldwide.co.uk:44001/Services/CilsDataReceive.svc" binding="basicHttpBinding" name="BasicHttpEndpoint" bindingConfiguration="WindowsAuth" contract="Bbc.Ww.SalesProjections.UI.Services.ICilsDataReceive" />
      </service>
    </services>
    <serviceHostingEnvironment>
      <baseAddressPrefixFilters>
        <add prefix="http://spin-localhost:44001" />
      </baseAddressPrefixFilters>
    </serviceHostingEnvironment>

  </system.serviceModel>

上述解决方案失败了我在工厂尝试过

public class CustomHostFactory : ServiceHostFactory
{
    protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
    {
        return new ServiceHost(serviceType, baseAddresses[0]);
    }
}

编辑:我使用的是 /Net 3.5 而不是 4。

参考资料 http://www.sieena.com/blog/archive/2011/02/01/wcf-service-in-iis-with-multiple-host-headers.aspx

http://blogs.msdn.com/b/rampo/archive/2008/02/11/how-can-wcf-support-multiple-iis-binding-specified-per-site.aspx

http://blogs.msdn.com/b/rampo/archive/2007/06/15/supporting-multiple-iis-bindings-per-site.aspx

http://social.msdn.microsoft.com/forums/en-US/wcf/thread/9e248455-1c4d-4c5c-851c-79d9c1631e21/

还有很多....

更新 1:经过进一步测试,worldwide.bbc.co.uk 似乎存在错误,所以我更改了名称并绑定到 spin-localhost2。

<endpoint address="http://spin-localhost2:44001/Services/CilsDataReceive.svc" binding="basicHttpBinding" name="BasicHttpEndpoint" bindingConfiguration="WindowsAuth" contract="Bbc.Ww.SalesProjections.UI.Services.ICilsDataReceive" />

我可以使用 spin-localhost 访问第一个服务,但 spin-localhost2 给出 401、401 和 400(未找到)。用 Fiddler 查了一下。

解决方案(尚未测试):

  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="Bbc.Ww.SalesProjections.UI.Services.CilsDataReceiveBehavior">
          <!--          <serviceMetadata httpGetEnabled="true" />-->
          <serviceDebug includeExceptionDetailInFaults="true"/>
          <serviceCredentials>
            <userNameAuthentication userNamePasswordValidationMode="Windows"/>
          </serviceCredentials>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <basicHttpBinding>
        <binding name="WindowsAuth" maxReceivedMessageSize="2097152">
          <security mode="TransportCredentialOnly">
            <transport clientCredentialType="Windows"/>
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <services>
      <service behaviorConfiguration="Bbc.Ww.SalesProjections.UI.Services.CilsDataReceiveBehavior" name="Bbc.Ww.SalesProjections.UI.Services.CilsDataReceive">
        <endpoint address="" binding="basicHttpBinding" name="BasicHttpEndpoint" bindingConfiguration="WindowsAuth" contract="Bbc.Ww.SalesProjections.UI.Services.ICilsDataReceive"/>
      </service>
    </services>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
4

2 回答 2

1

vesion 4 下带有 .NET 的 WCF 不支持多主机头 IIS 托管,对此有一些解决方法,这取决于您的 .NET 版本,或多或少复杂。

.NET 4.0 中的 WCF 支持此作为通过<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />在配置中使用启用的选择加入功能。

那里的一切都得到了彻底的解释:http: //blogs.msdn.com/b/rampo/archive/2008/02/11/how-can-wcf-support-multiple-iis-binding-specified-per-site.aspx

于 2012-08-22T16:15:07.757 回答
0

带有 IIS 的 WCF 将支持具有不同相对地址的多个端点,如本博文所示,但我认为 IIS 不会支持同一端口和同一网站/应用程序中的不同主机头。尝试创建单独的 IIS 网站,每个主机头一个,并为每个服务使用单独的 serviceModel 配置。这样您就可以为您创建的服务使用相同的端口。

于 2012-08-22T15:50:15.180 回答