< Day Day Up > |
WebLogic Workshop fully supports creating and using Web services. With Workshop, you can create Web services from scratch or extend an existing Web service. Workshop also supports creating control wrappers around existing Web services, whether they were created with Workshop or exist outside WebLogic Server. To create a Web service, follow the steps shown in Figure 9.3:
Figure 9.3. Creating Web services.
From a Workshop development perspective, Web services look much like controls. Web services have methods, can support callbacks, and can use other controls, EJBs, or J2EE services. You can add methods simply by dragging them from the Data Palette, as you would with a control or Page Flow. Exposing Web Services Beyond WorkshopWeb services are typically created to make a service or an interface available to the outside world. WebLogic Workshop Web services are no different, and external Web service consumers can easily use them. Examine the creditServices Web service, which the Wonderland Casino requires to support checking a player's credit limit. creditServices supports the checklimit method, which takes a string name and a bet in the form of an integer and returns true or false, depending on whether the player's bet is within his or her limit. Table 9.1 lists some of the more important components created for the creditServices Web service. Table 9.1. Web Services Components
Using Web Services Within Workshop ApplicationsAlthough a Web service is typically used to make a service available to the outside world, often you want to use a previously defined Web service from within a Workshop application. The following list illustrates three possible situations in which you would access Web services from within a Workshop application:
The simplest situation is having a Web service contained within the same project as the Web or portal application. In this case, you can simply right-click the Web service JWS file, and choose Generate Service Control. A control with the same name as the Web service is created, with Control.jcx added to the end of the name. Drag and drop the newly created control onto a Page Flow or any other consumer, and use it as you normally would. If the Web service is nonlocal , you need to access its WSDL to create a control wrapper. WebLogic Workshop can easily create a WSDL file from a Web service. To do this, right-click the Web service, and choose Generate WSDL File. A WSDL file is created with the same name as the Web service, but it ends in Contract.wsdl . Workshop is smart enough to keep the associated WSDL file synchronized with its Web service parent. Changes to the Web service's methods or signatures cause an update to the associated WSDL. To create a Web service control around an external Web service within a Page Flow, follow the steps shown in Figure 9.4:
Figure 9.4. Creating a Web service control from an external Web service.
Workshop then creates a JCX file defined by the selected WSDL that can be used like any other control. It's important to note that the newly created control represents the Web service as it was defined by the WSDL file at its moment of creation. If the underlying Web service changes, such as modifying a method signature, the control instance will not match the running service. Be careful to ensure that the Web service is stable before you create a control from it. Using Web Services from Standalone ApplicationsAs you've seen, using Web services from within a Workshop application is easy. But what about using Workshop-created Web services from within a standalone Java client or JSP page?
Workshop-based Web services provide proxy JAR files that enable standalone clients to call Web services directly. Listing 9.1 details a simple Java client that uses the checkcredit method of the client service's Web service. Listing 9.1. client.javaimport weblogic.jws.proxies.*; public class client { public static void main(String[] args) { try { System.out.println("Attempting to get credit services proxy"); CreditServices_Impl proxy = new CreditServices_Impl(); System.out.println("Using proxy to get service object instance"); CreditServicesSoap sp = proxy.getcreditServicesSoap(); System.out.println("Calling service method"); System.out.println("check credit(Al,100) returned:" + + sp.checkcredit("Al",100)); System.out.println("check credit(Tom,1000) returned:" + sp.checkcredit("Tom",1000)); System.out.println("check credit(Unknown,1000) returned:" + sp.checkcredit("Unknown",1000)); } catch (Exception e) { e.printStackTrace(); } } } Using a Web service from a Java client requires first downloading the client proxy JAR and its associated Web service's support JAR file (in this example, creditServices.jar and webservicesclient.jar ), and then adding them to the application's classpath. After you've obtained the required JARs, using the Web service is a three-step coding process:
Of course, you can also use the client normally from a JSP by writing similar code, but embedding it appropriately within <% and %> JSP tags. |
< Day Day Up > |