First, the demand
- The previous section, although binding WebService and Web projects together, does not share a single port, this chapter explains WebService and Web project bindings and common ports.
Ii. Case 2.1 Create a Web project and introduce a dependency
2.2 Authoring The Service interface
Package Service; Import Javax.jws.WebParam; Import Javax.jws.WebResult; Import Javax.jws.WebService; @WebService (targetnamespace= "http://www/shyroke.com/") Public Interface Ifirst { = "Addresult") publicintint int y);}
2.3 Writing the service interface proxy class
Package Service; Import Javax.jws.WebService; @WebService (endpointinterface= "service. Ifirst ")publicclassimplements ifirst{ public int Add (intint y) { return x+y; } }
2.4 Build and write Sun-jaxws.xml in the Web-inf directory
<?XML version = "1.0"?><Endpointsversion= "2.0"xmlns= "Http://java.sun.com/xml/ns/jax-ws/ri/runtime"> <Endpointname= "First"Implementation= "service. Firstdelegate "Url-pattern= "/firstport"> </Endpoint></Endpoints>
- Where Url-pattern Browse the address of the Webserice service for the browser,implementation is the proxy class for the service interface
2.5 Configuring Web. Xml
<!DOCTYPE Web-app Public "-//sun Microsystems, INC.//DTD Web Application 2.3//en" "http://java.sun.com/dtd/web-app_2 _3.dtd "><Web-app> <Listener> <Listener-class>Com.sun.xml.ws.transport.http.servlet.WSServletContextListener</Listener-class> </Listener> <servlet> <Servlet-name>Public</Servlet-name> <Servlet-class>Com.sun.xml.ws.transport.http.servlet.WSServlet</Servlet-class> <Load-on-startup>1</Load-on-startup> </servlet> <servlet-mapping> <Servlet-name>Public</Servlet-name> <Url-pattern>/firstport</Url-pattern> </servlet-mapping></Web-app>
2.6 Results
2.7 Finally build the client again
(12) Web services combined with Javaweb (3)