Wrox Programmer Forums
BOOK: Beginning iOS 4 Application Development
This is the forum to discuss the Wrox book Beginning iOS 4 Application Development by Wei-Meng Lee; ISBN: 978-0-470-91802-9
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning iOS 4 Application Development section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old February 10th, 2011, 02:24 PM
Registered User
Join Date: Feb 2011
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Default Consuming a web service in your iPhone app

Hello guys,

I'm doing chapter 16 - web services

In the book a web service address(www.ecubicle.net/iptocountry.asmx) is given but unfortunly its not available.

So i'm using the following one: http://www.w3schools.com/webservices...nheitToCelsius

the problem is that the soap response is giving me the following error: Server did not recognize the value of HTTP Header SOAPAction: http://www.w3schools.com/webservices...nheitToCelsius.

<?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><soap:Fault><faultcode>soap:Client</faultcode><faultstring>Server did not recognize the value of HTTP Header SOAPAction: http://www.w3schools.com/webservices/tempconvert.asmx?op=FahrenheitToCelsius.</faultstring><detail /></soap:Fault></soap:Body></soap:Envelope>
Why is a dot at the end of the service ? maybe can be this causing my problem.

Take a look above at my code and soap request..



	//NSString *soapMsg = [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
	//					 "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\">"
	//					 "<soap:Body>"
	//					 "<FahrenheitToCelsius xmlns=\"http://tempuri.org/\">"
	//					 "<Fahrenheit>%@</Fahrenheit>"
	//					 "</FahrenheitToCelsius>"
	//					 "</soap:Body>"
	//					 "</soap:Envelope>", value_.text];
	NSString *soapMsg = [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
						 "<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/\">"
						 "<FahrenheitToCelsius xmlns=\"http://tempuri.org/\">"
						 "</soap:Envelope>", value_.text];
	NSURL *url = [NSURL URLWithString:@"http://www.w3schools.com/webservices/tempconvert.asmx"];
	NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
	NSString *msgLenght = [NSString stringWithFormat:@"%d", [soapMsg length]];
	[req addValue:@"tet/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
	[req addValue:@"http://www.w3schools.com/webservices/tempconvert.asmx?op=FahrenheitToCelsius" forHTTPHeaderField:@"soapaction"];
	[req addValue:msgLenght forHTTPHeaderField:@"Content-Lenght"];
	[req setHTTPMethod:@"POST"];
	[req setHTTPBody:[soapMsg dataUsingEncoding:NSUTF8StringEncoding]];
	[activityIndicator startAnimating];
	conn = [[NSURLConnection alloc] initWithRequest:req delegate:self];
	if (conn) {
		webData = [[NSMutableData data] retain];

-(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{
	[webData release];
	[connection release];

-(void) connectionDidFinishLoading:(NSURLConnection *)connection{
	NSLog(@"DONE. Received Bytes:%d",[webData length]);
	NSString *theXml = [[NSString alloc] initWithBytes:[webData mutableBytes] length:[webData length] encoding:NSUTF8StringEncoding];
	[theXml release];
	[activityIndicator stopAnimating];
	[connection release];
	[webData release];


<?xml version="1.0" encoding="utf-8"?><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/"><soap:Body><FahrenheitToCelsius xmlns="http://tempuri.org/"><Fahrenheit>55</Fahrenheit></FahrenheitToCelsius></soap:Body></soap:Envelope>
Old February 11th, 2011, 12:45 AM
Friend of Wrox
Join Date: Aug 2010
Posts: 298
Thanks: 1
Thanked 62 Times in 60 Posts

You have a few errors that need to be corrected.

[req addValue:@"tet/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"]; //typo text/xml

[req addValue:@"http://www.w3schools.com/webservices/tempconvert.asmx?op=FahrenheitToCelsius" forHTTPHeaderField:@"soapaction"];//incorrect should be
[req addValue:@"http://tempuri.org/FahrenheitToCelsius" forHTTPHeaderField:@"SOAPAction"];

As you can see from the page in your link
POST /webservices/tempconvert.asmx HTTP/1.1
Host: www.w3schools.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/FahrenheitToCelsius" This is the SOAPAction

[req addValue:msgLenght forHTTPHeaderField:@"Content-Lenght"]; // typo "Content-Length"

For working examples of the WebService refer to

Problem with web service example chapter 14

I have made two working examples of Web Services available including a Temperature Converter. Check for download links on a January 20 post from thepianoguy

These corrections should resolve your request error.
The Following User Says Thank You to thepianoguy For This Useful Post:
dapinheiro (February 11th, 2011)
Old February 11th, 2011, 06:17 AM
Registered User
Join Date: Feb 2011
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts


I've download your code, but i was able to receive a response from soap with your corrections ! Many thanks
Old February 11th, 2011, 08:44 AM
Friend of Wrox
Join Date: Aug 2010
Posts: 298
Thanks: 1
Thanked 62 Times in 60 Posts

Glad it worked. I didn't actually compile your code, just did a visual inspection, so I could have missed something.
The projects I did for the other forum (different book by the same author, identical project and, annoyingly, same lack of functionality that should have been addressed on the forum or in an errata, since it was pointed out months before this book was released) also include a working ipToCountry, extension of use of the xmlParser and implementations of all versions of the requests (SOAP 1.1, SOAP 1.2, HTTP_GET and HTTP_POST) when available.
I probably got more out the Chapter since project didn't work, since I had to find out a way to make it work. It seems you had the same mindset in looking for alternatives. However, I would prefer it if the Chapter project did work, and finding, and implementing another service was followup exercise or challenge.
Old May 30th, 2013, 10:40 AM
Registered User
Join Date: May 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Same code updated with blocks

I'm posting this code as I found this link useful. There are a few syntax errors, in the original answer.

        NSString *soapMessage = //form the soap envelope
        NSURL *url = [NSURL URLWithString:@"http://www.w3schools.com/webservices/tempconvert.asmx"];
	NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:url];
	[urlRequest addValue:@"text/xml"
	[urlRequest setHTTPMethod:@"POST"];
	[urlRequest setHTTPBody:[soapMessage
       [NSURLConnection sendAsynchronousRequest:urlRequest 
                                                            queue:[NSOperationQueue mainQueue] 
                                           completionHandler:^(NSURLResponse *response, 
                                                                        NSData *responseData,
                                                                        NSError *error) 
           NSString *responseString = [[NSString alloc]initWithData:responseData

Last edited by Anupdas; May 30th, 2013 at 10:44 AM.. Reason: Improved formatting

Similar Threads
Thread Thread Starter Forum Replies Last Post
Trouble consuming doc literal web service ... mussitsch Classic ASP XML 0 March 4th, 2009 02:43 PM
Consuming Web service with NuSoap CraigWhitfield PHP How-To 0 February 27th, 2008 11:20 AM
Consuming Web Service edgtr .NET Web Services 0 November 1st, 2006 03:50 PM
Consuming web service with dismal performance jcrossett ASP.NET 2.0 Professional 0 December 13th, 2005 11:19 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.