JAVA WebService configuration and invocation of server & Client (JDK-based)

Source: Internet
Author: User

Preface: I was engaged in C # development, because the company project is now moving to java&android development, because of the various Java do not understand, encountered is also a lot of difficulties. At present, to do webservice to provide data support, see the online related large tracts of information is also foggy, and finally to solve, now the code and methods published as follows, there is a need for friends to reference, thank you!

---------------------------------------------------

WebService Service Side

 PackageLavasoft;ImportJavax.jws.WebMethod;ImportJavax.jws.WebService;Importjavax.xml.ws.Endpoint; @WebService Public classHIA {@WebMethod PublicString getnewsa () {return"Geted Func GETNEWSA"; }  PublicString Getnewsb () {return"Geted Func GETNEWSB"; } Publicstring Setnewsa (string title, string content) {return"Seted setnewsa title=" +title+ "content=" +content;} @WebMethod Publicstring Setnewsb (String newId) {return"Seted setnewsa newid=" +newId;} Public Static voidMain (string[] args) {//Publish WebService Access addressEndpoint.publish ("Http://127.0.0.1:8081/jws1",NewHIA ()); Endpoint.publish ("Http://127.0.0.1:8082/jws2",NewHIA ()); Endpoint.publish ("Http://192.168.4.191:8083/jws3",NewHIA ()); } } 

WebService Client

1. Use Wsimport to generate WebService related files. Command: Wsimport-d Store directory-keep-verbose http address

Parameter explanation:

-d:directory

-keep Keep the build file

-verbose Output Related information

2, copy the relevant generated files to the scheme.

3. Write the client calling code:

Import Lavasoft. Hia;  Public class starts {publicstaticvoid  main (string[] args) {    //  Instantiate the service Lavasoft. Hiaservice sss=New  Lavasoft. Hiaservice (); // Get Service Map Hia s=sss.gethiaport (); System.out.println (S.SETNEWSB ("Shit"));    }  

---------------------------- done! Preparation: look at the online article has a variety of ways and methods of webservice construction, personal feel based on the JDK is relatively simple, the above for reference only!

JAVA WebService configuration and invocation of server & Client (JDK-based)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.