2012-01-13 66 views
0

工作,我有一个服务需要帮忙的getJSON通过SSL

[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。 请帮我通过SSL获取此工作。由于

我的环境是净3.5,IIS 7

+0

您是否在服务上启用了SSL? http://stackoverflow.com/questions/425978/enable-ssl-for-my-wcf-service – 2012-01-13 00:34:10

+0

该服务是为整个站点启用了SSL的大型网站的一部分。我是否需要明确地为服务本身做些事情? – Sisiutl 2012-01-13 03:44:43

+0

有关于您的配置的快速问题?您的配置显示服务类名称和合同名称是相同的“B2B.JsonServices.B2BServiceJson”。是否正确,是否在没有SSL的情况下使用相同的配置 – Rajesh 2012-01-13 09:49:55

回答

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

+0

谢谢,但那没有奏效。你有什么其他的事情可以尝试吗? – Sisiutl 2012-01-13 03:43:25

0

有几件事情要做:

  1. 检查错误,无论是网络服务器,jQuery的上(通过增加误差函数对Ajax调用参数列表),也许尝试一个http观察者来查看从服务器返回的响应。
  2. 页面本身是否通过ssl访问?
  3. 您在服务器上使用的证书是否受浏览器信任?在Ajax调用中,您无法手动接受带有信任警告的确认,以便解释发生的情况。
+0

服务调用成功(状态200),但结果为空。该页面正在通过SSL调用并正常工作;只有ajax调用失败。证书来自知名的商业CA. – Sisiutl 2012-01-13 13:10:48