示例Webservice Mehtod
public String getMsg(String arg1,String arg2)
{
System.out.println("arg1--->"+arg1);
System.out.println("arg2--->"+arg2);
return "response";
}
客户代码
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;
}
我想添加wwo参数来调用我的webservice mehtod。使用上面的代码,我只能发送一个参数。
请帮助我实现这一目标。
答案 0 :(得分:0)
您是否尝试过创建/添加新元素,就像您为第一个参数做的那样?
SOAPElement soapBodyElem2 = soapBody.addChildElement("getMsg", "MineralWebService",serverURI);
SOAPElement value2 = soapBodyElem2.addChildElement("getMsg","MineralWebService");
value2.setTextContent("Arguments Two");