Call ASP.NET Webservice with Soap and get back JSON

Posted on 2011-10-20
Last Modified: 2012-05-12
I am developing an iPad app that calls my ASP.NET Webservice.  I am sending a SOAP request which works great.  The response I am getting back is in XML wrapped around my JSON result.  

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="" xmlns:xsi="" xmlns:xsd="">
        <AuthenticateUserResponse xmlns="">
                ["Authentication Error: Please provide a Username and Password"]

Open in new window

My Webserivice has [ScriptMethod(ResponseFormat = ResponseFormat.Json)] but it is returning the above statement.  I only want the JSON data that is bold.

Is this possible?

And for those wondering... I have the code already to create the soap requests, but I didn't want to mess with XMLParsing to get my results, as I read more and more, JSON and the JSON Framework for XCODE and IOS that I got works great for parsing and returning my data with one line of code...

Cory Jorgensen
Bitco Software
Question by:derftoy
    LVL 3

    Accepted Solution

    just make your webmethod type void and set output by


    Open in new window

    LVL 4

    Author Comment

    Ok, that kind of works... but my response is now this:

    2011-10-20 09:21:09.266 PT Mobile[7428:11603] Data: ["8085a2a1-e6bc-422b-969a-695ce303b7a0"]<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="" xmlns:xsi="" xmlns:xsd=""><soap:Body><AuthenticateUserResponse xmlns="" /></soap:Body></soap:Envelope>

    Now, if I open up a web browser and call the function, I only get the JSON response.  Through the connection in iOS it seems to tack on the xml soap envelope to the response...

    This is how I am calling the request in iOS:

    -(void)startConnectionWithSoapAction:(NSString *)sa soapEnvelope:(NSString *)sEnvelope
        isConnectionFinished = NO;
        NSLog(@"SOAP Envelope: %@", sEnvelope);
        NSMutableString *url = [[NSMutableString alloc]  initWithString:[AppSettings userDefaultsValueByString:DV_PermitTraxServiceURL]];
        [url appendString:@"/WS_PermitInfo.asmx"];
        [url autorelease];
        NSURL *myWebserverURL = [NSURL URLWithString:url];
    	NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:myWebserverURL]; 
    	[request addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
        [request addValue:sa forHTTPHeaderField:@"SOAPAction"];
    	NSString *contentLengthStr = [NSString stringWithFormat:@"%d", [sEnvelope length]];
    	[request addValue:contentLengthStr forHTTPHeaderField:@"Content-Length"];
        [request setHTTPMethod:@"POST"];
        [request setHTTPBody:[sEnvelope dataUsingEncoding:NSUTF8StringEncoding]];
        connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
        NSLog(@"Fire Off Request");

    Open in new window

    Any clues why the data returned is the JSON and then the Soap XML?


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now