Jump to content

Web Services with Nested Arrays/Objects. How to input data into these?


jonoc33

Recommended Posts

Hey guys! Haven't been here in a while but it's finally time I need help again.

 

Heres the issue i'm having:

I'm working for my Dad, making a new application called Traveller. They use web services to input data and get data.

Web services so far have worked well for me. They output data perfectly and it's all worked fine.

Now i'm up to the stage where I need to input data to a web service so that it can create a record. It uses ALOT of data.

 

I'm talking:

 

POST /merit_traveller/ws_merit_request.asmx HTTP/1.1

Host: localhost

Content-Type: text/xml; charset=utf-8

Content-Length: length

SOAPAction: "http://tempurl.org/ws_create_request"

 

<?xml version="1.0" encoding="utf-8"?>

<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">

  <soap:Body>

    <ws_create_request xmlns="http://tempurl.org">

      <user_id>string</user_id>

      <password>string</password>

      <req_input>

        <request_id>int</request_id>

        <service_type>string</service_type>

        <request_type>string</request_type>

        <function_type>string</function_type>

        <issue_type>string</issue_type>

        <request_datetime>dateTime</request_datetime>

        <due_datetime>dateTime</due_datetime>

        <count_only>string</count_only>

        <centre>string</centre>

        <priority>string</priority>

        <refer_no>string</refer_no>

        <input_by>string</input_by>

        <how_received>string</how_received>

        <request_description>string</request_description>

        <request_instruction>string</request_instruction>

        <customer_name_det>

          <customer_name_details>

            <name_id>int</name_id>

            <surname>string</surname>

            <given_names>string</given_names>

            <initials>string</initials>

            <pref_title>string</pref_title>

            <telephone>string</telephone>

            <work_phone>string</work_phone>

            <mobile_no>string</mobile_no>

            <fax_no>string</fax_no>

            <email_address>string</email_address>

            <company_name>string</company_name>

            <name_ctr>int</name_ctr>

            <name_type>string</name_type>

          </customer_name_details>

          <customer_name_details>

            <name_id>int</name_id>

            <surname>string</surname>

            <given_names>string</given_names>

            <initials>string</initials>

            <pref_title>string</pref_title>

            <telephone>string</telephone>

            <work_phone>string</work_phone>

            <mobile_no>string</mobile_no>

            <fax_no>string</fax_no>

            <email_address>string</email_address>

            <company_name>string</company_name>

            <name_ctr>int</name_ctr>

            <name_type>string</name_type>

          </customer_name_details>

        </customer_name_det>

        <address_det>

          <address_details>

            <address_id>int</address_id>

            <house_number>string</house_number>

            <house_suffix>string</house_suffix>

            <street_name>string</street_name>

            <street_type>string</street_type>

            <locality>string</locality>

            <postcode>string</postcode>

            <property_no>string</property_no>

            <gis_x_coord>string</gis_x_coord>

            <gis_y_coord>string</gis_y_coord>

            <address_ctr>int</address_ctr>

            <melway_map>string</melway_map>

            <melway_ref>string</melway_ref>

            <address_type>string</address_type>

            <address_desc>string</address_desc>

            <address_type_code>string</address_type_code>

          </address_details>

          <address_details>

            <address_id>int</address_id>

            <house_number>string</house_number>

            <house_suffix>string</house_suffix>

            <street_name>string</street_name>

            <street_type>string</street_type>

            <locality>string</locality>

            <postcode>string</postcode>

            <property_no>string</property_no>

            <gis_x_coord>string</gis_x_coord>

            <gis_y_coord>string</gis_y_coord>

            <address_ctr>int</address_ctr>

            <melway_map>string</melway_map>

            <melway_ref>string</melway_ref>

            <address_type>string</address_type>

            <address_desc>string</address_desc>

            <address_type_code>string</address_type_code>

          </address_details>

        </address_det>

        <ws_status>int</ws_status>

        <ws_message>string</ws_message>

      </req_input>

    </ws_create_request>

  </soap:Body>

</soap:Envelope>

 

Notice how theres nested data or objects in there? Look at address_det, theres multiple address_details in that.

 

At the moment it passes through all values fine, except for these nested objects.

What i'm struggling with is being able to input multiple address detail objects inside address_det. Considering each object would have the same name its a bit hard to code that.

 

Heres what i've got at the moment.

 

$parameters = new Request();
$parameters->user_id = $_COOKIE['user_id'];
$parameters->password = $_COOKIE['password'];	

$parameters->req_input = new ReqInput();
$parameters->req_input->request_id = 0;
$parameters->req_input->request_description = $issue;
$parameters->req_input->refer_no = $refno;
$parameters->req_input->service_type = $service;
$parameters->req_input->request_type = $request;
$parameters->req_input->function_type = $function;
$parameters->req_input->request_datetime = date("Y-m-d") . "T" . date("H:i:s");
$parameters->req_input->due_datetime = date("Y-m-d") . "T" . date("H:i:s");
$parameters->req_input->centre = 'WEB';
$parameters->req_input->how_received = 'WEB';
$parameters->req_input->input_by = $_COOKIE['responsible_code'];

$customer_name_det = 
array(
	"name_id" => 0,
	"pref_title" => $cust_title,
	"given_names" => $cust_given,
	"surname" => $cust_surname,
	"mobile_no" => $cust_mobile,
	"telephone" => $cust_phone,
	"work_no" => $cust_work,
	"email_address" => $cust_email,
	"name_ctr" => 0,
	"company_name" => $cust_company
);

$address_det = 
array(
	array(
		"address_id" => 0,
		"house_number" => $cust_address_number,
		"property_number" => $cust_address_fnumber,
		"street_name" => $cust_address_street,
		"street_type" => $cust_address_streettype,
		"locality" => $cust_address_suburb,
		"address_ctr" => 0,
		"address_desc" => $cust_address_desc
	),
	array(
		"address_id" => 0,
		"house_number" => $loc_address_number,
		"property_number" => $loc_address_fnumber,
		"street_name" => $loc_address_street,
		"street_type" => $loc_address_streettype,
		"locality" => $loc_address_suburb,
		"address_ctr" => 0,
		"address_desc" => $loc_address_desc
	)
);

$parameters->req_input->customer_name_det->customer_name_details = $customer_name_det;
$parameters->req_input->address_det->address_details = $address_det;

$parameters->req_input->ws_status = 0;
$parameters->req_input->ws_message = '';

$wsdl = WEB_SERVICES_PATH.MERIT_REQUEST_FILE."?wsdl";
try {
$client = new SoapClient ($wsdl, array ("classmap" => array ("ws_create_request" => "Request")));
$result = $client->ws_create_request($parameters)->ws_create_requestResult;
}
catch (Exception $e) {
echo $e -> getMessage ();
}

 

Notice where I have the $customer_name_det and $address_det variables. They're the ones that are nested as you'll see in the web service sample.

 

I've tried putting each into an array and then just setting customer_name_det->customer_name_details to that array variable (and address_det->address_details as well ), but when passed through that fails to work as well.

 

How should I input data into these nested objects in a web service?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.