将图像从iPhone上传到WCF服务 [英] Upload Image From iPhone to WCF Service

查看:103
本文介绍了将图像从iPhone上传到WCF服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建一个iPhone应用程序和c#WCF服务,以将图像上传到SQL服务数据库。

I'm trying to build an iPhone app and c# WCF Service to upload an image to a SQL Service database.

我的应用程序打破了图像使用以下代码下载到NSData并发布到WCF服务:

I've got my app breaking an image down to NSData and posting off to a WCF Service using the following code:

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];

我遇到的问题是网络服务。我不确定应该从app POST接收什么类型的数据。我已经尝试接收它作为一个字节数组,但是没有用。

The problem I'm having is with the web service. I'm not sure what type of data I should be receiving from the app POST. I've tried receiving it as an a byte array but that didn't working.

我的WCF服务是一个REST服务。

My WCF Service is a REST service.

非常感谢任何帮助。

推荐答案

尝试将其作为流接收。博客文章 http://blogs.msdn.com/b/carlosfigueira/archive/2008/04/17/wcf-raw-programming-model-receiving-arbitrary-data.aspx 展示了如何接收任意数据在WCF REST服务中。

Try receiving it as a Stream. The blog post at http://blogs.msdn.com/b/carlosfigueira/archive/2008/04/17/wcf-raw-programming-model-receiving-arbitrary-data.aspx shows how to receive arbitrary data in a WCF REST service.

这篇关于将图像从iPhone上传到WCF服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆