我正在尝试构建一个 iPhone 应用程序和 c# WCF 服务以将图像上传到 SQL 服务数据库。
我的应用程序将图像分解为 NSData 并使用以下代码发布到 WCF 服务:
NSData *imageData = UIImageJPEGRepresentation(self.image, 90);
NSURL *url = [NSURL URLWithString:@"http://example.com/ImageDiaryService.svc/json/AddMediaItem"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:@"Test" forKey:@"Name"];
[request setPostValue:@"Test description." forKey:@"Description"];
[request setPostValue:@"JPEG" forKey:@"ImageType"];
[request setPostValue:@"iPhone" forKey:@"MediaType"];
[request setData:imageData withFileName:@"myphoto.jpg" andContentType:@"image/jpeg" forKey:@"ImageData"];
[request setDidFinishSelector:@selector(uploadFinished:)];
[request setDidFailSelector:@selector(uploadFailed:)];
[request setDelegate:self];
[request startAsynchronous];
我遇到的问题是网络服务。我不确定应该从应用程序 POST 接收什么类型的数据。我尝试过以字节数组的形式接收它,但这不起作用。
我的 WCF 服务是 REST 服务。
非常感谢任何帮助。
最佳答案
尝试将其作为流接收。博客文章位于http://blogs.msdn.com/b/carlosfigueira/archive/2008/04/17/wcf-raw-programming-model-receiving-arbitrary-data.aspx演示如何在 WCF REST 服务中接收任意数据。
关于c# - 将图像从 iPhone 上传到 WCF 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6011595/