1. Interface: ( make service annotations )
Package ws.qlq.a; Import Javax.jws.WebService; /** * interface-oriented WebService Publishing method * * /@WebServicePublicinterface Jobservice { public String getjob ();}
2. Implementation class ( also to be rewarded annotation set Service endpoint interface full path )
Packagews.qlq.a;ImportJavax.jws.WebService; @WebService (Endpointinterface= "Ws.qlq.a.jobservice")//set up a service endpoint interface to specify an interface for external services Public classJobserviceimplImplementsJobservice {@Override PublicString getjob () {return"Jee Research Engineer | Android Research Engineer | Database Engineer | front-end Engineer | Test Engineer | operations Engineer "; } Public voidsay () {System.out.println ("Good morning!"); }}
3. The class that publishes the service
Package ws.qlq.a; Import Javax.xml.ws.Endpoint; Public class Test { publicstaticvoid main (string[] args) { jobservice Jobservice=new Jobserviceimpl (); String address= "Http://127.0.0.1:9999/ws/jobservice"; Endpoint.publish (address, jobservice); System.out.println ("WSDL address:" +address+ "?) WSDL ");} }
Results:
WSDL Address: Http://127.0.0.1:9999/ws/jobservice?WSDL
4. The client generates the local agent via Wsimport and packages it into a jar package
C:\USERS\LIQIANG>CD Desktop
C:\users\liqiang\desktop>wsimport Http://127.0.0.1:9999/ws/jobservice?WSDL
C:\users\liqiang\desktop>jar-cvf Test.jar./WS (after packaging the name Test.jar, the packaged folder is the WS folder of the directory)
Added inventory
adding: ws/(input = 0) (output = 0) (0% stored)
adding: ws/qlq/(input = 0) (output = 0) (0% stored)
adding: ws/qlq/a/(input = 0) (output = 0) (0% stored)
adding: ws/qlq/a/getjob.class (input = 411) (output = 277) (32% compressed)
adding: ws/qlq/a/getjobresponse.class (input = 733) (output = 414) (43% compressed)
adding: ws/qlq/a/jobservice.class (input = 772) (output = 430) (44% compressed)
adding: ws/qlq/a/jobserviceimplservice.class (input = 2304) (output = 1036) (compressed
55%)
adding: ws/qlq/a/objectfactory.class (input = 1495) (output = 661) (55% compressed)
adding: ws/qlq/a/package-info.class (input = 230) (output = 184) (20% compressed)
5. Client-side test WebService (add the above-mentioned jar package into the project )
Packagecn;ImportWs.qlq.a.jobservice;ImportWs.qlq.a.jobserviceimplservice; Public classJobservicetest { Public Static voidMain (string[] args) {Jobserviceimplservice Jobserviceimplservice=NewJobserviceimplservice (); Jobservice Jobserviceimplport=Jobserviceimplservice.getjobserviceimplport (); String Job=Jobserviceimplport.getjob (); String [] Jobs=job.split ("\\|"); for(String s:jobs) {System.out.println (s); } }}
Jee Development Engineer
Android Development Engineer
Database Engineer
Front End Engineer
Test Engineer
Maintenance Engineer
Release of WebService with interface