0

I created a EJB project in eclipse id, the project is to retrieve data from a database and write data to the database. I did that database handling part using JPA. Now I want to convert this to a web service. I googled for two days but every guide stuck me some where with lot of questions. Some of the tutorials said just add @webservice, @webmethod annotations to the Stateless bean class, but then eclipse gives error even without deploying. Please someone help me to move forward.

Thank you. Isuru

Alexander Rühl
  • 6,769
  • 9
  • 53
  • 96
Isuru
  • 79
  • 1
  • 3
  • 9
  • But why you using EJB if you need to make it a WS? Because EJB itself a distributed component. Rather than make a simple DAO class to handle the DB operation, make one service to handle the operations and publish that service as Webservice. Eclipse provide plugin to create a WS from any POJO class. It will generate the WSDL as well when you deploy the code. – Parth Jul 27 '11 at 06:50
  • @Paarth it's quite legitimate to expose a WS interface from an Stateless Session Bean. I agree it's not the only way, but what Isuru is trying should be possible. – djna Jul 27 '11 at 07:15

3 Answers3

0

It is indeed enough to just add the annotation:

@Stateless
@WebServicepublic 
class MySessionBean {  
  public void doSomething() { … }
}

By default, all public methods are exposed to the web service. If you want to limit it, you have to add @Webmethod to all methods which should be exposed.

Besides that, you should tell us which errors you get.

Alexander Rühl
  • 6,769
  • 9
  • 53
  • 96
0

For me Eclipse does not complain about this:

package ord.djna.ejb;
import javax.ejb.Local;
import javax.jws.WebService;

@Local
@WebService
public interface TheFacadeLocal {

    int countItems();

}

Please show us your code.

djna
  • 54,992
  • 14
  • 74
  • 117
0

Try to download Eclipse for Java EE and create new project just with a stateless session bean. See if the annotations work, I guess its a problem with your 'java build path' settings in eclipse.

Kris
  • 5,714
  • 2
  • 27
  • 47