How to add Multiple Arguments In SOAP Webservice in java

1k views Asked by At

Sample Webservice Mehtod

     public String getMsg(String arg1,String arg2)
        {
            System.out.println("arg1--->"+arg1);
            System.out.println("arg2--->"+arg2);

            return "response";
        }   

Client Code

              private static SOAPMessage createSOAPRequest() throws Exception 
              {
              System.out.println("createSOAPRequest---->");
              MessageFactory messageFactory = MessageFactory.newInstance();
              SOAPMessage soapMessage = messageFactory.createMessage();
              SOAPPart soapPart = soapMessage.getSOAPPart();
              String serverURI = "http://webservice.jaipal.econnectsolution.com";  
              // SOAP Envelope
              SOAPEnvelope envelope = soapPart.getEnvelope();
              envelope.addNamespaceDeclaration("MineralWebService", serverURI);
              //SOAP Body
              SOAPBody soapBody = envelope.getBody();
              System.out.println("soapBody----->"+soapBody);
              SOAPElement soapBodyElem = soapBody.addChildElement("getMsg", "MineralWebService",serverURI);
              SOAPElement value = soapBodyElem.addChildElement("getMsg","MineralWebService");
              value.setTextContent("Arguments One");
               MimeHeaders headers = soapMessage.getMimeHeaders();
              headers.addHeader("SOAPAction", serverURI  + "add");
              System.out.println("headers----->"+headers.toString());
              soapMessage.saveChanges();
              /* Print the request message */
              System.out.print("Request SOAP Message = ");
              soapMessage.writeTo(System.out);
              System.out.println();
               return soapMessage;
          }

I want To add wwo arguments to call my webservice mehtod. Using above code, I was Able to send only one Argument.

Please help me to achieve this.

1

There are 1 answers

0
kingAm On BEST ANSWER

Have you tried creating/adding new element, like you are doing it for first argument?

SOAPElement soapBodyElem2 = soapBody.addChildElement("getMsg", "MineralWebService",serverURI);
                  SOAPElement value2 = soapBodyElem2.addChildElement("getMsg","MineralWebService");
                  value2.setTextContent("Arguments Two");