Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 587
  • Last Modified:

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
0
derftoy
Asked:
derftoy
1 Solution
 
osmantemizCommented:
just make your webmethod type void and set output by

Context.Response.Output.Write(yourJsonString);

Open in new window

0
 
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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now