Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Ejb Webservice 
 

In this tutorial I will explain you how you can develop an EJB and then expose the EJB as webservice.

 

EJB Webservies

                         

In this tutorial I will explain you how you can develop an EJB and then expose the EJB as webservice. We will also explain how the webservices can be called from a client.

Topics discussed are:

  • Create EJB and deployin on the server
  • Then expose EJB as webservice
  • Develop the webservices client
  • Deploy the client
  • Test the application
Select File--> New Project and then select JavaEE project

EjbWebservice

Give the name of the project as EjbWebService
EjbWebservice

Select the server as Glassfish
In Ejb web Service Only Stateless Bean can be used .So take a Session Bean

EjbWebservice
Now take a Session Bean

EjbWebservice

Here select Stateless Bean and Remote interface

EjbWebservice
It creates session1Bean.java and session1Remote.java

In Remote Interface  give a method named  add() as follows 
package pack1;
import javax.ejb.Remote;

@Remote
public interface session1Remote {
    public int add(int x,int y);
}

Implement the method add in the bean class
Add @Webservice method before class
Add  @Webmethod before the method as given in figure

EjbWebservice
Now deploy the project
After deploying  now test the Web Service
Right Click on the web service Session1Bean .
Select the Test Web Service

EjbWebservice

It will open the file in the browser
There give the two no and click on   add button
Add button is actually the operation present in the SessionBean file

EjbWebservice
It gives the sum with the SOAP Request and SOAP response

EjbWebservice

Creating the client for the EJB Web Service

Client can be created as the the servlet or jsp or simple java file
For this take a web project

EjbWebservice
After making the project Right click on it
Select New Web Service Client
It creates the client environment in this project

EjbWebservice

In the dialog box select the WSDL file for the web service by clicking on the browser button

EjbWebservice
EjbWebservice

Now make a servlet program

EjbWebservice
Give name as Client1

EjbWebservice

Rt. Click  on the servlet code and select Web Service Client operation

EjbWebservice

Here Select the operation name  as in fig

EjbWebservice

This will generate the additional code in the servlet  file
In arg0 and arg1 give the value

public class Client1 extends HttpServlet {
    @WebServiceRef(wsdlLocation = "WEB-INF/wsdl/client/session1Bean/localhost_8080/session1BeanService/session1Bean.wsdl")
    private Session1BeanService service;
 
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
      try {
        pack1.Session1Bean port = service.getSession1BeanPort();
             int arg0 = 10;
             int arg1 = 20;
             int result = port.add(arg0, arg1);
             out.println("Result = "+result);
         }
      catch (Exception ex) {
          System.out.println(ex.getMessage());
                }
        }
}

Now deploy this project
Rt click and select run  file
EjbWebservice

 

Download Code

                         
» View all related tutorials
Related Tags: c gui web ide netbeans ui service help services vi deploy id tool developer oo beans to developers bean e

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.