Web Method With Return Type And Parameters : Web Services « EJB3 « Java

Web Method With Return Type And Parameters

File: EmployeeBean.java

import javax.ejb.Stateless;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;

@WebService(serviceName = "EmployeeBeanService", targetNamespace = "urn:EmployeeBean")
@SOAPBinding(style = SOAPBinding.Style.DOCUMENT)
public class EmployeeBean implements EmployeeServiceLocal, EmployeeServiceRemote {

  public EmployeeBean() {

  @WebResult(name = "bidNumber")
  public Long addBid(@WebParam(name = "User")String userId, 
      @WebParam(name = "Item")Long itemId, 
      @WebParam(name = "Price")Double bidPrice) {
    System.out.println("Bid for " + itemId + " received with price" + bidPrice);
    return 0L;

File: EmployeeServiceLocal.java

import javax.ejb.Local;
import javax.jws.WebParam;

public interface EmployeeServiceLocal {
  public Long addBid(String userId,Long itemId,Double bidPrice);


File: EmployeeServiceRemote.java

import javax.ejb.Remote;

public interface EmployeeServiceRemote {
  public Long addBid(String userId,Long itemId,Double bidPrice);

File: jndi.properties


File: Employee.java

import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.PostRemove;


public class Employee implements java.io.Serializable {
  private int id;

  private String firstName;

  private String lastName;

  public int getId() {
    return id;

  public void postRemove()

  public void setId(int id) {
    this.id = id;

  public String getFirstName() {
    return firstName;

  public void setFirstName(String first) {
    this.firstName = first;

  public String getLastName() {
    return lastName;

  public void setLastName(String last) {
    this.lastName = last;

File: Main.java

import javax.ejb.EJB;
import javax.naming.InitialContext;

public class Main {

  public static void main(String[] a) throws Exception {

    EmployeeServiceRemote service = null;

    // Context compEnv = (Context) new InitialContext().lookup("java:comp/env");

    // service = (HelloService)new
    // InitialContext().lookup("java:comp/env/ejb/HelloService");
    service = (EmployeeServiceRemote) new InitialContext().lookup("EmployeeBean/remote");





EJB-WebMethodWithReturnTypeAndParameters.zip( 4,489 k)

Related examples in the same category

1.EJB With Web Method
2.Turn Ejb To Web Service
3.EJB Tutorial from JBoss: turn EJB to web service
4.EJB Based Web Services