wcfWebサービスで画像を送信する必要があるAndroidアプリを作成しています。私のアプリはWebサービスに接続して、画像を提供できます。ただし、サイズが異なり、Webサービスで画像を開くことができません。
編集:Webサービスの部分を変更することで、両方でまったく同じサイズになりました。しかし、それでも開くことができません。
Androidパーツ(ファイルサイズ20ko):
File img;
try {
Log.i("image", "get file");
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
Log.i("call", "end build");
MultipartEntity entity = new MultipartEntity();
entity.addPart("data", new FileBody(f));
httppost.setEntity(entity);
Log.i("call", "call");
HttpResponse response = httpclient.execute(httppost);
Log.i("call", "After");
}
catch (Exception e) {
Log.i("error cal image", e.toString());
}
編集:Webサービス(ファイルサイズ20ko):
[OperationContract]
[WebInvoke(Method = "POST",
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "picture")]
public void UploadPicture(Stream image)
{
var ms = new MemoryStream();
image.CopyTo(ms);
var streamBytes = ms.ToArray();
FileStream f = new FileStream("C:\\appicture.jpg", FileMode.OpenOrCreate);
f.Write(streamBytes, 0, streamBytes.Length);
f.Close();
ms.Close();
image.Close();
}