• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1776
  • Last Modified:

Jquery/ajax/WCF over SSL?

Is there anything special I have to do in order to make JQuery .ajax work with a WCF Rest service over SSL (or is there something I need to do with the WCF to allow it to work over SSL)?

Everything works fine when it's over http but when I enable https it stops working.
0
fredstov
Asked:
fredstov
1 Solution
 
mwochnickCommented:
here's an article that might point you in the right direction, but its hard to tell without knowing more about the actual call you are making and the actual errors you are getting.
http://stackoverflow.com/questions/1478680/why-does-wcf-web-service-hosted-in-iis-over-ssl-result-in-403-forbidden-jquer
what error are you getting in the browser?
is the reuest actually making it to the server?
what does the jquery code that makes the call look like?
what does the service configuration look like?

0
 
leakim971PluritechnicianCommented:
protocols and domain used in url of the client and the server (address used by the ajax call) must match.

the page doing the call need to use ssl and the address of the service too.
0
 
fredstovAuthor Commented:
The service is on the same site in a sub directory so everything is under SSL. I'm using a relative path from the jquery call. The data going back and forth is Json data.

IHI:
[OperationContract(Name = "GetQuote")]
        [ServiceKnownType(typeof(HIQuoteObject))]
        [WebInvoke(UriTemplate = "/GetQuote", ResponseFormat = WebMessageFormat.Json,
                                           RequestFormat = WebMessageFormat.Json,
                                           BodyStyle = WebMessageBodyStyle.Bare,
                                           Method = "POST")]
        HIResultObject GetHIQuote(HIQuoteObject hi);

Open in new window


$.ajax({
        type: "POST",
        url: "API/HI.svc/GetQuote",
        data: tempJ,
        contentType: "application/json",
        success: function (data, textStatus, XMLHttpRequest) {

            //DO a bunch of stuff
        },
        error: function (xhr, status, error) {
           
            
            var tempText = "";
            for (prop in xhr) {
            tempText = tempText + xhr[prop];
            }
            alert("error:" + tempText);        }
    });

Open in new window


Web Config:
<system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="false"
      multipleSiteBindingsEnabled="true" />
    
    <services>
      <service name="Enroll2011.API.CensusSearch">
        <endpoint address="" behaviorConfiguration="SearchServiceBehavior"
                  binding="webHttpBinding" contract="Enroll2011.API.ICensusSearch" />
        
      </service>
      <service name="Enroll2011.API.enroll">
        <endpoint address="" behaviorConfiguration="EnrollServiceBehavior"
                  binding="webHttpBinding" contract="Enroll2011.API.Ienroll" />
      </service>
      <service name="Enroll2011.API.HI">
        <endpoint address="" behaviorConfiguration="HIServiceBehavior"
                  binding="webHttpBinding" contract="Enroll2011.API.IHI" />
      </service>
      <service name="Enroll2011.API.DIS">
        <endpoint address="" behaviorConfiguration="DISServiceBehavior"
                  binding="webHttpBinding" contract="Enroll2011.API.IDIS" />
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior name="SearchServiceBehavior">
          <webHttp />
          
        </behavior>
        <behavior name="EnrollServiceBehavior">
          <webHttp />
        </behavior>
        <behavior name="HIServiceBehavior">
          <webHttp />
        </behavior>
        <behavior name="DISServiceBehavior">
          <webHttp />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="">
          <serviceMetadata httpsGetEnabled="true" httpGetEnabled="true" />
          
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

Open in new window

0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
fredstovAuthor Commented:
ok, I've been able to narrow it down to the web.config and, after changing some settings, it works now. However...is there a way to get it to seamlessly work between my non-https test environment and the live https server without having to go in and comment stuff out in the config before I publish?

New Web.Config code:
<system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="false"
      multipleSiteBindingsEnabled="true" />
    
    <services>
      <service name="Enroll2011.API.CensusSearch">
        <endpoint address="" bindingConfiguration="httpsBinding" behaviorConfiguration="SearchServiceBehavior"
                  binding="webHttpBinding" contract="Enroll2011.API.ICensusSearch" />
        
      </service>
      <service name="Enroll2011.API.enroll">
        <endpoint address="" bindingConfiguration="httpsBinding"  behaviorConfiguration="EnrollServiceBehavior"
                  binding="webHttpBinding" contract="Enroll2011.API.Ienroll" />
      </service>
      <service name="Enroll2011.API.HI">
        <endpoint address="" bindingConfiguration="httpsBinding" behaviorConfiguration="HIServiceBehavior"
                  binding="webHttpBinding" contract="Enroll2011.API.IHI" />
      </service>
      <service name="Enroll2011.API.DIS">
        <endpoint address="" bindingConfiguration="httpsBinding" behaviorConfiguration="DISServiceBehavior"
                  binding="webHttpBinding" contract="Enroll2011.API.IDIS" />
      </service>
    </services>

    <behaviors>
      <endpointBehaviors>
        <behavior name="SearchServiceBehavior">
          <webHttp />
        </behavior>
        <behavior name="EnrollServiceBehavior">
          <webHttp />
        </behavior>
        <behavior name="HIServiceBehavior">
          <webHttp />
        </behavior>
        <behavior name="DISServiceBehavior">
          <webHttp />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="ServBeh">
          <serviceMetadata httpsGetEnabled="true" httpGetEnabled="true" />
          
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <webHttpBinding>
        <binding name="httpsBinding">
          <security mode="Transport" />
        </binding>
      </webHttpBinding>
    </bindings>
  </system.serviceModel>

Open in new window

0
 
mwochnickCommented:
Not that I'm aware of - we generally put environment specific configuration information in its own file and include it in the web config - we only deploy the "correct" one to each environment using deployment scripts that are environment aware.
0
 
tushar_keCommented:
One thing that we did was exposed 2 endpoints, one for http and one for https. No need to change web config that way.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now