Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9082117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:28:48+00:00 2026-06-16T20:28:48+00:00

tl;dr: sending multiple strings as a response to SOAP request. I am new to

  • 0

tl;dr: sending multiple strings as a response to SOAP request.

I am new to SOAP. I have written a simple web service which serves request via SOAP. As I wanted to implement this in PHP, I have used NuSOAP library. The specification given to me for the SOAP API design is as follows.

REQUEST FORMAT:

<?xml version="1.0" encoding="utf-8"?> 
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:q0="http://www.sandeepraju.in/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
<soapenv:Body> 
<q0:getData> 
<token>String</token> 
</q0:getData> 
</soapenv:Body> 
</soapenv:Envelope>

EXAMPLE / SAMPLE RESPONSE:

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:getDataResponse xmlns:ns2="http://www.sandeepraju.in/">
<return>
<Data>
   <animal>cat</animal>
   <phone>225</phone>
   <code>FYI</code>
</Data>

The PHP code I have written for the above specification is as follows.

require_once("../nusoap_old/lib/nusoap.php");

// Definition of getData operation
function getData($token) {
    if($token == "somestring") {
        return array("animal" => "cat", "phone" => "225", "code" => "FYI");
    }
    else {
        return array("animal" => "null", "phone" => "null", "code" => "null");
    }  
}

// Creating SOAP server Object
$server = new soap_server();

// Setup WSDL
$server->configureWSDL('catnews', 'urn:catinfo');

$server->wsdl->addComplexType('return_array_php',
    'complexType',
    'struct',
    'all',
    '',
    array(
    'animal' => array('animal' => 'animal', 'type' => 'xsd:string'),
    'phone' => array('phone' => 'phone', 'type' => 'xsd:string'),
    'code' => array('code' => 'code', 'type' => 'xsd:string')
   )
);

// Register the getData operation
$server->register("getData",
    array('token' => 'xsd:string'),
    array('return' => 'tns:return_array_php'),
    'urn:catinfo',
    'urn:catinfo#getData');

// Checking POST request headers
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA)? $HTTP_RAW_POST_DATA : "";
$server->service($HTTP_RAW_POST_DATA);

Here, I think I should NOT return a PHP array. But I am not sure what I should return according the specification. Can anyone help me with this. Or returning an array is correct?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T20:28:49+00:00Added an answer on June 16, 2026 at 8:28 pm

    You need to add another complex type for an array consisting of your data.
    Like this:

    $server->wsdl->addComplexType(
        'dataArray',    // MySoapObjectArray
        'complexType', 'array', '', 'SOAP-ENC:Array',
        array(),
        array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:return_array_php[]')), 'tns:return_array_php'
    );
    

    Register the new datatype to be the return-value of the function.

    $server->register(
        'getData',     
        array('Datum'=>'xsd:token'), 
        array('return'=>'tns:dataArray'),
        $namespace,
        false,
        'rpc',
        'encoded',
        'description'
    );
    

    Then your function needs to set the single parts of the array.

    function GetData($token)
    {
        if($token == "somestring") {
            $result[0] = array(
                "animal"  => "cat",
                "phone"   => "225",
                "code"    => "FYI"
            );
    
            $result[1] = array(
                "animal"  => "dog",
                "phone"   => "552",
                "code"    => "IFY"
            );
        } else {
            $result = null;
        }
        return $result;
    }
    

    The response of this service called with the string “somestring” will be:

    <ns1:getDataResponse xmlns:ns1="http://localhost/status/status.php">
        <return xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="tns:return_array_php[2]">
            <item xsi:type="tns:return_array_php">
               <animal xsi:type="xsd:string">cat</animal>
               <phone xsi:type="xsd:string">225</phone>
               <code xsi:type="xsd:string">FYI</code>
            </item>
            <item xsi:type="tns:return_array_php">
               <animal xsi:type="xsd:string">dog</animal>
               <phone xsi:type="xsd:string">552</phone>
               <code xsi:type="xsd:string">IFY</code>
            </item>
        </return>
    </ns1:getDataResponse>
    

    That matches your specifications.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I sending ajax request from a jQuery file like below, which expects response in
Hi I am new to Restful web service. My Goal is to create multiple
I have an AJAX intensive application that requires sending multiple AJAX requests rapidly or
I'm having problems, while sending multiple attachments in my program. I didn't have any
In my app i am sending multiple sms at one time which working perfectly
I have some JavaScript which I want to perform a REST Request (GET) to
I've tried to program sending messages from one server to multiple clients. I have
I have a program which will be receiving information from an external source via
How to use multithreading in c# for sending the SMS to multiple person at
sending mail along with embedded image using asp.net I have already used following but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.