|
Get it:
The con.call (msg, myEndpoint); method returns a SOAPMessage from the server, as long as you give it a SOAPMessage variable.
The code is written like this: msg = con.call (msg, myEndpoint);
The entire code is as follows:
Client:
import javax.xml.soap. *;
import javax.xml.messaging. *;
public class CustomSoap {
public static void myCustomSoap () {
try {
URLEndpoint myEndpoint = new URLEndpoint ("http://127.0.0.1:8080/axis/HelloService.jws?wsdl");
SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance ();
SOAPConnection con = scf.createConnection ();
MessageFactory mf = MessageFactory.newInstance ();
SOAPMessage msg = mf.createMessage ();
SOAPPart sp = msg.getSOAPPart ();
SOAPEnvelope envelope = sp.getEnvelope ();
SOAPBody bdy = envelope.getBody ();
SOAPBodyElement gltp = bdy.addBodyElement (envelope.createName (
"sayHello", "soapenv",
"http://schemas.xmlsoap.org/soap/encoding/"));
gltp.addChildElement ("zzm"). addTextNode ("The Frist MySoap");
con.call (msg, myEndpoint);
System.out.println ("Soap message transmitted:");
msg.writeTo (System.out);
System.out.println ("");
System.out.println ("Soap message in response to the server:");
msg = con.call (msg, myEndpoint);
msg.writeTo (System.out);
}
catch (Exception e) {
System.out.println (e.toString ());}
}
public static void main (String [] args) {
myCustomSoap ();
}
}
The information printed on the control panel is as follows:
Soap message transmitted:
<? xml version = "1.0" encoding = "UTF-8"?>
<soapenv: Envelope xmlns: soapenv = "http://schemas.xmlsoap.org/soap/envelope/" xmlns: xsd = "http://www.w3.org/2001/XMLSchema"
xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance">
<soapenv: Body>
<soapenv: sayHello xmlns: soapenv = "http://schemas.xmlsoap.org/soap/encoding/">
<soapenv: zzm> The Frist MySoap </ soapenv: zzm>
</ soapenv: sayHello>
</ soapenv: Body>
</ soapenv: Envelope>
Respond to the server's Soap message:
<? xml version = "1.0" encoding = "utf-8"?>
<soapenv: Envelope xmlns: soapenv = "http://schemas.xmlsoap.org/soap/envelope/" xmlns: xsd = "http://www.w3.org/2001/XMLSchema"
xmlns: xsi = "http://www.w3.org/2001/XMLSchemainstance">
<soapenv: Body>
<soapenc: sayHelloResponse soapenv: encodingStyle = "http://schemas.xmlsoap.org/soap/encoding/" xmlns: soapenc = "http://schemas.xmlsoap.org/soap/encoding/">
<sayHelloReturn xsi: type = "xsd: string"> Hello: The Frist MySoap </ sayHelloReturn>
</ soapenc: sayHelloResponse>
</ soapenv: Body>
</ soapenv: Envelope>
Services on the server:
public class HelloService
{
public String sayHello (String username)
{
return "Hello:" + username;
}
} |
|