WebService Super Simple Getting Started Tutorial (Java)

 

In front of the words:  
    When two people meet, they have a good impression. If you need to get information from both parties, then the communication between the two parties is essential! The same is true for apps,  
    The communication between various applications requires WebService as a bridge for mutual communication!  
  
Project purpose:  
    Program A calls method C in program B...  
  
  
First of all, it is stated that the JDK version that needs to be used this time is jdk1.6+, that is, java6+ is required to see the effect, but java5 has not been tried... I think it is better to upgrade the JDK version than to install it.  
In terms of Axis and importing a bunch of jar packages and configuring N multiple configuration files, the webservice of java6 is undoubtedly simple and can't be simpler!  
  
Less nonsense, less whole point, open whole:  
1. Create a project called Trans, web project, or ordinary java project! Here we will use a simple java application as a demonstration!  
    1.1 Create a method belonging to the com.shu.function.Function class:  
  
//Don't forget to import webservice  
@WebService  
public class Function{  
  
    //This method is the method to be exposed to other applications to call  
    public String transWords(String words){  
        String res="";  
        for(char ch : words.toCharArray()){  
            res+="\t"+ch+"\t";  
        }  
        return res;  
    }  
  
    //Here we use the main method to publish our service  
    public static void main(String[] args){  
        Endpoint.publish("http://localhost:9001/Service/Function",new Function());  
        System.out.println("Publish Success~");  
    }  
}  
  
2. After typing "Publish Success~", it means that our message has been published successfully. If it fails, please note: 1. JDK1.6+ is required, 2. Make sure the server port is not occupied; after success,  
Enter in the browser address bar: http://localhost:9001/Service/Function?wsdl to see the details of the service!  
  
3. Create another project: GiveMeWords  
  
The key is here, open cmd and enter the following command: wsimport -s path of src -p full package name -keep the release address of webservice and then press Enter and it's OK,  
比如说: wsimport -s F:\\WorkBench\\Eclipse\\GiveMeWords\\src  -p com.shu.service -keep http://localhost:9001/Service/Function wsdl  
(If the wsimport command fails, please check whether jdk is assigned to the environment variable! JAVA_HOME: the location of the JDK, CLASSPATH: %JAVA_HOME%\lib\tools.jar)  
  • Finally...how about it, webservice is not difficult, it all depends on the upgrade of jdk!
After the carriage return, it will appear:  
    parsing WSDL...  
    generating code...  
    compiling code...  
Congratulations, you are successful, you can refresh your GiveMeWords project and there will be files generated by the corresponding WebService under the com.shu.service package!  
Then call as follows:  
public static void main(String[] args){  
    Function fu =new FunctionService().getFunctionPort();  
    String str=fu.transWords("Let's Get Heck Out Of Here!");  
    //The last str is the string processed by the transWords method under the Trans project!  
}  
  

 

https://zhidao.baidu.com/question/23658531.html

WebServive Free Video Tutorial http://edu.51cto.com/course/course_id-1373.html

 

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326460053&siteId=291194637