WCF和多个主机标头

Ryu*_*Ryu 10 c# iis wcf iis-6

我的雇主网站有多个主机名,所有主机名都在同一台服务器上,我们只是展示不同的皮肤用于品牌推广.

不幸的是,WCF似乎在这种情况下效果不佳.

我尝试用自定义主机工厂覆盖默认主机.

这不是一个可接受的解决方案,因为它需要在所有主机上工作,而不仅仅是1.

我也看了这篇博文,但要么我无法让它工作,要么它不是为了解决我的问题.

我得到的错误是"此集合已包含带有方案http的地址"

必须有一种方法来配置这个,请帮助:)

tha*_*awg 5

如果您没有在端点中放置一个地址,那么它应该解析为服务器命中的任何服务器.我使用这个代码,它解析了我的.local地址和IIS的.com地址.

<system.serviceModel>
    <services>
        <service name="ServiceName" behaviorConfiguration="ServiceName.Service1Behavior">
            <endpoint address="" binding="wsHttpBinding" contract="iServiceName">
            </endpoint>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
        </service>
    </services>
    <behaviors>
        <serviceBehaviors>
            <behavior name="ServiceName.Service1Behavior">
                <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
                <serviceMetadata httpGetEnabled="true"/>
                <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
                <serviceDebug includeExceptionDetailInFaults="true"/>
            </behavior>
        </serviceBehaviors>
    </behaviors>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)


zcr*_*r70 5

我认为上面发布的主机基地址解决方案不适用于IIS托管网站(OP确实提到这是针对其雇主的网站).

看到这篇博文

此外,thaBadDawg的另一个答案将无法在指定多个主机头的情况下工作 - 您只需获取OP提到的错误("此集合已包含带有方案http的地址".)

我认为到目前为止提到的任何解决方案都不会起作用,因为它看起来不像WCF允许单个站点访问单个站点,并且所有站点都有多个主机头.我能为.Net 3.5(及其下)找到的唯一解决方法是为每个主机头创建不同的合同,并使用自定义ServiceHostFactory根据指定的合同使用正确的主机头.这根本不实用.显然.Net 4.0将解决此问题.