Java Reference
In-Depth Information
<S:Envelop e xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:sayRespons e xmlns:ns2="http://hello.ws.bemach.com/">
<return> Hello, Johnny ! </return>
</ns2:sayResponse>
</S:Body>
</S:Envelope>
*/
private HelloWorldSOAPClient() {}
public static void main(String[] args) {
try {
// 1. Create a SOAP Message
SOAPFactory sf = SOAPFactory. newInstance (); MessageFactory mf
=
MessageFactory. newInstance ();
SOAPMessage
sm
=
mf.createMessage();
SOAPHeader sh = sm.getSOAPHeader(); SOAPBody sb
= sm.getSOAPBody(); sh.detachNode();
// 2. Add necessary elements to header and body.
Name bodyName = sf.createName( "say" , "m" , "http://hello.ws.bemach.com/” ) ;
SOAPBodyEle-
ment be = sb.addBodyElement(bodyName);
Name name = sf.createName( "name" ); SOAPElement arg0
=
be.addChildElement(name);
ar-
g0.addTextNode( "Johnny" );
// 3. Create a SOAP connection
URL
ep
=
new
URL(String. format ( "http://localhost:%s/java-ws/
hello?WSDL" ,args[0]));
SOAPConnectionFactory scf = SOAPConnectionFactory. newInstance (); SOAPConnec-
tion sc = scf.createConnection();
// 4. Send a SOAP message using the connection. SOAPMessage
response = sc.call(sm, ep); sc.close();
Search WWH ::




Custom Search