1: The writing of a functional class---publishing Service
@WebService
public class Carfactory {
public string car (string num) {
switch (num) {
Case "Lu A1000":
return "BMW";
Case "Lu A1001":
Return "Mercedes";
Case "Lu A1002":
Return "oooo";
Default
SYSTEM.OUT.PRINTLN (num);
Return "Without this car";
}
}
public static void Main (string[] args) {//
Endpoint.publish ("Http://localhost:8080/ws/service",
New Carfactory ());
}
}
Comments:
1: This class has a car method, the role is based on the license plate number to query the corresponding model, then how can the outside world use my method?
Specific practices:
1: Add annotations to @webservice,--to make it available to everyone on the Internet
2: And write a method, the method content is as follows: Endpoint.publish ("Http://localhost:8080/ws/service", New Carfactory ());
Parameter is: 1: Custom Path 2: Object of Class
To run this method, wait for the caller to call
----released, only so that others can use
2: Caller's notation----Invoke service
public class Carclint {
public static void Main (string[] args) {
Carfactoryservice cfs=new carfactoryservice ();
Carfactory CF=cfs.getcarfactoryport ();
String A=cf.car ("lanxing");
System.out.println (a);
}
}
Note: 1: Callers need to know the developer's custom path, run this path on the browser to get another path ending in wsdl --Get the WSDL
2: Run cmd--On dos page input:wsimport http://localhost:8080/ws/service?wsdl----Enter, parse WSDL to get the corresponding class
3: Input: (start)---Get the corresponding folder location, you can see the same name as the project name of the folder, the folder is some class, we call to use
4: Input: (jar CVF lanxing.jar./folder name)-----The third step to get the folder into a clip pack
5: Lead the clip into your project and start writing the test class
1. Create an object of a class that is the end of the service in the package
2. Get the object of the developer's class
3, through the obtained object call has the function method-----obtains the concrete function, the call completes
Note: The entire process does not need to introduce other folders, directly using Java, the JDK is more than 1.6
2:main method up after the program must always be up, write the test method can be measured through
Use Java's own webservice