Hi Guys,
Ksoap does not implement serialization itself while sending byte array using ksoap call.
When we are using web services in android we need to implement serialization before we send the byte array otherwise we are getting error can not serialize byte array.
private static final String NAMESPACE = ".xsd url taken from the web service URL";
private static final String URL = "web service URL";
private static final String SOAP_ACTION = "Action port typr";
private static final String METHOD_NAME = "Method name";
private static final String URL = "web service URL";
private static final String SOAP_ACTION = "Action port typr";
private static final String METHOD_NAME = "Method name";
the above parameter can be taken from the users web service (?WSDL) url
SoapObject request = new SoapObject(NAMESPACE, AUTH_METHOD);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
new MarshalBase64().register(envelope); //serialization
envelope.encodingStyle = SoapEnvelope.ENC;
request.addProperty("body", str);
request.addProperty("image", imagebyte);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try{
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;
String str=resultsRequestSOAP.toString();
SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;
String str=resultsRequestSOAP.toString();
}catch(Exception e)
{
}
Thanks... very helpful
ReplyDeletehi, we are using your example but is not working for us... we work with Android 2.2, we can send the webservice, but we cant send the byte array. can you help us??
ReplyDeleteI want to send an image to the webserver. I have a method that generates a random number as a webservice . I want to upload the image and the webservice to generate a random number.
ReplyDeleteThe image is captured with a built in camera. I have the code for the built-in camera for the image sending to the server and the method that generates a random number but I can't figure out how to connect these three since I;ve only started developing in android for 3 months.
Can you help me please?
Thanks
Here is the java method for random number
getNumber doesn't have an argument but it should be something like byte[] image where image is from setProperty("image", imagebytes)
Correct me if I'm wrong
package de.vogella.webservice.soap.axis2;
//import java.math.BigInteger;
import java.util.Random;
public class RandomNumber {
public int getNumber(){
Random random = new Random();
return random.nextInt(8);
}
}
Hi i want to send an audio file into web service from android. I am using KSOAP2. I could do send image as byte arrays to the web server.. but i cant send audio as byte arrays to my server.. any ways? how can i do that.. Any help pls?
ReplyDeleteHelpful information indeed.
ReplyDelete