Web Services client example
Note: This article is taken from Axis User's Guide on Apache's public AXIS server, you send a string to the service, which can return the same string to you. Below we write a Web Services client example Calling this service: 1? Morport org.apache.axis.client.call; 2 ?? Import org.Apache.axis.client.service; 3 ?? import javax.xml.namespace.qname; 4 ?? 5 ?? Public class testclient {6 ????? public static void main (string [] args) {7 ????????????????? String endpoint = 9 ?????????????????????? "http://nagoya.apache.org:5049/AXIS/Services/echo";10??? ?????????? // Create two JAX-RPC objects 11 ???????????? service? Service = new service (); 12 ????????? ??? Call ???? call ??? = (call) service.createcall (); 13? ?????????????? // SOAP message destination 14 ???? ???????? Call.SetTargetendPointDress (new java.net.url (endpoint)); ?????????????? // To call the operand name 15 ????? ??????? Call.SetoperationName (New QNAME ("http://soapinterop.org/", "echostring")); 16? ?????????????? Array form Introduction parameter 17 ??????????? String Ret = (String) Call.Invoke (new object [] {"Hello!"}); 18? 19 ??????? ????? system.out.println ("SENT 'HELLO!', GOT '" RET "'"; 20 ????????} cat CH (Exception E) {21 ???????????? system.err.println (e.tostring ()); 22 ????????} 23 ????} 24? } The above files on the D: / Axis / Axis-1_1 / Sample1 directory of the AXIS.
Join the needs of the package, connect to the network, run the program, you will get the following results: Sent 'Hello!', Got 'Hello!'
Use the TCPMON or SOAP MONITOR tool to view the delivery SOAP message as follows:
http://www.w3.org/2001/xmlschema "
??????????????????? XMLNS: soap-env = "
http://schemas.xmlsoap.org/soap/envelope/ "
???????????????????? xmlns: XSI = "
http://www.w3.org/2001/xmlschema-instance ">
?
???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
http://soapinterop.org/ ">
?????
Hello!
???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
?
This is a file that meets the SOAP specification.