0

我想通过 .NET 网络服务将用相机拍摄的照片上传到服务器。

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

有什么问题?我使用网络服务的方式或问题出在网络服务中?一些建议如何上传字节数组?

感谢所有回复。

4

0 回答 0