p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Beginning iPad Application Development (http://p2p.wrox.com/forumdisplay.php?f=575)
-   -   Problem with web service example chapter 14 (http://p2p.wrox.com/showthread.php?t=82076)

dontcallmejeff December 29th, 2010 07:13 PM

Problem with web service example chapter 14
 
Hello

I'm having a problem with the web service example. The spinner just spins and doesn't receive the information. I don't think the connection is being called. Does any one have a sollution for this.

Thanks

John

thepianoguy January 1st, 2011 03:53 PM

The site that is called is no longer active. (Enter the URL manually in your browser and also checkout the Console log)
There is an earlier posting regarding this that the author responded to.
http://p2p.wrox.com/book-beginning-i...site-down.html

Unfortunately this response is no longer valid. The query page no longer exists. The example was recycled for a subsequent book published in October, and readers of that book are having the same problem, and no response has been made from the author.
http://p2p.wrox.com/book-beginning-i...dead-link.html

Obviously when something like this breaks it is beyond the author's control, but considering that the example was reused, and the problem known before the latter book was published, it would make sense to prepare an online alternative for users of both books.

I had not done this chapter previously since I had no immediate need for Web Services. Now that my interest has been piqued, if I find an alternative source for the service I will let you know. Hopefully, the author will also provide an alternative.

thepianoguy January 9th, 2011 03:04 PM

For those interested an alternate site for the IPAddress is
http://www.webservicex.net/geoipservice.asmx
This page supports supports all 4 request formats, SOAP 1.1 and 1.2, HTTP GET and HTTP POST. The project can be built and run as intended after making the necessary changes.
Bob

adumas January 19th, 2011 01:18 PM

Hi... I've tried updating / making the changes using GeoIPService - but something is failing - it says bad request... My interest is also piqued because of a project I'm working on.

Are you still working on this project? I would love to talk about this off-line...
Let me know...

thepianoguy January 19th, 2011 02:08 PM

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

adumas January 19th, 2011 02:23 PM

Bob - that's great... I inserted the 1st routine and it worked fine.

If you could post all of the code for download, that would be great. I'm interested in seeing the temp example as well.

thepianoguy January 19th, 2011 03:34 PM

I will post links to the project files late tonight or early tomorrow morning, since I am away from my computer right now.
Bob

adumas January 19th, 2011 03:40 PM

Thanks Bob... By the way, I'd love to chat more about what you are doing and also a project I am working on.... Any way we can talk about this off-line?

GeezerRoy January 20th, 2011 10:44 AM

Link to Working Code?
 
Have you posted a link to the working code?

Thanks.

thepianoguy January 20th, 2011 11:56 AM

For those interested, a working example of the iptocountry project. All 4 request types are implemented, and a few interface and other tweaks have been made.
A second project demonstrating a temperature converter is also in the .zip.
https://files.me.com/thepianoguy88/q3k7xc
The file should automatically download to your default downloads location.
The link will expire in 30 days.
Questions/feedback/improvements are welcome, either in the forum or via email @
ipadhelper@me.com
Bob


All times are GMT -4. The time now is 01:51 AM.

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