C# – Upload Image From iPhone to WCF Service

ciphoneobjective cwcf

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

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

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.

My WCF Service is a REST service.

Any help is much appreciated.

Best Answer

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.

Related Topic