Jump to content

Web Services - WSDL for two-dimensional arrays


goodjonx

Recommended Posts

Hey All,

 

I'm programming the server side of a small project and need to offer a few simple operations via web service.

 

Now I've only started with PHP a week ago (usually do Java although not pro-level either). I have a really hard time getting it right:

 

I've tried a few tools to generate the WSDL for me, without success. So I've read everything I could find on WSDL and tried to do it manually - after days of frustration still no idea..

 

Can someone help me out? Thanks!!

 

Rick

 

 

 

Here are my functions:

 

(All fields in the data base are strings)

 

<?php

require_once('SOAP/Server.php');
require_once('SOAP/Disco.php');

$soapserver = new SoapServer('myowngrouper.wsdl');
$soapserver->addFunction('getTopics');
$soapserver->addFunction('getLevels');
$soapserver->addFunction('getPartners'); 
$soapserver->addFunction('setUpdate');
$soapserver->handle();

/**
  * Delivers currently available topics.
  * @return string[][] This function returns a two-dimensional array of strings. 
  */
function getTopics($application)
{
  require_once('config.php');
  
  $dblink = mysql_connect($dbaddress, $dbuser, $dbpassword) or die('Data base connection error in getTopics: '.mysql_error()); 
  mysql_select_db($dbname) or die('Data base selection error in getTopics.');
  
  $result = mysql_query("SELECT topicid, name FROM groupertopicdata;") or die('Data base query error in getTopics: '.mysql_error()); 
  mysql_close($dblink);
  
  $i = 0;
  
  while($row = mysql_fetch_array($result))
  {
   $return[$i][0] = $row['topicid'];
   $return[$i][1] = $row['name'];
   $i++;
  }
  
  return $return;
}


/**
  * Delivers currently available level settings.
  * @return string[][] This function returns a two-dimensional array of strings.
  */
function getLevels($application) 
{
  require_once('config.php');
  
  $dblink = mysql_connect($dbaddress,$dbuser,$dbpassword) or die('Data base connection error in getLevels: '.mysql_error());
  mysql_select_db($dbname) or die('Data base selection error in getLevels: '.mysql_error()); 
  
  $result = mysql_query("SELECT levelid, name FROM grouperleveldata;") or die('Data base query error in getLevels: '.mysql_error());
  mysql_close($dblink);
  
  $i = 0;
  while($row = mysql_fetch_array($result)) 
  {
   $return[$i][0] = $row['levelid'];
   $return[$i][1] = $row['name'];
   $i++;
  }
  
  return $return;
}


/**
  * Stores the client's current data and delivers a set of currently available users with a common topic. 
  * @param string $userid The client's user ID
  * @param string $password The client's password
  * @param string $name The client's chosen name
  * @param string $position The client's current position 
  * @param string $topic The client's current topic
  * @param string $level The client's skill level
  * @return string[][] This function returns a two-dimensional array of strings.
  */
function getPartners($application,$userid,$password,$name,$position,$topic,$level) 
{
  require_once('config.php');
  
  $ip = clientIp();
  
  $dblink = mysql_connect($dbaddress,$dbuser,$dbpassword) or die('Data base connection error in getPartners: '.mysql_error());
  mysql_select_db($dbname) or die('Data base selection error in getPartners: '.mysql_error());
  
  $result = mysql_query("SELECT password FROM grouperuserdata WHERE userid = '".$userid."';") or die('Data base query error in getPartners: '.mysql_error()); 
  
  $row = mysql_fetch_array($result);
  if($row['password'] == md5($password))
  {
   //$headers = apache_request_headers();
   //$ip = $headers['PC-Remote-Addr'];
   $ip = ' 192.168.24.52';
   
   $result = mysql_query("SELECT name, ip, position, level FROM grouperuserdata WHERE topic = '".$topic."' AND userid != '".$userid."';") or die('Data base query error in getPartners: '.mysql_error()); 
   mysql_close($dblink);
   
   $i = 0;
   while($row = mysql_fetch_array($result))
   {
    $return[$i][0] = $row['name'];
    $return[$i][1] = $row['ip'];
    $return[$i][2] = $row['position']; 
    $return[$i][4] = $row['level'];
    $i++;
   }
   
   return $return;
  }
  else
  {
   mysql_close($dblink);
   return null; // authentication failed
  }
}


/** 
  * Stores the client's current data.
  * @param string $userid The client's user ID
  * @param string $password The client's password
  * @param string $name The client's chosen name
  * @param string $position The client's current position 
  * @param string $topic The client's current topic
  * @param string $level The client's skill level
  * @return boolean This function returns TRUE if the operation was successful.
  */
function setUpdate($application,$userid,$password,$name,$position,$topic,$level) 
{
  require_once('config.php');
  
  $ip = clientIp();
  
  $dblink = mysql_connect($dbaddress,$dbuser,$dbpassword) or die('Data base connection error in getPartners: '.mysql_error());
  mysql_select_db($dbname) or die('Data base selection error in setUpdate: '.mysql_error());
  
  $result = mysql_query("SELECT password FROM grouperuserdata WHERE userid = '".$userid."';") or die('Data base query error in setUpdate: '.mysql_error()); 
  
  $row = mysql_fetch_array($result);
  if($row['password'] == md5($password))
  {
   //$headers = apache_request_headers();
   //$ip = $headers['PC-Remote-Addr'];
   $ip = ' 192.168.24.52';
   
   $result = mysql_query("UPDATE grouperuserdata SET name = '".$name."', ip = '".$ip."', position = '".$position."', level = '".$level."' WHERE userid = '".$userid."';") or die('Data base query error in setUpdate: '.mysql_error()); 
   mysql_close($dblink);
   
   return true;
  }
  else
  {
   mysql_close($dblink);
   return false; // authentication failed
  }
}

?>

 

Here's my attempt at a WSDL:

 

<?xml version='1.0' encoding='UTF-8'?>
<definitions name="grouper"
targetNamespace="urn:grouper"
xmlns:typens="urn:grouper"
xmlns:xsd="http://www.w3.org/2001/XMLSchema "
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/ "
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:typens0="http://localhost/grouper/grouper.php">
<types>

  <xsd:schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:grouper">
  
  <xsd:element name="getTopicsRequest" type="tns:Request"/> 
  <xsd:element name="getTopicsResponse" type="tns:TopicArray"/>
  <xsd:element name="getLevelsRequest" type="tns:Request"/>
  <xsd:element name="getLevelsResponse" type="tns:LevelArray"/> 
  <xsd:element name="getPartnersRequest" type="tns:Person"/>
  <xsd:element name="getPartnersResponse" type="tns:PartnerArray"/>
  <xsd:element name="setUpdateRequest" type="tns:Person"/> 
  <xsd:element name="setUpdateResponse" type="tns:Confirmation"/>
  
   <xsd:complexType name="Request">
    <xsd:sequence>
     <xsd:element name="application" type="xsd:string"/> 
    </xsd:sequence>
   </xsd:complexType>
   
   <xsd:complexType name="TopicArray">
    <xsd:sequence>
     <xsd:element name="return" type="tns:Topic" nillable="true" minOccurs="0" maxOccurs="unbounded"/> 
    </xsd:sequence>
   </xsd:complexType>
   
   <xsd:complexType name="LevelArray">
    <xsd:sequence>
     <xsd:element name="return" type="tns:Level" nillable="true" minOccurs="0" maxOccurs="unbounded"/> 
    </xsd:sequence>
   </xsd:complexType>
   
   <xsd:complexType name="Person">
    <xsd:sequence>
     <xsd:element name="application" type="xsd:string"/> 
     <xsd:element name="userid" type="xsd:string"/>
     <xsd:element name="password" type="xsd:string"/>
     <xsd:element name="name" type="xsd:string"/> 
     <xsd:element name="ip" type="xsd:string"/>
     <xsd:element name="position" type="xsd:string"/>
     <xsd:element name="topic" type="xsd:string"/> 
     <xsd:element name="level" type="xsd:string"/>
    </xsd:sequence>
   </xsd:complexType>
   
   <xsd:complexType name="Partner">
    <xsd:sequence> 
     <xsd:element name="application" type="xsd:string"/>
     <xsd:element name="name" type="xsd:string"/>
     <xsd:element name="ip" type="xsd:string"/> 
     <xsd:element name="position" type="xsd:string"/>
     <xsd:element name="level" type="xsd:string"/>
    </xsd:sequence>
   </xsd:complexType> 
   
   <xsd:complexType name="PartnerArray">
    <xsd:sequence>
     <xsd:element name="return" type="tns:Partner" nillable="true" minOccurs="0" maxOccurs="unbounded"/> 
    </xsd:sequence>
   </xsd:complexType>
   
   <xsd:complexType name="Confirmation">
    <xsd:sequence>
       <xsd:element name="return" type="xsd:boolean"/> 
    </xsd:sequence>
   </xsd:complexType>
   
  </xsd:schema>
  
<message name="getTopicsRequest">
  <part name="parameters" type="tns:Request"/> 
</message>

<message name="getTopicsResponse">
  <part name="parameters" type="tns:TopicArray"/>
</message>

<message name="getLevelsRequest"> 
  <part name="parameters" type="tns:Request"/>
</message>

<message name="getLevelsResponse">
  <part name="parameters" type="tns:LevelArray"/> 
</message>

<message name="getPartnersRequest">
  <part name="parameters" type="tns:Partner"/>
</message>

<message name="getPartnersResponse"> 
  <part name="parameters" type="tns:PartnersArray"/>
</message>

<message name="setUpdateRequest">
  <part name="parameters" type="tns:Partner"/> 
</message>

<message name="setUpdateResponse">
  <part name="parameters" type="xsd:boolean"/>
</message>

<portType name="GrouperPortType"> 
  <documentation>
   This web service supports the Grouper application.
  </documentation>
  
  <operation name="getTopics"> 
   <documentation>
    Delivers a set of currently available topics.
   </documentation>
   <input message="typens:getTopicsRequest"/>
   <output message="typens:getTopicsResponse"/> 
  </operation>
  
  <operation name="getLevels">
   <documentation>
    Delivers a set of skill level designations.
   </documentation>
   <input message="typens:getLevelsRequest"/> 
   <output message="typens:getLevelsResponse"/>
  </operation>
  
  <operation name="getPartners">
   <documentation>
    Stores the client's current status and delivers a set of currently available users on the same topic. 
   </documentation>
   <input message="typens:getPartnersRequest"/>
   <output message="typens:getPartnersResponse"/>
  </operation>
  
  <operation name="setUpdate"> 
   <documentation>
    Stores the client's current status.
   </documentation>
   <input message="typens:setUpdateRequest"/>
   <output message="typens:setUpdateResponse"/> 
  </operation>
</portType>

<binding name="GrouperBinding" type="typens:GrouperPortType">
  <soap:binding style="document" transport=" http://schemas.xmlsoap.org/soap/http"/>
  <operation name="getLevels">
   <soap:operation soapAction="urn:GrouperAction"/>
   <input>
    <soap:body namespace="urn:grouper" use="literal" encodingStyle=" http://schemas.xmlsoap.org/soap/encoding/"/>
   </input>
   <output>
    <soap:body namespace="urn:grouper" use="literal" encodingStyle=" http://schemas.xmlsoap.org/soap/encoding/"/>
   </output>
  </operation>
  <operation name="getPartners">
   <soap:operation soapAction="urn:GrouperAction"/> 
   <input>
    <soap:body namespace="urn:grouper" use="literal" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/ >
   </input>
   <output>
    <soap:body namespace="urn:grouper" use="literal" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/ >
   </output>
  </operation>
  <operation name="getTopics">
   <soap:operation soapAction="urn:GrouperAction"/>
   <input>
    <soap:body namespace="urn:grouper" use="literal" encodingStyle=" http://schemas.xmlsoap.org/soap/encoding/"/>
   </input>
   <output>
    <soap:body namespace="urn:grouper" use="literal" encodingStyle=" http://schemas.xmlsoap.org/soap/encoding/"/>
   </output>
  </operation>
  <operation name="setUpdate">
   <soap:operation soapAction="urn:GrouperAction"/> 
   <input>
    <soap:body namespace="urn:grouper" use="literal" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/ >
   </input>
   <output>
    <soap:body namespace="urn:grouper" use="literal" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/ >
   </output>
  </operation>
</binding>

<service name="grouperService">
  <port name="GrouperPort" binding="typens:GrouperBinding"> 
   <soap:address location="http://localhost/grouper/grouper.php"/>
  </port>
</service>

</definitions>

 

Link to comment
Share on other sites

Can no one give me a pointer? I suspected that web services are a PHP weakness, but someone must have some experience with it?

 

I am especially wondering if there's a better way return the data, perhaps a string[] would be easier to implement than a string[][] although not as pretty? Or is there a more direct way to return a mysql result..?

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.