I just tested and the update that I did still works.
Since the book project did not work, I looked for some alternatives. I found and experimented with a couple of options: a GeoIP locater and a Temperature Converter. I also implemented the parser for the return from all 4 calls, and set it to display the result in the
view as text rather than in an alertView.
These are the implementations of the various calls with the new address for the GeoIP:
Code:
-(void)soap1_1Request
{
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>"
"<GetGeoIP xmlns=\"http://www.webservicex.net/\">"
"<IPAddress>%@</IPAddress>"
"</GetGeoIP>"
"</soap:Body>"
"</soap:Envelope>",ipAddress.text];
NSLog(@"%@",soapMsg);
NSURL *url = [NSURL URLWithString:@"http://www.webservicex.net/geoipservice.asmx"];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%d",[soapMsg length]];
[req addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[req addValue:@"http://www.webservicex.net/GetGeoIP" forHTTPHeaderField:@"SOAPAction"];
[req addValue:msgLength forHTTPHeaderField:@"Content-Length"];
[req setHTTPMethod:@"POST"];
[req setHTTPBody:[soapMsg dataUsingEncoding:NSUTF8StringEncoding]];
[activityIndicator startAnimating];
[self connect:req];
}
-(void)soap1_2Request
{
NSString *soapMsg =
[NSString stringWithFormat:
@"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
"<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\">"
"<soap12:Body>"
"<GetGeoIP xmlns=\"http://www.webservicex.net/\">"
"<IPAddress>%@</IPAddress>"
"</GetGeoIP>"
"</soap12:Body>"
"</soap12:Envelope>",ipAddress.text];
NSLog(@"%@",soapMsg);
NSURL *url = [NSURL URLWithString:@"http://www.webservicex.net/geoipservice.asmx"];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%d",[soapMsg length]];
[req addValue:@"application/soap+xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[req addValue:msgLength forHTTPHeaderField:@"Content-Length"];
[req setHTTPMethod:@"POST"];
[req setHTTPBody:[soapMsg dataUsingEncoding:NSUTF8StringEncoding]];
[activityIndicator startAnimating];
[self connect:req];
}
-(void)httpGETRequest
{
NSString *queryString = [NSString stringWithFormat:@"http://www.webservicex.net/geoipservice.asmx/GetGeoIP?IPAddress=%@",ipAddress.text];
NSURL *url = [NSURL URLWithString:queryString];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
[req addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[req addValue:0 forHTTPHeaderField:@"Content-Length"];
[req setHTTPMethod:@"GET"];
[activityIndicator startAnimating];
[self connect:req];
}
-(void)httpPOSTRequest
{
NSString *postString = [NSString stringWithFormat:@"IPAddress=%@", ipAddress.text];
NSLog(@"%@",postString);
NSURL *url = [NSURL URLWithString:@"http://www.webservicex.net/geoipservice.asmx/GetGeoIP"];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%d",[postString length]];
[req addValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[req addValue:msgLength forHTTPHeaderField:@"Content-Length"];
[req setHTTPMethod:@"POST"];
[req setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]];
[activityIndicator startAnimating];
[self connect:req];
}
To test calling with the different options I set up a UISegmentedControl with the 4 options as part of the interface and rewrote the -buttonClicked method as follows
Code:
-(IBAction)buttonClicked:(id)sender;
{
[ipAddress resignFirstResponder];
switch ([reqFormat selectedSegmentIndex]) {
case SOAP1_1:
[self soap1_1Request];
break;
case SOAP1_2:
[self soap1_2Request];
break;
case HTTPGET:
[self httpGETRequest];
break;
case HTTPPOST:
[self httpPOSTRequest];
break;
default:
break;
}
}
If you are interested, I can make my amended project and the TemperatureConversion available to download. After checking those out, if there are questions, I can try to clarify anything that is unclear.
Bob