Friday, August 31, 2012

KSOAP2 USING SEND IMAGE TO WEB SERVER IN ANDROID

its ksoap codes to send image and file to web server :



public class SoapuploadActivity extends Activity {
    /** Called when the activity is first created. */
public final String SOAP_ACTION = "http://tempuri.org/Add";

public  final String OPERATION_NAME = "Add";

public  final String WSDL_TARGET_NAMESPACE = "http://tempuri.org/";

public  final String SOAP_ADDRESS = "http://grasshoppernetwork.com/NewFile.asmx";
TextView tv;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
     
        tv=(TextView)findViewById(R.id.textView2);
     
        Bitmap bMap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        bMap .compress(Bitmap.CompressFormat.PNG, 100, baos);
        //bMap is the bitmap object
        byte[] b = baos.toByteArray();
        int i=b.length;
        Log.e("the output is",""+i);
String  IMAGE= Base64.encodeBytes(b);
        Call(IMAGE);
     
    }
 
 

public void Call(byte[] b)
{

SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,OPERATION_NAME);
PropertyInfo pi=new PropertyInfo();

        pi=new PropertyInfo();
        pi.setName("b");
        pi.setValue(b);
        pi.setType(byte[].class);
        request.addProperty(pi);

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

envelope.setOutputSoapObject(request);

HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
Object response=null;
try

{

httpTransport.call(SOAP_ACTION, envelope);

response = envelope.getResponse();



}

catch (Exception exception)

{

response=exception.toString();
Log.e("the error is",""+response);

}

Log.e("the output is",""+response);
tv.setText(response.toString());



}
 
 
}



its download and add library file to project:  link
its download and add base64conversion to project:  base 64


No comments:

Post a Comment