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
LVL 4
derftoyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

osmantemizCommented:
just make your webmethod type void and set output by

Context.Response.Output.Write(yourJsonString);

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
derftoyAuthor Commented:
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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

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.