问题描述
当尝试同时支持https和https时,我的WCF服务遇到配置问题.理想情况下,我想要在开发机器上运行http,然后发布到运行https的azure.
I'm running into a configuration problem with my WCF service when trying to support both https and https. Ideally what I'd like is to run http on my dev machine and then publish to azure running https.
我按照这些帖子尝试运行配置: http://jayakrishnagudla.blogspot.com/2009/12/configuring-wcf-services-to-work-with.html
I followed these posts to try and run the configuration:http://jayakrishnagudla.blogspot.com/2009/12/configuring-wcf-services-to-work-with.html
如何将单个WCF服务配置为具有多个HTTP和HTTPS端点?
我的Web.Config如下:
My Web.Config is as follows:
<system.serviceModel>
<services>
<service name="Backend.Services.UserService.UserService" behaviorConfiguration="">
<endpoint address=""
binding="webHttpBinding"
contract="Backend.Services.UserService.IUserService"
bindingConfiguration="HttpsBinding"
behaviorConfiguration="Web">
</endpoint>
<endpoint address=""
binding="webHttpBinding"
contract="Backend.Services.UserService.IUserService"
bindingConfiguration="HttpBinding"
behaviorConfiguration="Web"
>
</endpoint>
</service>
</services>
<bindings>
<webHttpBinding>
<binding name ="HttpBinding">
<security mode="None">
<transport clientCredentialType="None"/>
</security>
</binding>
<binding name="HttpsBinding">
<security mode="Transport"/>
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="Web">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<protocolMapping>
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
据我所知,根据上述链接,此配置应该正确.但是,当我通过http在本地构建和运行此服务时,出现以下错误:
As far as I can tell, this configuration should be correct according to the above links. However, when I build and run this service locally via http I get the following error:
Could not find a base address that matches scheme https for the endpoint with binding WebHttpBinding. Registered base address schemes are [http].
我不太确定问题出在哪里,并假设其配置错误.任何帮助,将不胜感激.
I'm not quite sure where the problem is and assume its a misconfiguration. Any help would be appreciated.
推荐答案
我已经尝试了好几天(实际上是几年,但几天前才重新开始),上面的帖子为我指明了正确的方向与 protocolMapping
一起使用,但是您需要在 protocolMapping
部分中指定 bindingConfiguration
,以使其选择< security mode = None>.或< security mode = Transport> ;:
I've been trying to do this for days (years actually, but just restarted a few days ago), and the post above pointed me in the right direction with protocolMapping
, but you need to specify the bindingConfiguration
in the protocolMapping
section to make it choose the <security mode=None> or <security mode=Transport>:
<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
<protocolMapping>
<add scheme="http" binding="basicHttpBinding" bindingConfiguration="ServiceBinding"/>
<add scheme="https" binding="basicHttpBinding" bindingConfiguration="ServiceBindingSSL"/>
</protocolMapping>
将 bindingConfiguration
属性保留在端点之外-它将根据协议自动设置.然后在您的绑定部分中设置第二个绑定配置:
Leave the bindingConfiguration
attribute off of the endpoint - it will be set automatically based on the protocol. Then set up the second binding configuration in your bindings section:
<basicHttpBinding>
<binding name="ServiceBinding" ...>
<security mode="None">
</security>
</binding>
<binding name="ServiceBindingSSL" ... >
<security mode="Transport">
</security>
</binding>
</basicHttpBinding>
这项技术对我有用.希望对您有帮助!
This technique worked for me. Hope it helps you!
这篇关于同时支持HTTP和HTTPS Web.Config WCF服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!