How to make a webservice from an EJB. Jessica Sherrill CIS 764...

Post on 01-Apr-2020

1 views 0 download

transcript

How to make a webservice from an EJB. Jessica Sherrill CIS 764 10/29/06

Prerequisites:

1. JDeveloper version 10.1.3.1 (there is another 10.1.3 version, that is different)2. Have completed an EJB facade bean and client tutorial.

(The example I will be using is using an Employee and a Department.)3. Have completed the standalone OC4J tutorial.

Steps:

1. Open your EJB facade project:

2. Right click on your EJB project, (not the client project) and select Project Properties.Select Libraries and scroll downt o JSR Web Services and add it to the project.

3. Open your facade’s java file (not the facade bean) and add the circled text:(You can add the other @WebMethods as I did, however we will only need

getEmail for this example.)Compile your changes.

4. Select your project and right click and select new. Go to General > Deployment Profiles> EJB JAR Files. Hit OK. You can name the file or leave it with the default name.(My example is emplWS.) Accept the EJB JAR without changes.

5. Select your deployment file (it should be under a Resources directory) and deploy itto your standalone OC4J server. Where it says OC4J in my example it would be thename you gave your OC4J connection.

6. Open up your internet browser of choice. Paste in:http://localhost:8888/emAnd log in using the name/password you set up for using standalone OC4J in a previoustutorial. Select Web Services, select your web service from the radio button options (ifthere are any other web services set up) and hit test service. You should see:

7. Now copy the URL and go back to JDeveloper. Create a new (and empty) project in yourapplication called webserviceclient (or whatever you like). Then right click on it andselect new. Pick Business Tier > Web Services Proxy and hit OK.

8. Take the URL copied from step 7 and paste it in the WSDL Document URL field.Add a ?WSDL to the end of the URL. Hit Next and then Finish.

(Continued on next Page)

9. In the webserviceclient > Application Sources directory you should see awebserviceclient.proxy package, expand it and click on the file inside to view the

contents in the structure pane.

Select the FacadeClient.java (named as yourfacade java file is named, in this case it wasEJBAppFacade.java toEJBAppFacadeClient.java)

Open the Client file.

10. Add the following code to your client’s main function:

System.out.println(myPort.getEmail(100));

(Continued Next Page)

11. Hit run with the client file selected. Your output should be:

(Assuming you have the same sample employee data in your database.)

If employee number 100 is not in your sample data, select a number that is and try again.