我正在编写一个必须在 wcf 网络服务上发送图片的 android 应用程序。我的应用程序可以联系网络服务并给它图片。但是,尺寸不同,我无法在网络服务上打开图片。
编辑:通过更改网络服务部分,我得到了完全相同的大小。但是,还是打不开。
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());
}
编辑:网络服务(文件大小 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();
}