Send image from Android to Soap web Service

70 Views Asked by At

I want to send an image from the Android device to a SOAP web service. Previously, I downloaded the image from the server from the Android device using SOAP web service, but this time I want to send the file to the server, unfortunately I encountered a problem in sending the file to the server. I tried with Base64 and String, unfortunately no data is sent to the server and it gives an error.

Error text When I send pi.setType with type String.class:

414 request-uri too large

Error text when I send pi.setType with type Base64.class:

Server was unable to process request.

//Decode Bitmap  :
String encoded = "";
encoded =ImageUtil.convert(bitmapOut);
// Client Side :

    @Override
    protected String doInBackground(String... params) {
        
        System.out.println("@line AcntCode:" + params[1]);
        System.out.println("@line AttachFile:" + params[2]);

        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME_FunAttachFile);

        PropertyInfo pi;


        pi = new PropertyInfo();
        pi.setName(Param_FunAttachFile_AcntCode);
        pi.setValue( params[1]);
        pi.setType(String.class);
        request.addProperty(pi);


        pi = new PropertyInfo();
        pi.setName(Param_FunAttachFile_AttachFile);
        pi.setValue(params[2]);
        pi.setType(Base64.class);
        request.addProperty(pi);

        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
        envelope.dotNet = true;

        envelope.setOutputSoapObject(request);

        String path = HTTP + _ip + ASMX;

        try {

            HttpTransportSE androidHttpTransport = new HttpTransportSE(path, 10000);

            androidHttpTransport.call(SOAP_ACTION_FunAttachFile, envelope);

            SoapPrimitive response = (SoapPrimitive) envelope.getResponse();

            Strresponse = response.toString();

        } catch (Exception e) {

            e.printStackTrace();
            String stackTrace = Log.getStackTraceString(e);
            System.out.println("@line e.getMessage : " + e.getMessage());
            System.out.println("@line stackTrace : " + stackTrace);

        }
        return null;

Bitmap to base64 conversion class :

public class ImageUtil {
public static Bitmap convert(String base64Str) throws IllegalArgumentException {
    byte[] decodedBytes = Base64.decode(
            base64Str.substring(base64Str.indexOf(",") + 1),
            Base64.DEFAULT
    );

    return BitmapFactory.decodeByteArray(decodedBytes, 0, decodedBytes.length);
}

public static String convert(Bitmap bitmap) {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.PNG, 100, outputStream);

    return Base64.encodeToString(outputStream.toByteArray(), Base64.DEFAULT);
}

}

Server Side :

    <WebMethod(
Description:="write file")>
Public Function FunAttachFile(ByVal AcntCode As String,
                              ByVal AttachFile As String) As Boolean

    Dim log As New WriteToTextFileClass
    log.WriteTxt(" Start Request ...")

    Return True

End Function

Of course, I have tried other ways, unfortunately, it was not solved. If you need more documents, I will send them. I welcome any guidance.

0

There are 0 best solutions below