我正在尝试将图像从Android设备上传到WCF服务。如果我发送一个小图像(大约20kb),那么它工作正常。如果我发送稍大的图像(大约95kb),我会收到错误:
org.xmlpull.v1.XmlPullParserException: unexpected type (position:END_DOCUMENT null@1:1 in java.io.InputStreamReader@41636470)
Android代码是:
byte[] fileContents = IOUtil.readFile(image.getFileName());
request = new SoapObject(CommonFunctions.NAMESPACE, "SaveAttachment");
envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
new MarshalBase64().register(envelope);
androidHttpTransport = new HttpTransportSE(CommonFunctions.SERVICE_URL);
request.addProperty("SomeProperty1", somevalue1);
request.addProperty("SomeProperty2", somevalue2);
PropertyInfo p1=new PropertyInfo();
p1.setName("FileContents");
p1.setType(MarshalBase64.BYTE_ARRAY_CLASS);
p1.setValue(fileContents);
request.addProperty(p1);
androidHttpTransport.call(CommonFunctions.SOAP_ACTION + "SaveAttachment", envelope);
int fileId = Integer.parseInt(envelope.getResponse().toString());
几秒钟后,androidHttpTransport.call行会抛出异常。我的WCF服务中的断点永远不会被命中。我已经提高了对WCF绑定的请求限制:
<basicHttpBinding>
<binding name="MobileIntegrationBinding" messageEncoding="Text" allowCookies="true" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647">
<security mode="Transport" />
</binding>
</basicHttpBinding>
KSOAP将为属性添加的数据量是否有限制,如果有,有办法增加这个数据吗?
答案 0 :(得分:0)
答案 1 :(得分:0)
你需要压缩imagen
String imageEncoded;
InputStream is = activity.getContentResolver().openInputStream(uri);
Bitmap img = BitmapFactory.decodeStream(is);
ByteArrayOutputStream convert = new ByteArrayOutputStream();
img.compress(Bitmap.CompressFormat.JPEG, 50, convert);
byte[] b = convert.toByteArray();
imageEncoded = Base64.encodeToString(b, Base64.DEFAULT);
然后使用Base64转换无字节.. 在android上只有转换为字节aprox 50mb不再