1 Reply Latest reply on Mar 14, 2006 10:41 AM by Bill Burke

    How to consume a web service from a SLSB EJB3?

    Anders Hedstrom Novice

      Hi,

      I'm trying to consume a web service from my SLSB, but I can't get hold of the service reference. Instead of using injection (I can't find the annotation javax.xml.ws.WebServiceRef anywhere, so I guess that it's not implemented yet), I just declare the service ref myself in the dd and try to get it via JNDI - without any luck...

      ejb-jar.xml snippet

      <session>
       <ejb-name>WsClientEJB</ejb-name>
       <env-entry>
       <env-entry-name>testEnv</env-entry-name>
       <env-entry-type>java.lang.String</env-entry-type>
       <env-entry-value>VALUE FROM DD</env-entry-value>
       </env-entry>
       <service-ref>
       <service-ref-name>service/CountrySrv</service-ref-name>
       <service-interface>test.ejb3.ws.CountryInfoService</service-interface>
       <wsdl-file>META-INF/wsdl/country-srv.wsdl</wsdl-file>
       <jaxrpc-mapping-file>META-INF/wsdl/mapping.xml</jaxrpc-mapping-file>
       </service-ref>
      </session>


      SLSB code:

      @Stateless
      public class WsClientEJB implements WsClient {
       private static final Logger log4j = Logger.getLogger(WsClientEJB.class);
      
       public String getCountryCapital(String countryISOCode){
       try {
       InitialContext ic = new InitialContext();
       log4j.info(ic.lookup("java:comp.ejb3/env/testEnv"));
       CountryInfoServiceSoapType ws =
       ((CountryInfoService)ic.lookup("java:comp.ejb3/env/service/CountrySrv")).getCountryInfoServiceSoap();
       return ws.capitalCity(countryISOCode);
       } catch (NamingException e) {
       log4j.error(e.getMessage());
       return e.getMessage();
       } catch (ServiceException e) {
       log4j.error(e.getMessage());
       return e.getMessage();
       } catch (RemoteException e) {
       log4j.error(e.getMessage());
       return e.getMessage();
       }
       }
      }


      The output on the console when calling this method:
      15:36:42,515 INFO [WsClientEJB] Entering getCountryCapital!
      15:36:42,515 INFO [WsClientEJB] VALUE FROM DD
      15:36:42,515 ERROR [WsClientEJB] service not bound


      As you can see I can find the env-entry in the dd via JNDI (it took me some time to figure out the it was bound under comp.ejb3 context), but I can't look up the service-ref . It's not bound?

      This is how I get it when using EJB 2.1. How should I get it in EJB3? Any ideas?

      Cheers
      //Anders