Thursday, September 12, 2013

Upload image to .NET REST web service from iOS using AFNetworking

Previously I talked about calling a .NET REST full web service method that returns a object, now I’m going to talk about a how to upload a image using .NET REST web service. 

Here also I’m using AFNetworking. You can download it from here.

In this example I’m sending image as an NSInputStream. I’m sending the file name and the folder name, which the image should save in the server by adding as header fields to request object.

This how your web service interface method look like.



This is how your service method looks like


Here I can directly get the image data from the stream. I’m getting the image name and the folder name by calling this method from the incoming request.

WebOperationContext.Current.IncomingRequest.Headers.Get("folderName");

In iOS this is how you should call it. Hear I have written my method using blocks, so after calling the web service it will notify the caller.


As I told you earlier I’m converting the image to NSImputStream and assign it to the request operation object. And I have added folder name and the file name as request to herder fields.