问题描述
我试图用,我试过,我得到一个错误说无法序列这是我在做什么Ksoap2但是一切从Android电子发送.JPEG图片:
I'm trying to send an .jpeg image from Android using Ksoap2 however everything that I've tried I get a error saying "Cannot Serialize" Here's what I'm doing:
ByteArrayOutputStream out = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.JPEG, 100, out);
byte[] raw = out.toByteArray();
String encodedImage = Base64.encodeToString(raw, Base64.DEFAULT);
SoapObject request = new SoapObject("http://tempuri.org/", "sendImage");
request.addProperty("image", out);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
envelope.dotNet = true;
try {
Toast.makeText(getApplicationContext(), "Sending Pic", Toast.LENGTH_LONG).show();
HttpTransportSE androidHttpTransport = new HttpTransportSE("http://www.letstrend.com/spursService.asmx?WSDL");
androidHttpTransport.call("http://tempuri.org/sendImage", envelope);
SoapObject result = (SoapObject)envelope.bodyIn;
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(), "in catch e=" + e.getMessage(), Toast.LENGTH_LONG).show();
}
我试着发出,原材料和连接codeDIMAGE和所有回来的一些错误。该出实际上是什么,我相信它应该看起来像什么,我想我的.NET Web服务上期望。 WebService的期待:
I've tried sending out, raw and encodedImage and all come back as some error. The out is actually what I believe it should look like and what I think my .Net webservice is expecting. The webservice is expecting:
<myImage>base64Binary</myImage>
任何想法?谢谢你。
Any ideas? Thanks.
推荐答案
没关系我得到了它。这是code我用:
Never mind I got it. This is the code I used:
byte[] bytearray = null;
try
{
is = new FileInputStream(_path);
if(_path != null)
try{
bytearray = streamToBytes(is);
}finally{
is.close();
}
}catch (Exception e)
{}
SoapObject request = new SoapObject("http://tempuri.org/", "sendImage");
request.addProperty("myImage", bytearray);
SoapSerializationEnvelope envelope=new SoapSerializationEnvelope(SoapEnvelope.VER11);
new MarshalBase64().register(envelope);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
try {
Toast.makeText(getApplicationContext(), "Sending Pic", Toast.LENGTH_LONG).show();
Toast.makeText(getApplicationContext(), "array length=" + bytearray.length, Toast.LENGTH_LONG).show();
HttpTransportSE androidHttpTransport = new HttpTransportSE("http://www.letstrend.com/spursService.asmx?WSDL");
androidHttpTransport.call("http://tempuri.org/sendImage", envelope);
SoapObject result = (SoapObject)envelope.bodyIn;
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(), "in catch e=" + e.getMessage(), Toast.LENGTH_LONG).show();
Toast.makeText(getApplicationContext(), "fault=" + ((SoapFault) envelope.bodyIn).faultstring, Toast.LENGTH_LONG).show();
}
然后,我有一个叫做程序:
Then I had a procedure called:
public static byte[] streamToBytes(InputStream is) {
ByteArrayOutputStream os = new ByteArrayOutputStream(1024);
byte[] buffer = new byte[1024];
int len;
try {
while ((len = is.read(buffer)) >= 0) {
os.write(buffer, 0, len);
}
} catch (java.io.IOException e) {
}
return os.toByteArray();
}
code来自:<一href=\"http://lakshman39.word$p$pss.com/2012/09/08/sending-byte-to-a-webservice-using-ksoap2-in-android/\" rel=\"nofollow\">http://lakshman39.word$p$pss.com/2012/09/08/sending-byte-to-a-webservice-using-ksoap2-in-android/
在Web服务器把它放回图像做到这一点:
On the web server to turn it back into an image do this:
Dim FilePath As String = Server.MapPath("~/folder/")
System.IO.File.WriteAllBytes(FilePath & "filename.jpg", myImage)
这篇关于使用Android的ksoap2发送图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!