.net WCF获取HTTPS 400错误请求但可以正常使用Http

时间:2013-01-24 13:20:47

标签: c# .net wcf ssl https

我在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>

2 个答案:

答案 0 :(得分:3)

经过大量的测试,它正在发挥作用。我需要在webHttpBinding而不是basicHttpBinding中配置绑定部分,但我不知道为什么。

在我的绑定部分下面:

<bindings>
    <webHttpBinding>
        <binding name="TransportSecurity">
            <security mode="Transport">
                <transport clientCredentialType="None" />
            </security>
        </binding>
    </webHttpBinding>
</bindings>

答案 1 :(得分:0)

对于您的部分,您是否尝试过为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>