我可以根据客户端要使用的协议向客户端隐藏 http 端点或 https 端点吗
我已按照此处的各种说明来配置我的 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 中手动删除不需要的重复端点来消除该错误,但我的偏好是在设置服务引用时首先不要显示它们。
这可能吗?
I've followed various instructions from here to configure my WCF service to support both http and https. Basically, they've all pretty much pointed out that I need to duplicate my endpoints for each protocol, so my server is configured like this:
<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>
So I've got different bindings, one for http, and one for https for each endpoint.
My issue is when I create a client for this webservice using Visual Studio 2010 Service References. I'd like to be able to just point the service reference to either:
http://mysite.com/myapp/servicelibrary.svc
or
https://mysite.com/myapp/servicelibrary.svc
My ideal scenario is if the service reference is using http or https, only the appropriate endpoints using the same protocol are pulled into the client app.config file. As it is, if I reference the http servicelibrary, I get both pairs of endpoints like this:
<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>
So, when I try to access a function from AuthenticationService, I get this error:
An endpoint configuration section for contract 'Services.IAuthenticationService' could not be loaded because more than one endpoint configuration for that contract was found. Please indicate the preferred endpoint configuration section by name.
I know I can get rid of the error by manually removing the unwanted duplicate endpoints from my app.config on my client, but my preference would be for them not to show up in the first place when setting up the service reference.
Is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论