gpt4 book ai didi

java - 安卓 : how to send array as parameter in wsdl request

转载 作者:行者123 更新时间:2023-12-02 05:54:39 24 4
gpt4 key购买 nike

我想将数据从 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 示例,用于将 Web 服务与 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中没有直接支持发送数组。所以你可以创建一个带有方法名称的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 作为属性添加到该数组对象

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。

关于java - 安卓 : how to send array as parameter in wsdl request,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23214264/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com