I am trying to upload a photo from iphone to a restful wcf. I have tried many times but failed. Here is some code of mine
Code from client
-(IBAction)uploadClick:(id)sender{
NSString *surl = @"http://192.168.5.226:8068/FileService.svc/UploadFile" ;
NSURL *url = [NSURL URLWithString:surl];
ASIFormDataRequest *r = [ASIFormDataRequest requestWithURL:url];
[r setValidatesSecureCertificate:NO];
[r setTimeOutSeconds:30];
[r setRequestMethod:@"POST"]; //default is POST (insert),
[r setDelegate:self];
[r setDidFailSelector:@selector(requestDidFail:)];
//[r addRequestHeader:@"Content-Type" value:@"application/json"] this will cause the call to fail. No content-type header for this call.
NSMutableData *imageData = [NSMutableData dataWithData:UIImageJPEGRepresentation([UIImage imageWithData:self.pickedFileContent], .35)];
[r setPostBody:imageData];
[r setDidFinishSelector:@selector(imageSaveDidFinish:)];
[r startAsynchronous];}
Code from restful wcf:
public interface IFileService
{
[OperationContract, WebInvoke(UriTemplate = "UploadFile", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare, Method = "POST")]
void UploadFile( Stream fileContent);
}
public class FileService : IFileService
{
public void UploadFile(Stream fileContent)
{
convert the stream to a file and save it.
}
}
when I trigger the uploadClick event from iphone, the image data is converted to NSMutableData, but after [r startAsynchronous], nothing happened it restful wcf. I guess maybe the request didn't reach the wcf or the wcf couldn't recognize it. I want to know what's wrong with it or give me another solution. any comments is appreciated.