0

I want upload photo taken with camera into server via .NET webservice.

Webservice takes byte array (byte[]) as parameter. It looks like this in xsd file:

<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>

Upload code

    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();
    }

I looks like it's uploading but then the code above fires exception:

SoapFault - faultcode: 'a:InternalServiceFault' faultstring: 'Buffer cannot be null.
Parameter name: buffer' faultactor: 'null' detail: org.kxml2.kdom.Node@44c50c50

What can be problem? Way as I use webservice or problem is in webservice? Some suggestions how to upload byte array?

Thanks for all responses.

Martin Vandzura
  • 3,047
  • 1
  • 31
  • 63

0 Answers0