title: How to consume a webservice from an EJB
body: <p>I am currently trying to wrap my mind around Java EE 5. What I'd like to do is create a sample application that</p>
  
  <ul>
  <li>offers a simple stateless EJB (e. g. a simple calulator with an add() method)</li>
  <li>expose this add method as a webservice</li>
  <li>consume this webservice from another EJB</li>
  </ul>
  
  <p>The first two steps are easy and I can deploy and test this bean to Glassfish v2.1 already and test it with a standalone client:</p>
  
  <pre><code>@WebService
  @Stateless
  public class CalculatorWS {
  
      @WebMethod
      public int add(@WebParam(name = "i") int i, @WebParam(name = "j") int j) {
          int k = i + j;
          return k;
      }
  }
  </code></pre>
  
  <p>What I do not get however, is how to consume a webservice like this from a second EJB. While not strictly useful in this example, I will have to write some EJBs soon that will wrap external webservices as to keep my internal clients from having to deal with those external resources.</p>
  
  <p>From what I understand, I should be able to have the container inject me a webservice into a field of my EJB? I did not find an example for this, however. I'd welcome any hints to tutorials covering this - or even better an example right here :-)</p>
  
  <p>For what it's worth, I am using Eclipse 3.5.</p>