Development Environment eclipse + WTP
How to Use
Eclipse
Of
"Web Service Explorer"
Come
Test
Existing
Web ServiceHttp://www.eclipse.org/webtools/jst/components/ws/1.0/tutorials/WebServiceExplorer/WebServiceExplorer.html
How to Develop
JAX-WS 2.0
Of
Web Service (
Non
Stateless Bean
Version
)Step 1: create a dynamic web project. File-> New-> other...-> Web-> dynamic web project. Step 2: add the jar related to EJB to classpath. In addition, it is best to add jaxb jar (because jaxb annotation is required for some complex data types, such as list) step 3: Create a hellows. java ====================================
PackageWS;
ImportJavax. JWS. webmethod;
ImportJavax. JWS. WebService; @ WebService (name = "helloworld", servicename = "helloworldservice ")
Public
ClassHellows {@ webmethod
PublicString gethello (string name ){
Return"Hello" + name ;}} ================================== Step 4: in eclipse J2EE perspective, double click the "deployment descriptor: XXX" of the dynamic Web project. add the following content in XML
Put the aboveWeb service classSetServlet.=====================================< Servlet> <servlet-Name> hellows </servlet-Name> <servlet-class> ws. hellows </servlet-class> </servlet> <servlet-mapping> <servlet-Name> hellows </servlet-Name> <URL-pattern>/hellows </url-Pattern> </servlet-mapping >================================ step 5: set the preceding WEB Project
Package
War
File: In eclipse J2EE perspective, right click the WEB Project node, select menu "Export à war file ", then, add the war file deploy to your web server (I use JBoss, So copy the war file to "deploy" folder ). Step 6: Check whether your web service is running normally. Start the JBoss server and enter http: // localhost: 8080/jbossws/services to check whether your web service exists. If yes, use the eclipse Web Service explorer mentioned earlier to test it. The above step is to explain the development of JAX-WS 2.0 web service. If you are using eclipse to develop Apache Axis 2 Web Service, see http://www.eclipse.org/webtools/community/tutorials/BottomUpAxis2WebService/bu_tutorial.html
For an existing
Web Service
To create
Java Web service clientStep 1: Create a normal Java project Step 2: generate a web service client through Wizard:
File-> New-> other...-> Web Services-> Web service client
This will automatically generate the following files based on the WSDL you provide:
Step 3 ======================================
ImportWS. helloworld;
ImportWS. helloworldproxy;
Public
ClassTestws {
Public
Static
VoidMain (string ARGs []) {
Try{// Call Web Service Operation
Helloworldproxy service = new helloworldproxy ();
Helloworld Port = service. gethelloworld ();System.
Out. Println (port. gethello ("Tomson "));}
Catch(Exception ex) {ex. printstacktrace ();}}} ================================ Step 4: Run testws. java to test
How
WSDL
File to create
Web Service
(
Top down
Method)Step 1: create a dynamic web project. File-> New-> other...-> Web-> dynamic web project. (
Note: Check the "add project to an ear" option.) Step 2: import the WSDL file to the project root directory Step 3: Right click the WSDL file, select menu "Web Services à generate Java Bean skeleton ", generate a Web Service Based on the wizard. You can also see http://www.eclipse.org/webtools/jst/components/ws/1.5/tutorials/TopDownWebService/TopDownWebService.html
Note: above
Top down
Method
Web Service
Is based on
Apache axis
Of
Web Service
(Not based on
Jax-ws 2.0
So it does not generate
Annotation
Of
Web Service
.Another: http://www.eclipse.org/webtools/community/tutorials/TopDownAxis2WebService/td_tutorial.html teaches you how to use Apache Axis 2 to generate top-down web services (also does not use annotation)
: Create a testws. Java