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 544991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:42:51+00:00 2026-05-13T10:42:51+00:00

I have defined a web service that will return the data from my mysql

  • 0

I have defined a web service that will return the data from my mysql data base.

I have written the web service in php.

Now I have defined a complex type as follows:

$server->wsdl->addComplexType(
'Category',
'complexType',
'struct',
'all',
'',
array(
    'category_parent_id' => array('name' => 'category_parent_id', 'type' => 'xsd:int'),
    'category_child_id' => array('name' => 'category_child_id', 'type' => 'xsd:int'),
    'category_list' => array('name' => 'category_list', 'type' => 'xsd:int')
)

);

The above complex type is a row in a table in my database.

Now my function must send an array of these rows so how do I achieve the same

My code is as follows:

require_once('./nusoap/nusoap.php');
$server = new soap_server;

$server->configureWSDL('productwsdl', 'urn:productwsdl');

// Register the data structures used by the service
$server->wsdl->addComplexType(
    'Category',
    'complexType',
    'struct',
    'all',
    '',
    array(
        'category_parent_id' => array('name' => 'category_parent_id', 'type' => 'xsd:int'),
        'category_child_id' => array('name' => 'category_child_id', 'type' => 'xsd:int'),
        'category_list' => array('name' => 'category_list', 'type' => 'xsd:int')
    )
);
$server->register('getaproduct',                    // method name
    array(),          // input parameters
    //array('return' => array('result' => 'tns:Category')),    // output parameters
    array('return' =>  'tns:Category'),    // output parameters
    'urn:productwsdl',                         // namespace
    'urn:productwsdl#getaproduct',                   // soapaction
    'rpc',                                    // style
    'encoded',                                // use
    'Get the product categories'        // documentation
);

function getaproduct()
{
    $conn = mysql_connect('localhost','root','');
     mysql_select_db('sssl', $conn);
     $sql = "SELECT * FROM jos_vm_category_xref";
     $q = mysql_query($sql);
     while($r = mysql_fetch_array($q))
     {
         $items[] = array('category_parent_id'=>$r['category_parent_id'],
                              'category_child_id'=>$r['category_child_id'],
                              'category_list'=>$r['category_list']);
     }
       return $items;
}


    // Use the request to (try to) invoke the service
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
  • 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-05-13T10:42:51+00:00Added an answer on May 13, 2026 at 10:42 am

    I figured the answer myself after searching the internet.

    Following is the code to create a complex data type. Here I am creating a datatype Person whch has firstname, age and gender as its data members.

    $server->wsdl->addComplexType(
      'Person',
      'complexType',
      'struct',
      'all',
      '',
      array(
        'firstname' => array('name' => 'firstname', 'type' => 'xsd:string'),
        'age'       => array('name' => 'age', 'type' => 'xsd:int'),
        'gender'    => array('name' => 'gender', 'type' => 'xsd:string')
      )
    );
    

    Next we must create another new datatype which is an array of the datatype we have created. I call it the person array and the code for it is below:

    $server->wsdl->addComplexType(
        'PersonArray',    // Name
        'complexType',    // Type Class
        'array',          // PHP Type
        '',               // Compositor
        'SOAP-ENC:Array', // Restricted Base
        array(),
        array(
            array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:Person[]')
        ),
        'tns:Person'
    );
    

    Now I registered a function called getPeople which takes no input parameters but return an array of persons as:

    $server->register(
        'getPeople',                          // method name
        array(),                              // input parameters
        array('return' => 'tns:PersonArray'), // output parameters
        'urn:hellowsdl2',                     // namespace
        'urn:hellowsdl2#getPeople',           // soapaction
        'rpc',                                // style
        'encoded',                            // use
        'Return an array of people'           // documentation
    );
    

    and programmed the function to return some dummy data as:

    function getPeople()
    {
        $peopleArray = array();
        $peopleArray[] = array(
            'firstname' => "Anand",
            'age'       => 25,
            'gender'    => "Male"
        );
    
        $peopleArray[] = array(
            'firstname' => "Sandhya",
            'age'       => 21,
            'gender'    => "Female"
        );
    
        return $peopleArray;
    }
    

    by the way I am sorry I haven’t mentioned but all this code is in PHP.

    Hope this helps someone.

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

Sidebar

Ask A Question

Stats

  • Questions 372k
  • Answers 372k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Your example datetime stamp is not conforming to CLDR, so… May 14, 2026 at 7:22 pm
  • Editorial Team
    Editorial Team added an answer I've found a solution to my own problem. When you… May 14, 2026 at 7:22 pm
  • Editorial Team
    Editorial Team added an answer You shouldn't use document.write or document.writeln after the page has… May 14, 2026 at 7:22 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.