|
Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide
10g Release 3 (10.1.3) B14428-01 |
|
![]() Previous |
![]() Next |
From within a stateless session bean, you can obtain a web service and invoke its methods.
You must use the initial context (see "Using Initial Context") and you must create an environment reference for the web service (see "Configuring an Environment Reference to a Web Service") before you can look it up.
After you define an environment reference to a web service (see "Configuring an Environment Reference to a Web Service"), you can use the initial context to look up the web service and invoke its methods from within your stateless session bean as Example 30-1 shows.
Example 30-1 Calling Out to a Web Service Obtained from the Initial Context
@Stateless public class InvestmentBean implements Investment
{
public void checkPortfolio(...)
{
...
// Obtain the default initial JNDI context.
Context initCtx = new InitialContext();
// Look up the stock quote service in the environment.
com.example.StockQuoteService sqs = (com.example.StockQuoteService)initCtx.lookup(
"java:comp/env/service/StockQuoteService"
);
// Get the stub for the service endpoint
com.example.StockQuoteProvider sqp = sqs.getStockQuoteProviderPort();
// Get a quote
float quotePrice = sqp.getLastTradePrice(...);
...
}
}