InfoCenter Home >
4: Developing applications >
4.8: Web services - an overview >
4.8.1: Web services components >
4.8.1.2: SOAP support >
4.8.1.2.2: Building a SOAP client >
4.8.1.2.2.1: Accessing enterprise beans through SOAP

4.8.1.2.2.1: Accessing enterprise beans through SOAP

Calling enterprise beans through SOAP is handled in the same manner as calling Java bean methods through SOAP. The SOAP runtime handles the bean cases for you, such as calling an enterprise bean's create method if the create was not called previously.

A Web service can be a simple stateless session bean that performs number processing and returns a data value. When the client code makes a call to the data processing method of this service and an instance of the stateless session is not available, the SOAP runtime does the following:

  • Calls the EJB create method to obtain a stateless session
  • Calls the requested method

At times the client code must do additional work to use enterprise beans through SOAP. For example, if a Web application intends to use stateful or entity beans that persist data between calls, the client requires a reference to identify the bean instance that must be accessed in subsequent calls to methods. This reference/key can be obtained from the response object that the client receives on the initial call to the bean.

Response objects are created:

  • When the client explicitly calls a create method
  • From a findByPrimaryKey() Entity Bean method call
  • From a regular bean method call

The following code example demonstrates calling a bean's create method with parameters:


/*This  code snippet is from a simple MessageBoard bean that
stores strings sent to it for retrieval at a later date.*/


...
/*Call create with \"This is a test\"to initialize the EJB*/
call = new Call();
call.setTargetObjectURI("urn:messageboard");

/*Note, you can explicitly call a create. Parameters for the bean's create can be passed like parameters to any SOAP RPC call.*/
call.setMethodName("create");
call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
params = new Vector();
params.addElement(new Parameter("msg", String.class, "This is a test", null));
call.setParams(params);

System.out.println("Calling create with \"This is a test\"");
resp = call.invoke(url, "");

/*Now use the same instance of the bean that you just 'created' and initialized. Obtain the reference from the response object through the method getFullTargetObjectURI()*/
ejbKeyURI = resp.getFullTargetObjectURI();

/*Subsequent calls to this bean can now be made by using the obtained ejb key.*/
/*Call getMessage using the handle from the create*/
call = new Call();
call.setFullTargetObjectURI(ejbKeyURI);
call.setMethodName("getMessage");
call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
System.out.println("Calling getMessage:");
resp = call.invoke(url, "");
...

Go to previous article: Building a SOAP client Go to next article: Deploying a programming artifact as a SOAP accessible Web service

 

 
Go to previous article: Building a SOAP client Go to next article: Deploying a programming artifact as a SOAP accessible Web service