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.
Code:
<?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..
CODE:
Code:
-(IBAction)btnConvertToCelsius:(id)sender{
//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/\">"
"<soap:Body>"
"<FahrenheitToCelsius xmlns=\"http://tempuri.org/\">"
"<Fahrenheit>%@</Fahrenheit>"
"</FahrenheitToCelsius>"
"</soap:Body>"
"</soap:Envelope>", value_.text];
NSLog(@"%@",soapMsg);
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];
NSLog(@"%@",theXml);
[theXml release];
[activityIndicator stopAnimating];
[connection release];
[webData release];
}
SOAP REQUEST:
Code:
<?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>