Link to home
Start Free TrialLog in
Avatar of derftoy
derftoyFlag for United States of America

asked on

Call ASP.NET Webservice with Soap and get back JSON

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="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>
        <AuthenticateUserResponse xmlns="http://www.bitcosoftware.com/">
            <AuthenticateUserResult>
                ["Authentication Error: Please provide a Username and Password"]
            </AuthenticateUserResult>
        </AuthenticateUserResponse>
    </soap:Body>
</soap:Envelope>

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

Thanks,
Cory Jorgensen
Bitco Software
ASKER CERTIFIED SOLUTION
Avatar of osmantemiz
osmantemiz

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of derftoy

ASKER

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="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><AuthenticateUserResponse xmlns="http://www.bitcosoftware.com/" /></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?

Thanks,
Cory