Web Service Development Based on JAX-WS on myeclipse6.5

Source: Internet
Author: User

JAX-WS (Java API for XML-Web Services)

Environment Description:
Myeclpose 6.5 blue milestone-1
JDK 1.6.0 _ 15
Tomcat 6.0

Create and publish server applications

1. Create a Web Service Project.
Set as shown in.


2. Create an implementation class with the following code:

 

Package Net;

Public ClassAddimpl {
Public DoubleAdd (DoubleNum1,DoubleNum2 ){
ReturnNum1+Num2;
}
}

 

Here, you only need to implement the class, and do not need an interface like xfire.


PS: Web services can be implemented by a single Java class, but it is best to use the "interface + Implementation" method.
3. Create a webService
Select a project name and click the new Web Service button in the toolbar.

Then configure as follows:

Next (enter the name of the implementation class in Java Bean and select generate WSDL in project ):

After you click Finish, the package contains an additional proxy class addimpldelegate. Java for this implementation class.

4. Import package
Project-properties-build path-add library-myeclipse libraries import the following two packages:

If the two packages are missing, the following error occurs during Tomcat startup:

 

Severe: Error Handling application listener Class Com. Sun. xml. ws. Transport. http. servlet. wsservletcontextlistener
Java. Lang. classnotfoundexception: COM. Sun. xml. ws. Transport. http. servlet. wsservletcontextlistener

 

5. Start tomcat, verify and obtain the WSDL File

After Tomcat is started, enter http: // localhost: 8080/jaxws_src/addimplport in the browser and click the link on the page to view the WSDL file. If the file is correctly displayed, the server is declared successful.
The URI of the WSDL file isHttp: // localhost: 8080/jaxws_src/addimplport? WSDL (You may ask where the addimplport in Uri comes from. In fact, this name is set by the Service port in Figure 4)

 

PS: The following classes are available in Web. xml. You can see the role of this/addimplport.

Code

  < Servlet >
< Description > The JAX-WS endpoint-addimplservice </ Description >
< Display-name > Addimplservice </ Display-name >
< Servlet-name > Addimplservice </ 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 > Addimplservice </ Servlet-name >
< URL-Pattern > /Addimplport </ URL-Pattern >
</ Servlet-Mapping >

 

 



Create a client call:

(Do not close tomcat, otherwise .....)
1. Create a Java project and create a package (package name Security Requirements). Net.
2. Select the package point new Web Services Client (refer to the second figure in this article)
PS: Do not use xfire. The client is not necessarily a web services client of the same type as the server. It can be a common project and OK !!
3. Specify the file path of the URI or WSDL of the WSDL (see above ).
The program generates some classes in the net package.

PS: The Add. Java in the figure is a JavaBean. You should know how it works !!
4. Create a new test class:

 

Package Com;

ImportNet. addimpldelegate;
ImportNet. addimplservice;

Public   Class Test {
Public   Static   Void Main (string [] ARGs ){
Addimplservice Service = New Addimplservice ();
Addimpldelegate d = Service. getaddimplport ();
Double Result = D. Add ( 15.6 , 12.5 );
System. Out. println (result );
}
}

 

OK! You are done !!

 

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.