How can i add my own xml request to SoapObject?

649 Views Asked by At

I am trying to call my service with ksoap2.In my request I want to add my own xml to request how can i do that?I googled ,i see some example related PropertyInfo but i dont understand clearly.Please help me

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 


> /*PropertyInfo p = new PropertyInfo();
>           p.setName(METHOD_NAME);
>           p.setValue(getLoyaltyMember(URL,METHOD_NAME,"T111","3122100193697","3121002193697"));
>           p.setType(Boolean.class);
>           request.addProperty(p); Iam not sure here*//


            SoapSerializationEnvelope envelope = 
                new SoapSerializationEnvelope(SoapEnvelope.VER11); 

            envelope.setOutputSoapObject(request);
            HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

            try {

                androidHttpTransport.call(SOAP_ACTION, envelope);
                SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;
                String sd = resultsRequestSOAP.toString();
                String test = sd;
            } catch (Exception e) {
                e.printStackTrace();
            }

//My own Request i want to add the soap request

**public String getLoyaltyMember(String URL, String Method,
                String UserSessionId,String MemberPassword,String MemberLogin) {


            SOAPRequestXMLBody=


            "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ns1=\"http://hello.com.tr/services/WSHelloWebClient.DataTypes/1/\">"
                            + "<SOAP-ENV:Body>"
                            +"<ns1:ValidateMemberRequest>" 
                            +"<ns1:UserSessionId>"+UserSessionId+"</ns1:UserSessionId>"
                            +"<ns1:MemberPassword>"+MemberPassword+"</ns1:MemberPassword>"
                            +"<ns1:MemberLogin>"+MemberLogin+"</ns1:MemberLogin>"
                            +"<ns1:ReturnMember>true</ns1:ReturnMember>"
                            +"<ns1:MemberId>?</ns1:MemberId>"
                            +"<ns1:MemberCardNumber>?</ns1:MemberCardNumber>"
                            +"<ns1:MemberEmail>?</ns1:MemberEmail>"
                            +"<ns1:ClubId>?</ns1:ClubId>"
                            +"<ns1:IncludeAdvanceBooking>true</ns1:IncludeAdvanceBooking>"
                            +" </ns1:ValidateMemberRequest>"
                            +" </SOAP-ENV:Body>"
                            +"</SOAP-ENV:Envelope>";


            return SOAPRequestXMLBody;
        }**       

EDİT:

I must add my own xml. Because my other request like this

SOAPRequestXMLBody = "<?xml version=\"1.0\" encoding=\"utf-16\"?>"
                + "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">"
                + "<soap:Body>"
                + "<AddTicketsRequest xmlns=\"http://hello.com.tr/services/WSHelloWebClientWS.ServiceContracts/1\">"
                + "<OptionalClientClass xmlns=\"http://hello.com.tr/services/WSHelloWebClientWS.DataTypes/1/\"/>"
                + "<OptionalClientId xmlns=\"http://hello.com.tr/services/WSHelloWebClientWS.DataTypes/1\" />"
                + "<OptionalClientName http://hello.com.tr/services/WSHelloWebClientWS.DataTypes/1\" />"
                + "<UserSessionId>"
                + UserSessionId
                + "</UserSessionId>"
1

There are 1 best solutions below

2
On

You don't need to use PropertyInfo although it is not wrong, you can call your web service with your data like that:

request.addProperty("UserSessionId", value1);
request.addProperty("MemberPassword", value2);
request.addProperty("MemberLogin", value3);
request.addProperty("ReturnMember", value4);
request.addProperty("MemberId", value5);
......

the value1 here is the value you want to set in UserSessionId and value2 is the value that will be set to MemberPassword in the webservice and so on..

you should also add this line

envelope.dotNet = true;

below

envelope.setOutputSoapObject(request);

if you want to work with .net webservices

I hope it helped