0

I have a service

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

that I call from a web page using jQuery

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

Here is the callback for the getJSON call:

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

And here is the configuration

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

This worked fine until I enabled SSL on my servers. Now the getJSON call succeeds but returns null. Please help me get this working over SSL. Thanks

My environment is .Net 3.5, IIS 7

Sisiutl
  • 4,915
  • 8
  • 41
  • 54
  • Have you enabled SSL on your service? http://stackoverflow.com/questions/425978/enable-ssl-for-my-wcf-service – Bryan Naegele Jan 13 '12 at 00:34
  • The service is part of a larger web site that has SSL enabled for the entire site. Do I need to do something explicitly for the service itself? – Sisiutl Jan 13 '12 at 03:44
  • Have a quick question regarding your configuration? Your config shows that the service class name and the contract name are the same "B2B.JsonServices.B2BServiceJson". Is that correct and was it working before without SSL with the same configuration – Rajesh Jan 13 '12 at 09:49

3 Answers3

1

This is what I ended up with and it works perfectly.

  <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>
Sisiutl
  • 4,915
  • 8
  • 41
  • 54
0

I am proposing to use:

<serviceMetadata httpsGetEnabled="true"/>

and a https binding:

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

in your serviceModel configuration.

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

Nicolas Modrzyk
  • 13,961
  • 2
  • 36
  • 40
0

A few things to do:

  1. Check for errors, either on the web server, jquery ( by adding an error function to the Ajax call parameter list), maybe try a http watcher to see what response is coming back from the server.
  2. Is the page itself accessed via ssl?
  3. Is the certificate you have used on the server trusted by the browser? In an Ajax call you can't manually accept a certitude with trust warnings so this may explain what is taking place.
Xhalent
  • 3,914
  • 22
  • 21
  • The service call is succeeding (status 200) but the result is null. The page is being called via SSL and works fine; only the ajax call fails. The cert is from a well-known commercial CA. – Sisiutl Jan 13 '12 at 13:10