users@jax-rpc.java.net

Re: Return an array of objects

From: trebor iksrazal <iksrazal_at_yahoo.com>
Date: Wed, 7 Sep 2005 03:38:47 -0700 (PDT)

> So, my question is how I have to contruct this
> message from server side.

Its a bit tricky the first time, but perhaps looking
at an example of how I do it may help:

   <complexType name="ReturnWeb_Base">
        <sequence>
          <element name="errorMessage" type="string"/>
          <element name="successErrorCode"
type="int"/></sequence></complexType>

This is nessecary in my example because all methods
return an error code/message to indicate
success/failure.

 <complexType
name="ReturnWeb_AdminResellerListNewsCentres">
        <complexContent>
          <extension base="tns:ReturnWeb_Base">
            <sequence>
              <element name="list"
type="tns:ArrayOfReturnWeb_AdminResellerListNewsCentres_Item"/></sequence></extension></complex
Content></complexType>
      <complexType
name="ArrayOfReturnWeb_AdminResellerListNewsCentres_Item">
        <complexContent>
          <restriction base="soap11-enc:Array">
            <attribute ref="soap11-enc:arrayType"
wsdl:arrayType="tns:ReturnWeb_AdminResellerListNewsCentres_Item[]"/></restrictio
n></complexContent></complexType>
      <complexType
name="ReturnWeb_AdminResellerListNewsCentres_Item">
        <sequence>
          <element name="news_id" type="int"/>
          <element name="call_centre_id" type="int"/>
          <element name="call_centre_name"
type="string"/></sequence></complexType>

So what this says is my complex object extends
'ReturnWeb_Base' - hopefully not confusing you, see
below, and the web service returns
ReturnWeb_AdminResellerListNewsCentres .

To complete the wsdl we have:

<message
name="CallCentreWebEndpoint_web_adminreseller_ListNewsCentres">
    <part name="soap_session_id" type="xsd:string"/>
  </message>
  <message
name="CallCentreWebEndpoint_web_adminreseller_ListNewsCentresResponse">
    <part name="result"
type="ns2:ReturnWeb_AdminResellerListNewsCentres"/>
  </message>

  <operation name="web_adminreseller_ListNewsCentres"
parameterOrder="soap_session_id">
      <input
message="tns:CallCentreWebEndpoint_web_adminreseller_ListNewsCentres"/>
      <output
message="tns:CallCentreWebEndpoint_web_adminreseller_ListNewsCentresResponse"/>
    </operation>

<operation name="web_adminreseller_ListNewsCentres">
      <soap:operation soapAction=""/>
      <input>
        <soap:body
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
use="encoded"
namespace="http://localhost/callcentreweb"/></input>
      <output>
        <soap:body
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
use="encoded"
namespace="http://localhost/callcentreweb"/></output></operation>

The web service method signature is:

public ReturnWeb_AdminResellerListNewsCentres
web_adminreseller_ListNewsCentres(
                        String soap_session_id) throws
RemoteException {
ReturnWeb_AdminResellerListNewsCentres result = null;
 
result =
MyDAODelegate.web_adminreseller_ListNewsCentres(params);
                                                      
            
             
} catch(Exception ex) {
             result = new
ReturnWeb_AdminResellerListNewsCentres();
            
result.setErrorMessage(Messages_Codes.getcode(Messages_Codes.FAILURE.intValue()));
          return result;
        }

return result;
}

Ignore the soap_session_id - its not relevent here.
Hand coded of course.

Now, the delegate converts list to array as follows:

ReturnWeb_AdminResellerListNewsCentres result = new
ReturnWeb_AdminResellerListNewsCentres();
                int ret =
Messages_Codes.FAILURE.intValue();
ArrayList list = new ArrayList();
list.add(item1);
list.add(item2);
list.add(item3);

ReturnWeb_AdminResellerListNewsCentres_Item[]
list_array = new
ReturnWeb_AdminResellerListNewsCentres_Item[0];
                        list_array =
(ReturnWeb_AdminResellerListNewsCentres_Item[])
list.toArray(list_array);
                        // 'list' in wsdl example
                        result.setList(list_array);

                        ret =
Messages_Codes.SUCCESS.intValue();


result.setSuccessErrorCode(ret);
                     
result.setErrorMessage(Messages_Codes.getcode(ret));
                        return result;

HTH,
iksrazal
http://www.braziloutsource.com/

"None are more hopelessly enslaved than those who falsely believe they are free. -- Goethe"

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com