需要帮助让getJSON通过SSL工作

时间:2012-01-13 00:25:09

标签: jquery wcf ssl getjson

我有服务

[OperationContract]
[WebGet(ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
public Customer GetCustomer(string customerNumber)
{
    return _service.GetCustomer(customerNumber);
}

我使用jQuery从网页调用

    var customerNumber = '123456';
    $.getJSON('/JsonServices/B2BServiceJson.svc/GetCustomer', { customerNumber: customerNumber }, customerSelected);

以下是getJSON调用的回调:

// HELP! result is null when SSL is enabled
function customerSelected(result) { 
    var customer = result.GetCustomerResult;
    var email = customer.Email;
    // other stuff
}

这是配置

  <system.serviceModel>
    <services>
      <service name="B2B.JsonServices.B2BServiceJson">
        <endpoint address="" binding="webHttpBinding" contract="B2B.JsonServices.B2BServiceJson"
                  behaviorConfiguration="ajaxBehavior" />
      </service>
    </services>


<behaviors>
  <endpointBehaviors>
    <behavior name="ajaxBehavior">
      <webHttp />
    </behavior>
  </endpointBehaviors>
</behaviors>

<!-- other stuff -->

在我的服务器上启用SSL之前,此工作正常。现在getJSON调用成功但返回null。 请帮我解决这个问题。感谢

我的环境是.Net 3.5,IIS 7

3 个答案:

答案 0 :(得分:1)

这就是我最终的结果,它完美无瑕。

  <system.serviceModel>
    <services>
      <service name="B2B_lite.JsonServices.B2BLiteServiceJson">
        <!-- SSL -->
        <endpoint address="" binding="webHttpBinding" contract="B2B.JsonServices.B2BServiceJson"
                  bindingConfiguration="webHttpsBinding" behaviorConfiguration="restBehavior"/>
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior name="restBehavior">
          <webHttp />
        </behavior>
      </endpointBehaviors>
    <bindings>
      <webHttpBinding>
        <binding name="webHttpsBinding" closeTimeout="00:00:20">
          <security mode="Transport">
            <transport clientCredentialType="None" />
          </security>
        </binding>
      </webHttpBinding>
    </bindings>
  </system.serviceModel>

答案 1 :(得分:0)

我建议使用:

<serviceMetadata httpsGetEnabled="true"/>

和https绑定:

 <endpoint address="mex" 
           binding="mexHttpsBinding" 
           contract="IMetadataExchange"/>

在您的serviceModel配置中。

<system.serviceModel>
     <bindings>
            <wsHttpBinding>
                    <binding name="wsHttpEndpointBinding">
                            <security mode="Transport">
                                    <transport clientCredentialType ="None"/>
                            </security>
                    </binding>
            </wsHttpBinding>
    </bindings>
    <services>
        <service 
             behaviorConfiguration="App_WcfWebService.AppWebServiceBehavior"
             name="App_WcfWebService.AppWebService">
          <endpoint 
             address="" 
             binding="wsHttpBinding" 
             bindingConfiguration ="wsHttpEndpointBinding"
             contract="App_WcfWebService.IAppWebService">
           </endpoint>
           <endpoint 
             address="mex" 
             binding="mexHttpsBinding" 
             contract="IMetadataExchange"/>
            </service>
    </services>

    <behaviors>
            <serviceBehaviors>
                    <behavior name="App_WcfWebService.AppWebServiceBehavior">
                      <serviceMetadata httpsGetEnabled="true"/>
                      <serviceDebug includeExceptionDetailInFaults="true"/>
            <serviceThrottling maxConcurrentSessions="90" />                    
                    </behavior>
            </serviceBehaviors>
    </behaviors>

答案 2 :(得分:0)

要做的一些事情:

  1. 检查Web服务器上的错误,jquery(通过向Ajax调用参数列表添加错误函数),也可以尝试使用http观察器查看从服务器返回的响应。
  2. 页面本身是通过ssl访问的吗?
  3. 您在服务器上使用的证书是否受浏览器信任?在Ajax调用中,您无法手动接受具有信任警告的确认,因此这可以解释正在发生的事情。