繁体   English   中英

Android:如何在wsdl请求中将数组作为参数发送

[英]Android : how to send array as parameter in wsdl request

我想将数据从android应用程序发送到php web服务,web服务得到以下参数:

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

我使用kso​​ap2库,在此代码中我传递了sessionId,但我不知道如何将数组设置为wsdl请求的参数

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

我发现此php示例用于通过php代码使用网络服务:

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

我如何用Java做到这一点? 谢谢

步骤1 :在ksoap或ksoap2中,不直接支持发送Array。 因此您可以使用方法名称创建SoapObject(需要创建数组)

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

步骤2 :然后创建arrayType方法(可选,取决于您的WSDL)并将此soapObject作为属性添加到该数组Object

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

步骤3 :最后将数组添加到您的主Soap调用中

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

注意:步骤取决于您的WSDL,有时您可以直接添加第一步对象作为参数,这取决于WSDL。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM