iphoneから安らかなwcfに写真をアップロードしようとしています。私は何度も試しましたが、失敗しました。ここでは、クライアント写真をiphoneから安らかな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]の後に、何も起こりませんでした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/how-to-upload-image-data-to-server-specific-with-file-name#comment11996956_9479093 – Ravin