-2

I am in the process of creating an iPhone app that requires to interact with a .Net web service. I did some research this but a lot discussions on this website were outdated. So I thought it would be best to ask the question again and see if anyone of you can help me with this.

From the what I have read on other discussions, I can either use NSURLConnection or NSXMLParser to send and receive data. People have suggested I can use JSON as well. I am just starting to learn about web service. I'm just testing out some basic web methods on a web service that return a string. Nothing complex. What's the best way to achieve this functionality?

Thank you!

Update - Sorry I should've done some more research before posting the question. Now since I understood how to consume a web service on .net, I feel the question I asked was stupid and totally understand the down votes. Sorry!

wackytacky99
  • 614
  • 1
  • 14
  • 33

3 Answers3

1

I think you should go with the JSON format. It's faster to parse and lighter to download. Besides , there is no difference in the difficulty on the implementation. For parsing the data on the client size (your app) , I suggest the JSONKit library - it's the fastest around as far as I know. There are several speed tests available on the web. Like this one. NSURLConnection is very useful too. You can get response codes , fetch data , etc. JSON is obviously useful after you get that data.

Cheers!

George
  • 4,029
  • 1
  • 23
  • 31
0

It doesn't really matter how simple the response from your server method is. The idea of using a serialization format like JSON or XML is that you can guarantee that the message recd. by the client was an acceptable and parseable message.

Web services allows using JSON as its serialization format. Once you do that you can use Cocoa's built in JSON parser to parse out the response.

Devraj
  • 3,025
  • 24
  • 25
0

One useful tip that you may be able to use in your case is the following:

+ (NSString*)stringFromURL:(NSString*)urlString
{
    return [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString] encoding:NSUTF8StringEncoding error:nil];
}

You can use that line to get data from your server and then parse it if it's XML data. I typically don't use XML parsing. Instead, I just use query strings in the request URL and get a single string of data that is the specific value I am looking for.

And while I'm at it, you can convert the string you get from that method to integers or doubles or a lot of other types using the following:

int returnedInt = [[self stringFromURL:@"URL"] intValue];
double returnedDouble = [[self stringFromURL:@"URL"] doubleValue];

Hope this helps at least a little bit! And if not, maybe it'll help someone else down the line.