我想通过.NET webservice上传用相机拍摄的照片。
Webservice将字节数组(byte [])作为参数。在xsd文件中看起来像这样:
<xs:element name="Upload">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="path" nillable="true" type="xs:base64Binary"/>
<xs:element minOccurs="0" name="imagename" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
上传代码
Bitmap bitmap = BitmapFactory.decodeFile(filePath);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 60, baos);
byte[] imageBytes = baos.toByteArray();
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
new MarshalBase64().register(envelope); // serialization
envelope.encodingStyle = SoapEnvelope.ENC;
request.addProperty("imagename", fileName);
request.addProperty("path", imageBytes);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(
WEBSERVICE_URL);
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
Object resultsRequestSOAP2 = envelope.getResponse();
result = resultsRequestSOAP2.toString();
} catch (Exception e) {
Log.e(TAG, e.getMessage());
e.printStackTrace();
}
我看起来正在上传,但上面的代码会触发异常:
SoapFault - faultcode: 'a:InternalServiceFault' faultstring: 'Buffer cannot be null.
Parameter name: buffer' faultactor: 'null' detail: org.kxml2.kdom.Node@44c50c50
有什么问题?我使用webservice或问题的方式是在webservice?一些建议如何上传字节数组?
感谢所有回复。