C# 如何从web服务中获取stream类型的数据

C# 如何从web服务中获取stream类型的数据,c#,ios,objective-c,web-services,nsinputstream,C#,Ios,Objective C,Web Services,Nsinputstream,我想用相应的URL从服务器读取流数据,目前我正在尝试使用NSInputStream读取数据,但我收到错误“错误2操作无法完成。没有这样的文件或目录”。web开发人员接收字节格式的数据,然后将该数据转换为类似于MemoryStream(byteData)的流(注意:web服务是用.net编写的),并将其返回给我读取此类数据的方法是什么,我尝试了AISHTTPRequest,得到了大小为0字节的文件,我再次尝试了NSURLConnection,得到了大小为0字节的文件,现在我正在使用NSInputS

我想用相应的URL从服务器读取流数据,目前我正在尝试使用NSInputStream读取数据,但我收到错误“错误2操作无法完成。没有这样的文件或目录”。web开发人员接收字节格式的数据,然后将该数据转换为类似于MemoryStream(byteData)的流(注意:web服务是用.net编写的),并将其返回给我读取此类数据的方法是什么,我尝试了AISHTTPRequest,得到了大小为0字节的文件,我再次尝试了NSURLConnection,得到了大小为0字节的文件,现在我正在使用NSInputStream,我得到了开始时提到的错误。这是我的NSInputStream代码

如果可以,请指导我是否可以通过iOS作为前端读取此类数据 然后指导如何与此类数据交互。 如果NSInputStream是预期的交互方式,那么下面编写的代码有什么问题。

- (void)setUpStreamForFile {

    NSString *urlStr = @"http://192.168.1.201/example/example.svc/example?parameter={\"DCU_DocId\":\"05e24018-b728-4ec8-9848-d6cae02bec95\"}";

    // iStream is NSInputStream instance variable
    iStream = [[NSInputStream alloc] initWithFileAtPath:urlStr];
    [iStream setProperty:[NSDictionary dictionaryWithObjectsAndKeys:(id) kCFBooleanFalse,    kCFStreamSSLValidatesCertificateChain, nil ] forKey:(NSString *) kCFStreamPropertySSLSettings];
    [iStream setDelegate:self];
    [iStream scheduleInRunLoop:[NSRunLoop currentRunLoop]
                       forMode:NSDefaultRunLoopMode];
    [iStream open];
}

- (void)stream:(NSStream *)stream handleEvent:(NSStreamEvent)eventCode {
    _data = [[NSMutableData alloc] init];
    int bytesRead=0;

    switch(eventCode) {
        case NSStreamEventHasBytesAvailable:
        {
            if(!_data) {

            }
            uint8_t buf[20480];
            unsigned int len = 0;
            len = [(NSInputStream *)stream read:buf maxLength:20480];
            if(len) {
                [_data appendBytes:(const void *)buf length:len];
                // bytesRead is an instance variable of type NSNumber.
                //[bytesRead setIntValue:[bytesRead intValue]+len];
                bytesRead = bytesRead +len;
                NSLog(@"bytesRead:%d",bytesRead);
            }

            else {
                NSLog(@"no buffer!");
            }

            break;
        }
        case NSStreamEventEndEncountered:
        {
            [stream close];
            [stream removeFromRunLoop:[NSRunLoop currentRunLoop]
                              forMode:NSDefaultRunLoopMode];

            stream = nil; // stream is ivar, so reinit it
            break;
        }
        case NSStreamEventErrorOccurred:
        {
            NSError *theError = [stream streamError];
            UIAlertView *theAlert = [[UIAlertView alloc] initWithTitle:@"" message:[NSString stringWithFormat:@"Error %i: %@",[theError code], [theError localizedDescription]] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
            NSLog(@"Error %i %@",[theError code], [theError localizedDescription]);
            [theAlert show];

            [stream close];

            break;
        }
        case NSStreamEventOpenCompleted:
        {
            NSLog(@"EventOpen");
        }
        case NSStreamEventHasSpaceAvailable:
        {
             NSLog(@"EventHasSpac");
        }
        case NSStreamEventNone:
        {
            NSLog(@"EventNone");
        }
       }
}

它全部使用NSUrlConnection下载流数据。它得到了解决

我建议在iOS和.NETWeb服务之间使用JSON进行通信。这将迫使.Net开发人员以可在iOS应用程序中读取的JSON格式序列化字节流,如base64