1. Create a proxy interface file
Public interface isendsms extends java. RMI. Remote {
Public String getuser (string ID, string type );
}
Go to the directory .. \ webroot \ WEB-INF \ Classes:
2. Generate the client stub file and generate the sendsms. WSDL file.
Java-djava. ext. dirs = .. /lib Org. apache. axis. WSDL. java2wsdl-osendsms. WSDL-lhttp: /localhost: 8080/websms/services/sendsms-n "urn: sendsms"-P "sample. webService "" urn: sendsms "sample. webService. isendsms
In the generated sendsms. WSDL file, the parameter name defaults to in1, in2, and so on. You need to change it to the corresponding name.
3. Generate client stub
Java-djava. ext. dirs = .. /lib Org. apache. axis. WSDL. wsdl2java-o. -d session-s true-nurn: sendsms sample. webService sendsms. WSDL
The list of generated files is as follows:
Deploy. WSDD
Undeploy. WSDD
Isendsms. Java
Isendsmsservice. Java
Isendsmsservicelocator. Java
Sendsmssoapbindingimpl. Java
Sendsmssoapbindingskeleton. Java
Sendsmssoapbindingstub. Java
4. Deploy services to generate WEB-INF files under the server-config.wsdd directory and automatically load the services defined in them as Tomcat starts
Go to the directory .. \ webroot \ WEB-INF \ Classes \ sample \ WebService
Java-CP % axisclasspath % org. Apache. axis. Client. adminclient-lhttp: // localhost: 8080/websms/services/adminservice deploy. WSDD
Write deploy in axis. WSDD and use Org. apache. axis. client. adminclient release, its main job is to add the content in the <service> label in the server-config.wsdd, so it is more convenient to directly edit the server-config.wsdd file. But when you don't have a server-config.wsdd file, use deploy. the WSDD method is more convenient, because adminclient will help you generate some additional XML elements (
5. Add the required package for axis to the project, and add related definitions to Web. xml.
<Display-Name> APACHE-axis </display-Name>
<Servlet>
<Display-Name> APACHE-axis servlet </display-Name>
<Servlet-Name> axisservlet </servlet-Name>
<Servlet-class>
Org. Apache. axis. Transport. http. axisservlet
</Servlet-class>
</Servlet>
<Servlet>
<Display-Name> AXIS admin servlet </display-Name>
<Servlet-Name> adminservlet </servlet-Name>
<Servlet-class>
Org. Apache. axis. Transport. http. adminservlet
</Servlet-class>
<Load-on-startup> 100 </load-on-startup>
</Servlet>
<Servlet-mapping>
<Servlet-Name> axisservlet </servlet-Name>
<URL-pattern>/services/* </url-pattern>
</Servlet-mapping>
Http: // localhost: 8080/websms/services/sendsms? To view the WSDL description.
6. Test code
Public static void main (string [] ARGs ){
Try {
/* Isendsmsservice service = new isendsmsservicelocator ();
Isendsms sender = service. getsendsms ();
String result = sender. Send ("CID", "cname ");
System. Out. println ("Call Result:" + result );*/
String tvserviceurl = "http: // localhost: 8080/websms/services/sendsms"; // web service address
Java.net. url endpointurl = new java.net. URL (tvserviceurl );
String result = "OK ";
Result = new sendsmssoapbindingstub (endpointurl, null). Send ("ID", "cname ");
System. Out. println ("Call Result:" + result );
}
Catch (exception ex ){
Ex. printstacktrace ();
}
}
You can also use IE to directly call the service by adding "method = xxx" after the service URL, where XXX is the name of the method to be called. For example, you can use http: // localhost: 8080/websms/services/sendsms? Method = Send & userid = uid &... call the method.
========================================================== ========================================================== ====
In addition, you may have created a new deploy. WSDD file to deploy our services directly.
Java-djava. Ext. dirs = lib org. Apache. axis. Client. adminclient-lhttp: // localhost: 8080/websms/services/sendsms deploy. WSDD
// It generates a WEB-INF file in the server-config.wsdd directory, and if this file already exists, it adds the registration of the current service to the file.
Generate a WSDL File
Java-djava. ext. dirs = .. /lib Org. apache. axis. WSDL. java2wsdl-osendsms. the WSDL-lhttp: // localhost: 8080/websms/services/sendsms-nsendsms sample. webService. sendsms
Generate client files
Java-djava. Ext. dirs = ../lib org. Apache. axis. WSDL. wsdl2java sendsms. WSDL-P Client