Android 如何 发送图片到webservice中
我的webservice那边的接受代码是
[WebMethod]
public bool PutImage(byte[] ImgIn)
{
System.IO.MemoryStream ms =
new System.IO.MemoryStream(ImgIn);
System.Drawing.Bitmap b =
(System.Drawing.Bitmap)Image.FromStream(ms);
b.Save("C:\\1.png",
System.Drawing.Imaging.ImageFormat.Png);
return true;
}
然后android那边的链接代码是
private static final String NAMESPACE = "http://tempuri.org/";
private static String URL = "http://192.168.0.32:8081";
private static final String METHOD_NAME = "PutImage";
private static String SOAP_ACTION = "http://tempuri.org/PutImage";
in = new FileInputStream("/sdcard/logo.jpg");
buf = new BufferedInputStream(in,1070); //??? 1070 what for
System.out.println("1..........." + buf);
byte[] bMapArray = new byte[buf.available()];
buf.read(bMapArray);
System.out.println("2..........." + buf.read(bMapArray));
Bitmap bMap = BitmapFactory.decodeByteArray(bMapArray,0,bMapArray.length);
iv.setImageBitmap(bMap);
in.close();
SoapObject rpc = new SoapObject(NAMESPACE, METHOD_NAME);
rpc.addProperty("ImgIn",Base64.decode(bMapArray,Base64.DEFAULT));
AndroidHttpTransport ht = new AndroidHttpTransport(URL);
ht.debug = true;
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.bodyOut = rpc;
envelope.dotNet = true;
envelope.setOutputSoapObject(rpc);
//1
ht.call(SOAP_ACTION,envelope);
//2
SoapObject result = (SoapObject) envelope.bodyIn;
String ret = result.getProperty("PutImageResult").toString();
if(ret.equals("true"))
{
Toast.makeText(this, "发送成功", Toast.LENGTH_LONG).show();
}
else
{
}
这个程序的目的是将手机上的图片上传到服务器中,并且保存在服务器上,可是每次运行到//1处就会出现异常,
请问一下,有什么方法 我自已觉得是rpc.addProperty("ImgIn",Base64.decode(bMapArray,Base64.DEFAULT))
这里问题 ,可是却不知道怎么改。我看过在soap1.1中接受的字段类型是 Base64Binary...
....或者有什么其他好的办法 只要实现这个功能就可以。。。
3Q~~~~