Pass Array using Web services in Ksoap2

后端 未结 1 613
旧时难觅i
旧时难觅i 2021-01-03 09:22

I have to call a web service in which web service is called by kSoap2 method, now in this one node is a Array so how i can pass it.

POST /opera/OperaWS.asmx          


        
相关标签:
1条回答
  • 2021-01-03 10:27

    This can be done by making different SoapObject of corresponding Node, so like in the above problem we have to make two soap objects one for Group, and other for GroupMembers.

    entire code

    public static String sendGroupMessageNotification(ArrayList<String>          
    groupIdList,ArrayList<String> members,String senderId,String messageText,boolean isUrgentFlag)
        {
            SOAP_ACTION = "http://tempuri.org/SendGroupMessageNotification";
            METHOD_NAME = "SendGroupMessageNotification";
    
            Calendar currentDate = Calendar.getInstance();
            SimpleDateFormat formatter= new SimpleDateFormat("yyyy/MMM/dd HH:mm:ss");
            String dateNow = formatter.format(currentDate.getTime());
            SoapObject myObject = new SoapObject(NAMESPACE, METHOD_NAME);
            SoapObject groupSoap=new SoapObject(NAMESPACE,METHOD_NAME);
            SoapObject groupMembers=new SoapObject(NAMESPACE,METHOD_NAME);
    
    
            groupSoap.addProperty("groupid","1");
            groupMembers.addProperty("Id","29");
            groupMembers.addProperty("Id","36");
            groupSoap.addProperty("groupMembers",groupMembers);
    
    
            PropertyInfo receiverMemberid = new PropertyInfo();
            receiverMemberid.setName("reciverMemberId");
            receiverMemberid.setValue(groupSoap);
            receiverMemberid.setType(groupSoap.getClass());
            myObject.addProperty(receiverMemberid);
    
            PropertyInfo memberId=new PropertyInfo();
            memberId.setName("MemberId");
            memberId.setValue(Integer.parseInt(senderId));
            memberId.setType(PropertyInfo.INTEGER_CLASS);
            myObject.addProperty(memberId);
    
            PropertyInfo message=new PropertyInfo();
            message.setName("MESSAGE");
            message.setValue(messageText);
            message.setType(PropertyInfo.STRING_CLASS);
            myObject.addProperty(message);
    
            PropertyInfo createDate=new PropertyInfo();
            createDate.setName("CREATEDDATE");
            createDate.setValue(dateNow);
            createDate.setType(PropertyInfo.STRING_CLASS);
            myObject.addProperty(createDate);
    
            PropertyInfo isUrgent=new PropertyInfo();
            isUrgent.setName("isUrent");
            isUrgent.setValue(isUrgentFlag);
            isUrgent.setType(PropertyInfo.BOOLEAN_CLASS);
            myObject.addProperty(isUrgent);
    
            PropertyInfo predifMessage=new PropertyInfo();
            predifMessage.setName("Predifnemessage");
            predifMessage.setValue("Hello");
            predifMessage.setType(PropertyInfo.STRING_CLASS);
            myObject.addProperty(predifMessage);
    
            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelope.dotNet = true;
            envelope.setOutputSoapObject(myObject);
            HttpTransportSE transport = new HttpTransportSE(URL);
            try
            {
                transport.call(SOAP_ACTION, envelope);
            }
            catch (IOException ex)
            {
                Logger.getLogger(SoapWebServices.class.getName()).log(Level.SEVERE, null, ex);
                return null;
            }
            catch (XmlPullParserException ex)
            {
                Logger.getLogger(SoapWebServices.class.getName()).log(Level.SEVERE, null, ex);
                return null;
            }
            try
            {
                SoapPrimitive result = (SoapPrimitive) envelope.getResponse();
                return result.toString();
            }
            catch (SoapFault ex)
            {
                Logger.getLogger(SoapWebServices.class.getName()).log(Level.SEVERE, null, ex);
                return null;
            }
        } 
    

    Ok if anyone have problem then let me know

    0 讨论(0)
提交回复
热议问题