WebService
Interactions between heterogeneous platforms such as. NET, PHP, Python, Perl
Popular frames: CXF, Axis, Metro
Java provides: JAX-ws
I. Quickly implement a JWS-based WebService project
1, the establishment of the server
1.1 Creating an interface
Package Com.bling.service; Import Javax.jws.WebService; @WebService Public Interface Imyservice { publicint sum (int A,int b); Public int minus (int A,int b);}
1.2 Creating an implementation class
PackageCom.bling.service;ImportJavax.jws.WebService; @WebService (Endpointinterface= "Com.bling.service.IMyService") Public classMyserviceimplImplementsImyservice {@Override Public intSumintAintb) {//TODO auto-generated Method StubSystem.out.println (A + "+" +b+ "=" + (A +)b)); returnA +b; } @Override Public intMinus (intAintb) {//TODO auto-generated Method StubSystem.out.println (A + "+" +b+ "=" + (A-b)); returnA-b; }}
1.3 Open Service
Package Com.bling.service; Import Javax.xml.ws.Endpoint; Public class MyService { publicstaticvoid main (string[] args) { TODO auto-generated method stub String address = "Http://localhost:8888/ws"; New Myserviceimpl ());} }
Can generate a WSDL file in the service address
2. Client Building
PackageCom.bling.service;Importjava.net.MalformedURLException;ImportJava.net.URL;ImportJavax.xml.namespace.QName;ImportJavax.xml.ws.Service; Public classTestClient { Public Static voidMain (string[] args)throwsmalformedurlexception {//TODO auto-generated Method StubURL url =NewURL ("http://localhost:8888/ws?wsdl"); QName sname=NewQName ("http://service.bling.com/", "Myserviceimplservice"); Service Service=service.create (url,sname); Imyservice Ms= Service.getport (Imyservice.class); System.out.println (Ms.sum (10, 20)); System.out.println (Ms.minus (10, 20)); }}
Output:
30
-10
Gitbub Source Address: Https://github.com/WebServcie/service_start