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)