2

我已按照此处的各种说明配置我的 WCF 服务以支持 http 和 https。基本上,他们几乎都指出我需要为每个协议复制我的端点,所以我的服务器配置如下:

<service behaviorConfiguration="MyApp.WebServices.ServiceBehavior" name="MyApp.WebServices.ServiceLibrary">
    <endpoint address="" binding="basicHttpBinding" bindingConfiguration="basicHttpsBinding" name="AuthenticationService" contract="MyApp.WebServices.IAuthenticationService" />

    <!-- HTTP enpoints -->
    <endpoint address="" binding="basicHttpBinding" bindingConfiguration="basicBinding" name="AuthenticationService" contract="MyApp.WebServices.IAuthenticationService" />
</service>

所以我有不同的绑定,一个用于 http,一个用于每个端点的 https。

我的问题是当我使用 Visual Studio 2010 服务参考为此 Web 服务创建客户端时。我希望能够将服务引用指向以下任一:

http://mysite.com/myapp/servicelibrary.svc

或者

https://mysite.com/myapp/servicelibrary.svc

我的理想方案是,如果服务引用使用 http 或 https,则只有使用相同协议的适当端点被拉入客户端 app.config 文件。事实上,如果我引用 http 服务库,我会得到两对端点,如下所示:

<client>
    <endpoint address="https://ip-0af84f03/myapp/ServiceLibrary.svc"
        binding="basicHttpBinding" bindingConfiguration="AuthenticationService"
        contract="Services.IAuthenticationService" name="AuthenticationService" />
    <endpoint address="http://mysite.com/myapp/ServiceLibrary.svc"
            binding="basicHttpBinding" bindingConfiguration="AuthenticationService1"
            contract="Services.IAuthenticationService" name="AuthenticationService1" />
</client>

因此,当我尝试从 AuthenticationService 访问函数时,我收到此错误:

无法加载合同“Services.IAuthenticationService”的端点配置部分,因为找到该合同的多个端点配置。请按名称指明首选端点配置部分。

我知道我可以通过从客户端上的 app.config 中手动删除不需要的重复端点来消除该错误,但我的偏好是在设置服务引用时不首先显示它们。

这可能吗?

4

0 回答 0