Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I think asmx webservices are SOAP webservices you should read my blog entry here - </p> <p><a href="http://www.makebetterthings.com/iphone/call-soap-web-service-from-iphone/" rel="nofollow">http://www.makebetterthings.com/iphone/call-soap-web-service-from-iphone/</a></p> <p>To call a SOAP service first i create a string with the SOAP request as follows.</p> <pre><code> NSString *soapMessage = @"&lt;?xml version="1.0" encoding="utf-8"?&gt;n" "&lt;soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"&gt;n" "&lt;soap:Body&gt;n" "&lt;CelsiusToFahrenheit xmlns="http://tempuri.org/"&gt;n" "&lt;Celsius&gt;50&lt;/Celsius&gt;n" "&lt;/CelsiusToFahrenheit&gt;n" "&lt;/soap:Body&gt;n" "&lt;/soap:Envelope&gt;n"; After creating the SOAP request I create a NSMutableRequest to send this request to server. NSURL *url = [NSURL URLWithString:@"http://w3schools.com/webservices/tempconvert.asmx"]; NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url]; NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]]; [theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"]; [theRequest addValue: @"http://tempuri.org/CelsiusToFahrenheit" forHTTPHeaderField:@"SOAPAction"]; [theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"]; [theRequest setHTTPMethod:@"POST"]; [theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]]; NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self]; if( theConnection ) { webData = [[NSMutableData data] retain]; } else { NSLog(@"theConnection is NULL"); } </code></pre> <p>After firing the request we can collect the XML response in the NSURLConnection’s delegate methods.</p> <pre><code>-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { [webData setLength: 0]; } -(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { [webData appendData:data]; } -(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { NSLog(@"ERROR with theConenction"); [connection release]; [webData release]; } -(void)connectionDidFinishLoading:(NSURLConnection *)connection { NSLog(@"DONE. Received Bytes: %d", [webData length]); NSString *theXML = [[NSString alloc] initWithBytes: [webData mutableBytes] length:[webData length] encoding:NSUTF8StringEncoding]; NSLog(@"%@",theXML); [theXML release]; } </code></pre> <p>After collecting the XML response in theXML string in -(void)connectionDidFinishLoading:(NSURLConnection *)connection we can parse this string using <a href="http://www.tbxml.co.uk/TBXML/TBXML_Free.html" rel="nofollow">TBXML</a> for any other XML parser you like.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload