【发布时间】:2015-09-15 07:49:26
【问题描述】:
在尝试同时支持 https 和 https 时,我的 WCF 服务遇到了配置问题。理想情况下,我想要在我的开发机器上运行 http,然后发布到运行 https 的天蓝色。
我按照这些帖子尝试运行配置: http://jayakrishnagudla.blogspot.com/2009/12/configuring-wcf-services-to-work-with.html
How to configure a single WCF Service to have multiple HTTP and HTTPS endpoints?
我的Web.Config如下:
<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 在本地构建和运行此服务时,出现以下错误:
Could not find a base address that matches scheme https for the endpoint with binding WebHttpBinding. Registered base address schemes are [http].
我不太确定问题出在哪里,并认为是配置错误。任何帮助,将不胜感激。
【问题讨论】:
-
这可能是因为您将服务配置为使用 https 运行,但是,当 .NET 开发服务器加载您的应用程序时,它没有使用 https。设置一个测试,部署在你的开发机器上的 IIS 下并访问 http://DEVBOX/myapp。如果您的应用配置正确,则不会出现错误。
-
是的,如果我使用 https//DEVBOX/myapp,我会收到“连接被拒绝”,因为我没有在我的开发机器上配置 https 证书,但是如果我使用 http//DEVBOX/myapp我可以成功地看到可用的服务。该错误仅在我尝试访问 .svc 服务时发生。在此之前,一切都可以通过开发箱上的 http 正常工作。
标签: c# web-services wcf azure