.net WCF 获取 HTTPS 400 错误请求,但与 Http 配合使用正常
本文关键字:Http 但与 获取 WCF HTTPS 请求 错误 net | 更新日期: 2023-09-27 17:55:51
我在Windows Server 2008 R2上有一个WCF。我有一个 SSL 证书。
使用IE,http URL 工作正常(我得到了我的数据),但使用 Https,我有一个 400 错误请求。
在我的 WCF 的 web.config 下面:
<?xml version="1.0" encoding="utf-8"?>
<bindings>
<basicHttpBinding>
<binding name="TransportSecurity">
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="ServiceRequestResourcesAspNetAjaxBehavior">
<webHttp defaultOutgoingResponseFormat="Json" />
</behavior>
<behavior name="ServiceRequestResourcesAspNetAjaxBehaviorHttps">
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="ServiceRequestResourcesBehaviors">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="ServiceRequestResourcesBehaviors"
name="BaseSite.ServiceRequestResources">
<endpoint address=""
behaviorConfiguration="ServiceRequestResourcesAspNetAjaxBehaviorHttps"
binding="basicHttpBinding"
bindingConfiguration="TransportSecurity"
contract="BaseSite.ServiceRequestResources" />
<endpoint address=""
behaviorConfiguration="ServiceRequestResourcesAspNetAjaxBehavior"
binding="webHttpBinding" contract="BaseSite.ServiceRequestResources" />
</service>
</services>
经过大量测试,它正在工作。我需要在webHttpBinding
而不是basicHttpBinding
中配置绑定部分,但我不知道为什么。
在我的绑定部分下方:
<bindings>
<webHttpBinding>
<binding name="TransportSecurity">
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
</binding>
</webHttpBinding>
</bindings>
对于您的部分,您是否尝试过为 HTTPS 添加终结点,如下所示:
<services>
<service behaviorConfiguration="ServiceRequestResourcesBehaviors"
name="BaseSite.ServiceRequestResources">
<endpoint address=""
behaviorConfiguration="ServiceRequestResourcesAspNetAjaxBehaviorHttps"
binding="basicHttpBinding"
bindingConfiguration="TransportSecurity"
contract="BaseSite.ServiceRequestResources" />
<endpoint address=""
behaviorConfiguration="ServiceRequestResourcesAspNetAjaxBehavior"
binding="webHttpBinding" contract="BaseSite.ServiceRequestResources" />
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
</service>
</services>