After you’ve deployed a web service, you can use the example code on the WebLogic Web Services Home Page to invoke the web service.
Write a test client as follows:
1 Copy the example code on the Home Page.
E x p o r t i n g E J B s a s w e b s e r v i c e s
4 Modify the code to invoke and test the service.
For example, package untitled1;
import untitled1.generated.*; //<client>.jar import java.io.*;
public class Untitled1 {
public static void main(String[] args){
try {
String wsdlUrl =
"http://localhost:7001/web-services/untitled1?WSDL";
Bean1 service = new Bean1_Impl(wsdlUrl);
Bean1Port port = service.getBean1Port();
System.out.println(port.getSample());
}
catch (IOException ex) { ex.printStackTrace();
} } }
5 Right-click the new test class and choose Run to run the test and invoke the web service.
See also
• “Using the WebLogic Web Services Home Page” on page 4-5
• “The WebLogic Web Services Home Page and WSDL URLs”
in the WebLogic documentation at
http://edocs.bea.com/wls/docs70/webserv/client.html#1051033
Exporting EJBs as web services
Exporting Enterprise JavaBeans (EJBs) as web services in JBuilder requires no additional work other than configuring the project for web services.
Simply develop your EJB application as usual, configure the project for web services with the Web Services Configuration wizard, and run the project with the Web Services Server run configuration created by the wizard. Any EJBs in the project are automatically deployed to the
WebLogic Server as web services without any additional steps. By default, JBuilder automatically exposes all the stateless session beans with
business methods in the remote interface. You can also override this default behavior and select only the Enterprise JavaBean (EJB) modules, beans, and methods that you want to expose as web services.
Note Exporting an EJB is different from exporting a Java class. You must explicitly export a Java class with the Export As A Web Service wizard.
E x p o r t i n g E J B s a s w e b s e r v i c e s
EJBs, however, are exported automatically if the project is configured for web services with the Web Services Configuration wizard.
Important For configuration issues with application servers, see Chapter 10,
“Modifying enterprise application server settings for web services,” and the “Release Notes” (Help|Release Notes).
To create an EJB-based web service, complete the following steps:
1 Choose File|New Project to create a new project.
2 Set WebLogic Application Server 7.x as the server for the project on the Server tab of Project Properties (Project|Project Properties).
3 Use the Web Services Configuration wizard to configure the project for web services. You’ll create a web services WebApp and an EAR. This wizard creates a run configuration based on the project application server. For more information on the Web Services Configuration wizard, see “Working with the Web Services Configuration wizard” on page 3-1.
4 Create one or more EJB 2.0 modules and populate them with session and entity beans. Implement them as you would with any EJB application. You may already have coarse-grained stateless session beans. If you don’t, you need to create one, as only stateless session beans are exposed as web services. The stateless session beans must have at least one valid method in the remote interface. This model parallels the access of beans from a web container, such as Servlet/JSPs.
For more information on EJBs, see the Enterprise JavaBeans Developer’s Guide.
5 Choose Project|Make Project to build the project.
Note The wizard creates a deployment file, servicegen.wldu. Any manual edits to the deployment files are overwritten by the toolkit. If you edit servicegen.wldu, turn off the Regenerate Deployment option on the Web Services tab of the Build page of Project Properties or servicegen.wldu will be overwritten by the toolkit when you build the project. For more information, see “Setting build options” on page 3-6.
6 Choose Run|Run Project to run the project with the Web Services Server run configuration. This run configuration builds the project, deploys the EJBs, and runs the server. JBuilder deploys all the 2.0 compliant EJB modules and session beans in the project automatically.
If you want to change this deployment behavior, right-click the EJB-based Services node in the web services WebApp and choose Properties. Uncheck any modules or beans that you don’t want to expose.
D e p l o y i n g w e b s e r v i c e s
8 Test the EJB deployment on the WebLogic Web Services Home Page as described in “Testing deployed services” on page 8-8.
9 Copy the example code from the Home page and modify it to create a client to invoke and test the exported web service. For an example, see
“Writing the client and consuming the service locally” in Chapter 18,
“Tutorial: Creating a web service from an EJB application with WebLogic Server.”
Note that if you modify the EJB application after you’ve exported it as a service, you’ll need to rebuild and redeploy the application again for the changes to take effect.
For a tutorial that demonstrates the complete web services cycle using EJBs, see Chapter 18, “Tutorial: Creating a web service from an EJB application with WebLogic Server.”
Deploying web services
The Export As A Web Service wizard creates an XML web services deployment descriptor file called servicegen.wldu that provides
deployment information to the WebLogic Server. When EJBs are exported as web services, which JBuilder automatically exports without using a wizard, a .wldu file is generated for each EJB module in the project.