1

Ajax to consume WCF service hosted at server. I already configured and allowed following flag of JQM to use Cross-Domain Requests.

$.support.cors = true;
$.mobile.allowCrossDomainPages = true;

The same code is working with Android emulator and Device. I also allowed the url in config.xml file of Phonegap for IOS app.

Also I can browse the same HTML page in Safari and IOS emulator. In both webservice is working fine. The issue occurs when I build and run the phonegap app in IOS emulator or device. The service will not called and success callback of $.ajax is called. I checked the response in success and I found that it is returning the HTML of web service url page (.svc).

I used following code to call SVC using $.ajax

var soapRequest = '<?xml version="1.0" encoding="utf-8"?>'
                                    + '<soap:Envelope      xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">'
                                      + '<soap:Body>'
                                       + '<SignIn xmlns="http://tempuri.org/">'
                                          + '<UserName>' + $.trim($('#txtEmail').val()) + '</UserName>'
                                         + '<Password>' + $.trim($('#txtPassword').val()) + '</Password>'
                                         + '<DeviceDetails>' + GetDeviceInfo() + '</DeviceDetails>'
                                      + '</SignIn>'
                                     + '</soap:Body>'
                                   + '</soap:Envelope>';
            $.ajax({
                beforeSend: function (xhr) {
                    ShowLoading('Please wait...');
                    xhr.setRequestHeader("SOAPAction", "http://tempuri.org/IService/SignIn");
                }, //Show spinner
                complete: function () {
                    HideLoading();
                }, //Hide spinner
                url: "http://somedomain/service.svc",
                type: "POST",
                dataType: "xml",
                data: soapRequest,
                contentType: "text/xml; charset=\"utf-8\"",
                success: function (rcvdata, status) {
                   alert(rcvdata);  // THIS IS GIVING HTML OF SERVICE PAGE
                },
                error: function (request, status, error) {
                   alert(request + "\n" + status + "\n" + error);
                    HideLoading();
                }
            });

I also tied to change the value of async and processdata option of AJAX but it is always returning the svc service page html. Ajax request status is always 200.

This issue is only occurring in Phonegap IOS app. When I directly open the HTML page in IOS emulator browser then the service is called successfully and I got the valid SOAP response.

I am using Phonegap 2.8.1 and also tried in 2.9.0

Thanks in advance.

Edit --------------

I host the WCF service local environment in IIS then it is working fine and I got the response from service. I also checked and compare the IIS settings in local and live server. Both are same

4

0 回答 0