mahdi
mahdi

Reputation: 16407

Android : how to send array as parameter in wsdl request

i want to send data from android application to php web service , web service get this arguments :

Type       Name            Description
string     sessionId       Session ID
array      customerData    Array of customerCustomerEntityToCreate 

i use ksoap2 library , in this code i pass sessionId but i don`t know how to set array as parameter to wsdl request

                env = new SoapSerializationEnvelope(SoapEnvelope.VER11);
                env.dotNet = false;
                env.xsd = SoapSerializationEnvelope.XSD;
                env.enc = SoapSerializationEnvelope.ENC;

                SoapObject request = new SoapObject(NAMESPACE,
                        "createCustomer");
                request.addProperty("sessionId", "1234567890");

                env.setOutputSoapObject(request);
                androidHttpTransport = new HttpTransportSE(URL);
                androidHttpTransport.debug = true;

                // (new MarshalHashtable()).register(env);
                androidHttpTransport.call("", env);
                result = env.getResponse();

                Log.d("result", result.toString());

i found this php example for use web service with php code :

$client = new SoapClient('http://magentohost/api/v2_soap/?wsdl');
$session = $client->login('apiUser', 'apiKey');
$result = $client->customerCustomerCreate($session, array('email' => 'customer-  [email protected]', 'firstname' => 'Dough', 'lastname' => 'Deeks', 'password' => 'password', 'website_id' => 1, 'store_id' => 1, 'group_id' => 1));
var_dump ($result);

how can i do this with java ? thanks

Upvotes: 0

Views: 1946

Answers (2)

Zoo Zoo
Zoo Zoo

Reputation: 121

Step 1 : In ksoap or ksoap2 no direct support to send Array. so you can create a SoapObject with method name(which you need to create array)

SoapObject object= new SoapObject(NAMESPACE,"shoppingCartProductEntity");
object.addProperty("product_id","886");
object.addProperty("sku","ABC 456-Black-10");
         and more parameters.....

Step 2 : then create arrayType method(optional depends on your WSDL) and add this soapObject to that array Object as a property

SoapObject EntityArray = new SoapObject(NAMESPACE, "shoppingCartProductEntityArray");
EntityArray.addProperty("products",object);

Step 3 : finally add the array to your main soap call

SoapObject request = new SoapObject(NAMESPACE,"shoppingCartProductAdd");
request.addProperty("sessionId", sessionId);
request.addProperty("quoteId", cartId);
request.addProperty("products",EntityArray); //ADDING ARRAY HERE AS A PEOPERTY
env.setOutputSoapObject(request);
androidHttpTransport.call(NAMESPACE +"/shoppingCartProductAdd ", env);
resultSoap = env.getResponse();

NOTE : the steps varies depends on the your WSDL, sometimes you can directly add 1st step object as a parameter, this depends on WSDL.

Upvotes: 2

SoapObject request = new SoapObject(NAMESPACE,"login");

request.addProperty("username", "*****");
request.addProperty("apiKey", "********");
env.setOutputSoapObject(request);

HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call(" ", env);
Object result = env.getResponse();

Log.d("This is the New SessionId", result.toString());

String f_name=fname.getText().toString();
String l_name=lname.getText().toString();
String e_mail=email.getText().toString();
String c_pass=cpass.getText().toString();
//calling the soap api method "customerCustomerCreate"
SoapObject res=new SoapObject(NAMESPACE, METHODNAME);
res.addProperty("email",e_mail);
res.addProperty("firstname",f_name);
res.addProperty("lastname",l_name);
res.addProperty("password",c_pass);
res.addProperty("website_id", 1);
res.addProperty("store_id",1);
res.addProperty("Group_id",1);

String sessionId = result.toString();
request = new SoapObject(NAMESPACE, METHODNAME);
//adding the propery such as sessionId and Customerdata for request
request.addProperty("sessionId",sessionId );
request.addProperty("customerData",res);
env.setOutputSoapObject(request);
androidHttpTransport.debug=true;
androidHttpTransport.call("", env);
//getting the response which is the customerId
result=env.getResponse();

Log.d("Customer Id", result.toString());

Upvotes: 0

Related Questions