views:

415

answers:

0

Hiya,

I'm using PHP and NuSOAP to create a webservice to serve up various bit of my database to an external application.

The service works just fine, but I need to tweak the XML output from this:

<?xml version="1.0" encoding="ISO-8859-1"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"&gt;
 <SOAP-ENV:Body>
  <ns1:slidebank_authloginResponse xmlns:ns1="urn:Slidebank">
   <id xsi:type="xsd:string">300</id>
   <email xsi:type="xsd:string">[email protected]</email>
   <name xsi:type="xsd:string">Joe Blogs</fname>
   <dept xsi:type="xsd:string">Marketing</dept>
   <role xsi:type="xsd:string">Designer</role>
  </ns1:slidebank_authloginResponse>
 </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

to this... (notice the switch to permissions>dept>role)

<?xml version="1.0" encoding="ISO-8859-1"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"&gt;
 <SOAP-ENV:Body>
  <ns1:slidebank_authloginResponse xmlns:ns1="urn:Slidebank">
   <id xsi:type="xsd:string">300</id>
   <email xsi:type="xsd:string">[email protected]</email>
   <name xsi:type="xsd:string">Joe Blogs</fname>
   <permissions xsi:type="xsd:string" department="Marketing">
     <role xsi:type="xsd:string">Designer</role>
   </permissions >
  </ns1:slidebank_authloginResponse>
 </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Do you know how to play around with the output from the NuSOAP service? I'm creating it using a script which looks a bit like this:

require_once('soap/nusoap/nusoap.php');
$server = new soap_server();
$server->configureWSDL('Service', 'urn:Service');
$server->register('Service_authlogin',  // method name
    array('id' => 'xsd:string',
          'key' => 'xsd:string',
          'hash' => 'xsd:string'),          
    array('id' => 'xsd:string',             // User ID
          'email' => 'xsd:string',          // User email address
          'name' => 'xsd:string',           // User first name
          'dept' => 'xsd:string',           // SB department
          'role' => 'xsd:string'),          // output parameters
    'urn:Service',                      // namespace
    'urn:Service#Service_authlogin',    // soapaction
    'rpc',                                  // style
    'encoded',                              // use
    'Authentication of a user'              // documentation
);
function service_authlogin($id, $key, $hash) {
    //Pull code from DB and pass into variables - 
    //Deleted about 30 lines of this from this example
        return array('id' => $id, 'email' => $email, 'name' => $fname, 'dept' => $dept, 'role' => $role);
        mysql_close($conn);     
    }
}
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);

Thanks for any help or pointers :)