gpt4 book ai didi

WCF Rest - 在一个 ServiceContract 中混合 HTTP 和 HTTPS

转载 作者:可可西里 更新时间:2023-11-01 16:22:04 26 4
gpt4 key购买 nike

我目前有一个 Http Rest WCF4 服务,由 ServiceContract IEventService 定义,它仅通过 HTTP 公开。

我的任务是让一些 的 OperationContracts 只能在 HTTPS 上工作所以我将这些方法拆分成一个单独的 ServiceContract,称为 IEventServiceHTTPS

使用带有自签名证书的 IIS7.5 在我的开发箱上托管它,作为 IEventServiceHTTPS 一部分的方法在 HTTPS 上正常调用,而不是在 HTTP 上正常调用,正如预期的那样。

但是,IEventService 公开的 HTTP 方法现在不起作用。

我在尝试访问 HTTP 方法时得到以下信息:

HTTP Error 403.4 - Forbidden
The page you are trying to access is secured with Secure Sockets Layer (SSL).

带有我的更改的 web.config:

<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true">
<serviceActivations>
<add service="Api.EventService" relativeAddress="EventService.svc" factory="Api.UnityServiceHostFactory"/>
</serviceActivations>
</serviceHostingEnvironment>
<behaviors>
<serviceBehaviors>
<behavior name="Api.EventServiceBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="WebBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="Api.EventServiceBehavior" name="Api.EventService">
<endpoint address="" binding="webHttpBinding" behaviorConfiguration="WebBehavior" bindingConfiguration="webBindingHTTP" contract="Api.IEventService"/>
**<endpoint address="" binding="webHttpBinding" behaviorConfiguration="WebBehavior" bindingConfiguration="webBindingHTTPS" contract="Api.IEventServiceHTTPS"/>**
</service>
</services>
<bindings>
<webHttpBinding>
<binding name="webBindingHTTP">
<security mode="None"></security>
</binding>
**<binding name="webBindingHTTPS">
<security mode="Transport">
</security>
</binding>**
</webHttpBinding>
</bindings>
</system.serviceModel>

非常感谢任何帮助,谢谢。

最佳答案

我认为此错误是由于 IIS vdir [SSL 设置]-> 要求 SSL -> true 引起的。如果您希望在同一服务中同时访问 http 和 https 端点,请取消选中此设置,因为这将阻止您在 vdir 中执行不安全的 http。

关于WCF Rest - 在一个 ServiceContract 中混合 HTTP 和 HTTPS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15092081/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com