Skip to main content

How to expose an EJB as a web service that is not transactional?

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
No replies
nbhatia
Offline
Joined: 2003-06-15

I have an EJB (coded using Java EE 6 annotations) that is defined as follows:

@Stateless
@WebService
public class SecurityWebService {
    public void registerUser(RegistrationRequest request) {
        ...
    }
}

Note that this EJB is also exposed as a web service. However, I am running into an issue with the generated web service. The WSDL generated by GlassFish contains WS-Atomic Transaction policies because a stateless session bean by default is transactional (see details here). Unfortunately my .NET client is choking on the WSDL because it does not understand WS-AT policies.
So what I really want is a nice-clean web service that is not transactional, but the associated EJB should be transactional (it has to insert records in the database). How do I do this? The only approach I can think of is to create a "normal" web service that passes all its calls to an EJB like this - not elegant at all:
@WebService
public class SecurityWebService {

    @Inject
    private SecurityService securityService;

    public void registerUser(RegistrationRequest request) {
        securityService.registerUser(request);
    }
}

@Stateless
public class SecurityService {

    public void registerUser(RegistrationRequest request) {
        ...
    }
}

Is there a better way?
Thanks.
Naresh