1

Currently, the way our app works is we download a text file that describes the information we want. Then we use NSURLConnection and request that one packet that the text file describes. Then we ask for the next packet, wait for it to come in, check it, then ask for the next packet.

Is there a better way to do this without the text file? I feel like I should be able to have the app say, "InformationForJohnDoe" and then the server will just start sending all the packets for JohnDoe, but in this scenario, I don't know how I'd know which data is which in my connectionDidFinishLoading delegate method.

The web service implementation looks like this:

[WebGet(UriTemplate = "GetTestData/{file}")]
        public Stream GetTestData(string file)
        {

            string fileName =
               "\\testdirectory" + file;
            if (File.Exists(fileName))
            {
                FileStream stream = File.OpenRead(fileName);
                if (WebOperationContext.Current != null)
                {
                    WebOperationContext.Current.OutgoingResponse.ContentType = "text/.txt";
                }
                return stream;
            }
            return null;
        }

I'm not much of a C# person. I've only just started in C# and web services.

Rob
  • 415,655
  • 72
  • 787
  • 1,044
Crystal
  • 28,460
  • 62
  • 219
  • 393
  • Have you checked [this question](http://stackoverflow.com/questions/332276/managing-multiple-asynchronous-nsurlconnection-connections)? – Claudio Aug 08 '12 at 00:28
  • It sounds like what you are actually asking is how to change your C# web services to not use the text file. If that is the case, let's correct your tags so hopefully you'll get a better answer. – slf Aug 08 '12 at 02:49

1 Answers1

0

the Idea is that you append to a NSData you define in the class the NSData you get from the

-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data

method.

Then, in the

- (void)connectionDidFinishLoading:(NSURLConnection *)connection

method, you know that all data is completely loaded and ready for use.

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data 
{
    NSLog(@"Connection didReceiveData of length: %u", data.length);
    [self.dataData appendData:data];
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection 
{
   // do seomething with self.dataData


}
HeikoG
  • 1,793
  • 1
  • 20
  • 29