2012-01-13 62 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