zic*_*c10 5 c# wcf web-services azure
在尝试同时支持 https 和 https 时,我的 WCF 服务遇到了配置问题。理想情况下,我想要的是在我的开发机器上运行 http,然后发布到运行 https 的 azure。
我按照这些帖子尝试运行配置:http : //jayakrishnagudla.blogspot.com/2009/12/configuring-wcf-services-to-work-with.html
如何将单个 WCF 服务配置为具有多个 HTTP 和 HTTPS 端点?
我的 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>
Run Code Online (Sandbox Code Playgroud)
据我所知,根据上述链接,此配置应该是正确的。但是,当我通过 http 在本地构建和运行此服务时,出现以下错误:
Could not find a base address that matches scheme https for the endpoint with binding WebHttpBinding. Registered base address schemes are [http].
Run Code Online (Sandbox Code Playgroud)
我不太确定问题出在哪里,并假设其配置错误。任何帮助,将不胜感激。
我已经尝试这样做了好几天(实际上是几年了,但几天前才重新启动),上面的帖子为我指明了正确的方向protocolMapping,但您需要bindingConfiguration在该protocolMapping部分中指定 ,以使其选择 <安全模式=无>或<安全模式=传输>:
<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
<protocolMapping>
<add scheme="http" binding="basicHttpBinding" bindingConfiguration="ServiceBinding"/>
<add scheme="https" binding="basicHttpBinding" bindingConfiguration="ServiceBindingSSL"/>
</protocolMapping>
Run Code Online (Sandbox Code Playgroud)
将属性保留bindingConfiguration在端点之外 - 它将根据协议自动设置。然后在绑定部分设置第二个绑定配置:
<basicHttpBinding>
<binding name="ServiceBinding" ...>
<security mode="None">
</security>
</binding>
<binding name="ServiceBindingSSL" ... >
<security mode="Transport">
</security>
</binding>
</basicHttpBinding>
Run Code Online (Sandbox Code Playgroud)
这项技术对我有用。希望对您有帮助!
你看过wcf协议映射配置部分吗?
<protocolMapping>
<add scheme="http" binding="wsHttpBinding"/>
<add scheme="https" binding="wsHttpBinding"/>
</protocolMapping>
Run Code Online (Sandbox Code Playgroud)
编辑:我不确定为什么您在 webHttpBinding 类型下配置了“https”绑定。难道您不应该同时定义 http webHttpBinding 和 wsHttpBinding 并将其分配给您的端点吗?
<webHttpBinding>
<binding name ="HttpBinding">
<security mode="None">
<transport clientCredentialType="None"/>
</security>
</binding>
</webHttpBinding>
<wsHttpBinding>
<binding name="wsHttpEndpointBinding">
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="None" />
<message clientCredentialType="UserName" />
</security>
</binding>
</wsHttpBinding>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8097 次 |
| 最近记录: |