}
Direct axis calls Remote Web service
I think this method is more suitable for the master, they can directly read the XML format WSDL file, I do not understand, especially I do not specialize in this line, even if a period of time to understand, and then forget. The direct call mode is as follows:
Import Java.util.date;
Import Java.text.dateformat;
Import Org.apache.axis.client.call;
Import Org.apache.axis.client.service;
Import Javax.xml.namespace.qname;
Import Java.lang.integer;
Import Javax.xml.rpc.parametermode;
public class Caclient {
public static void Main (string[] args) {
try {
String endpoint = "HTTP://LOCALHOST:8080/CA3/SERVICES/CASYNROCHNIZED?WSDL";
Direct reference to remote WSDL file
Here are the routines.
Service service = new service ();
Call call = (call) Service.createcall ();
Call.settargetendpointaddress (endpoint);
Call.setoperationname ("AddUser"); Interface name described inside//WSDL
Call.addparameter ("username", Org.apache.axis.encoding.xmltype.xsd_date,
javax.xml.rpc.parametermode.in);//Interface parameters
Call.setreturntype (org.apache.axis.encoding.xmltype.xsd_string);//Set return type
The string temp = "Tester";
String result = (string) call.invoke (new object[]{temp});
Pass parameters to the method and call the method
System.out.println ("result is" +result);
}
catch (Exception e) {
System.err.println (E.tostring ());
}
}
}
2, direct SOAP calls remote WebService
I've never seen or tried this pattern, but someone posted it on the internet, and I turned around.
Import org.apache.soap.util.xml.*;
Import org.apache.soap.*;
Import org.apache.soap.rpc.*;
Import java.io.*;
Import java.net.*;
Import Java.util.vector;
public class caservice{
public static string GetService (string user) {
URL url = null;
try {
Url=new URL ("http://192.168.0.100:8080/ca3/services/casynrochnized");
catch (Malformedurlexception Mue) {
return Mue.getmessage ();
}
This is the main soap object
Call Soapcall = new Call ();
Use SOAP encoding
Soapcall.setencodingstyleuri (CONSTANTS.NS_URI_SOAP_ENC);
This is the remote object we ' re asking for the
Soapcall.settargetobjecturi ("urn:xmethods-casynrochnized");
This is the "method" on the above object
Soapcall.setmethodname ("GetUser");
We need to send the ISBN number as a input parameter to the method
Vector soapparams = new vector ();
Name, type, value, encoding style
Parameter Isbnparam = new parameter ("username", string.class, user, NULL);
Soapparams.addelement (Isbnparam);
Soapcall.setparams (Soapparams);
try {
Invoke the remote method on the object
Response Soapresponse = Soapcall.invoke (URL, "");
Check to the If there is a error, return "N/a"
if (Soapresponse.generatedfault ()) {
Fault fault = Soapresponse.getfault ();
string f = fault.getfaultstring ();
return F;
} else {
Read result
Parameter Soapresult = Soapresponse.getreturnvalue ();
Get a string from the
Return Soapresult.getvalue (). ToString ();
}
catch (SoapException se) {
return Se.getmessage ();
}
}
}
3, use Wsdl2java to turn the WSDL file into a local class, and then use it like a local class.