import javax.xml.soap.*;
import java.util.*;
import java.net.URL;public class Request {
public static void main(String[] args) {
try {
SOAPConnectionFactory soapConnectionFactory =
SOAPConnectionFactory.newInstance();
SOAPConnection connection =
soapConnectionFactory.createConnection();
SOAPFactory soapFactory =
SOAPFactory.newInstance(); MessageFactory factory =
MessageFactory.newInstance();
SOAPMessage message = factory.createMessage(); SOAPHeader header = message.getSOAPHeader();
SOAPBody body = message.getSOAPBody();
header.detachNode(); Name bodyName = soapFactory.createName(
"GetLastTradePrice", "m",
"http://wombats.ztrade.com");
SOAPBodyElement bodyElement =
body.addBodyElement(bodyName); Name name = soapFactory.createName("symbol");
SOAPElement symbol =
bodyElement.addChildElement(name);
symbol.addTextNode("SUNW"); URL endpoint = new URL
("http://wombat.ztrade.com/quotes");
SOAPMessage response =
connection.call(message, endpoint); connection.close(); SOAPBody soapBody = response.getSOAPBody(); Iterator iterator =
soapBody.getChildElements(bodyName);
SOAPBodyElement bodyElement =
(SOAPBodyElement)iterator.next();
String lastPrice = bodyElement.getValue(); System.out.print("The last price for SUNW is ");
System.out.println(lastPrice); } catch (Exception ex) {
ex.printStackTrace();
}
}
}
import java.util.*;
import java.net.URL;public class Request {
public static void main(String[] args) {
try {
SOAPConnectionFactory soapConnectionFactory =
SOAPConnectionFactory.newInstance();
SOAPConnection connection =
soapConnectionFactory.createConnection();
SOAPFactory soapFactory =
SOAPFactory.newInstance(); MessageFactory factory =
MessageFactory.newInstance();
SOAPMessage message = factory.createMessage(); SOAPHeader header = message.getSOAPHeader();
SOAPBody body = message.getSOAPBody();
header.detachNode(); Name bodyName = soapFactory.createName(
"GetLastTradePrice", "m",
"http://wombats.ztrade.com");
SOAPBodyElement bodyElement =
body.addBodyElement(bodyName); Name name = soapFactory.createName("symbol");
SOAPElement symbol =
bodyElement.addChildElement(name);
symbol.addTextNode("SUNW"); URL endpoint = new URL
("http://wombat.ztrade.com/quotes");
SOAPMessage response =
connection.call(message, endpoint); connection.close(); SOAPBody soapBody = response.getSOAPBody(); Iterator iterator =
soapBody.getChildElements(bodyName);
SOAPBodyElement bodyElement =
(SOAPBodyElement)iterator.next();
String lastPrice = bodyElement.getValue(); System.out.print("The last price for SUNW is ");
System.out.println(lastPrice); } catch (Exception ex) {
ex.printStackTrace();
}
}
}
1 message 这个变量是在拼SOAP的包是吧,如果我有一个完整的我可不可以直接把它付值给message
2 soapBody 是得到的返回的SOAP包是吧,我能不解析直接按字符串的方式保存