Release of WebService with interface

Source: Internet
Author: User

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

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.