locked
Cross-Domain JQuery Ajax call to WCF Service with BasicHttpbinding RRS feed

  • Question

  • I have a WCF service with "BasicHttpbinding" binding in place.I can gracefully call the service using JQuery in Internet Explorer. But the same code does not work in Chrome or FireFox. I can understand there is a Cross-Domain issue with JQuery Ajax call from Chrome or FireFox. I know I can expose a "webHttpBinding" binding with crossDomainScriptAccessEnabled="true" and call the service. But if there is a scanario that , I have to go with the existing "BasicHttp" binding then what is the solution? I have called the WCF service with the following JQuery code:

    $.ajax({
                      type
    : "POST",
                      url
    : "http://localhost:1415/MyService.svc/bh/",
                      data
    : bhRequest,
                      timeout
    : 10000,
                      contentType
    : "text/xml",
                      dataType
    : "xml",
                      beforeSend
    : function (xhr) {
                          xhr
    .setRequestHeader("SOAPAction", "http://tempuri.org/IMyService/GetData");
                     
    },
                      success
    : function (data) {
                          $
    (data).find("GetDataResponse").each(function () {
                              alert
    ($(this).find("GetDataResult").text());
                         
    });
                     
    },
                      error
    : function (xhr, status, error) {
                          alert
    (error);

                     
    }
                 
    });

    Thursday, January 3, 2013 2:03 PM

Answers

  • Hi,

    As far as I know, if you call the WCF service from FireFox or Chrome, there indeed a cross domain issue, after .NET 4.0, there is a property crossDomainScriptAccessEnabled (that you have mentioned above) that determines if cross domain script access is enabled, but the property is not available for basicHttpBinding. REST/JSONP is an alternative way for Cross-Origin Resource Sharing.

    Best Regards.


    Haixia
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Haixia_Xie Tuesday, January 15, 2013 12:54 AM
    Tuesday, January 8, 2013 2:54 AM