我正嘗試將iphone上的照片上傳到restful wcf。我嘗試了很多次,但都失敗了。下面是從客戶端礦山將iPhone上的照片上傳到restful wcf
代碼的一些代碼
-(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];}
從寧靜的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.
}
}
當我觸發來自iphone的uploadClick事件,圖像數據轉換爲NSMutableData,但在[r startAsynchronous]之後,沒有任何事情發生它restful wcf。我想也許請求沒有達到wcf或wcf無法識別它。我想知道它有什麼問題或給我另一種解決方案。任何意見表示讚賞。
我不確定wcf。但是,對於上傳圖片或其他數據,我們使用多部分請求模型。 http://stackoverflow.com/questions/9477046/how-to-send-image-data-to-server-i-already-have-a-sample-page/9477819#9477819,http://stackoverflow.com/問題/ 9479093 /如何上傳圖像數據到服務器與特定文件名#comment11996956_9479093 – Ravin 2012-02-29 08:42:20