dongqianzong4275 2014-04-22 08:24
浏览 153

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

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-  mail@example.org', '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

  • 写回答

2条回答 默认 最新

  • dqba94394 2014-06-11 07:32
    关注
    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());
    
    评论

报告相同问题?

悬赏问题

  • ¥15 cgictest.cgi文件无法访问
  • ¥20 删除和修改功能无法调用
  • ¥15 kafka topic 所有分副本数修改
  • ¥15 小程序中fit格式等运动数据文件怎样实现可视化?(包含心率信息))
  • ¥15 如何利用mmdetection3d中的get_flops.py文件计算fcos3d方法的flops?
  • ¥40 串口调试助手打开串口后,keil5的代码就停止了
  • ¥15 电脑最近经常蓝屏,求大家看看哪的问题
  • ¥60 高价有偿求java辅导。工程量较大,价格你定,联系确定辅导后将采纳你的答案。希望能给出完整详细代码,并能解释回答我关于代码的疑问疑问,代码要求如下,联系我会发文档
  • ¥50 C++五子棋AI程序编写
  • ¥30 求安卓设备利用一个typeC接口,同时实现向pc一边投屏一边上传数据的解决方案。