<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Dimuthu's Blog &#187; guide</title>
	<atom:link href="http://www.dimuthu.org/tag/guide/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dimuthu.org</link>
	<description>Waiting for your comments</description>
	<lastBuildDate>Wed, 21 Dec 2011 05:39:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<image>
  <link>http://www.dimuthu.org</link>
  <url>http://www.dimuthu.org/favicon.ico</url>
  <title>Dimuthu's Blog</title>
</image>
		<item>
		<title>MSSQL(Microsoft SQL) Data Services In PHP</title>
		<link>http://www.dimuthu.org/blog/2008/10/04/mssqlmicrosoft-sql-data-services-in-php/</link>
		<comments>http://www.dimuthu.org/blog/2008/10/04/mssqlmicrosoft-sql-data-services-in-php/#comments</comments>
		<pubDate>Sat, 04 Oct 2008 16:18:04 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[DataServices]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[WSDL]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[data services]]></category>
		<category><![CDATA[guide]]></category>
		<category><![CDATA[MSSQL]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[wsdl generation]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=387</guid>
		<description><![CDATA[PHP in most percentage is used with MySQL Server in LAMP or WAMP stacks. But there may be situations where PHP uses MSSQL databases in back-end. And PHP scripts can be used to make Web services exposing MSSQL Databases. That is enabled by the  Data Services capability in WSF/PHP 2.0.0. Here are the steps to [...]]]></description>
			<content:encoded><![CDATA[<p>PHP in most percentage is used with MySQL Server in LAMP or WAMP stacks. But there may be situations where PHP uses MSSQL databases in back-end. And PHP scripts can be used to make Web services exposing MSSQL Databases. That is enabled by the  Data Services capability in <a href="http://wso2.org/projects/wsf/php">WSF/PHP 2.0.0</a>.</p>
<p>Here are the steps to get the PHP Data Services working with MSSQL in windows. You can safelty skip the starting point if you have already have the necessory software installed.</p>
<ul>
<li>Download <a href="http://httpd.apache.org/download.cgi">Apache Web Server</a>, <a href="http://php.net/">PHP</a> and MSSQL server. (You can download the MSSQL server 2005 expess edition from <a href="http://www.microsoft.com/sql/editions/express/default.mspx">here</a>.</li>
<li>Enable the php_mssql, php_pdo and php_pdo_mssql extension from the php.ini.</li>
<li>If you have MSSQL server 2005, the default client DLL (ntwdblib.dll) use to connect to MSSQL server will not work. So you need to download a newer version of this dll. You can easily find this <a href="http://www.google.lk/search?q=ntwdblib.dll">googling the name of the dll</a>. (The dll version worked for me is 2000.80.194.0). Copy this dll to following directories.
<ul>
<li>&lt;your_windows_drive&gt;/windows/system32</li>
<li>&lt;your_apache_installation&gt;/apache2/bin</li>
</ul>
</li>
<li>To Demo purpose I have created a MSSQL database called &#8220;RESTFulSchool&#8221; and and table called &#8216;Subjects&#8221; with the following schema. If you already have a MSSQL database you can just continue with that.<br />
<table border="1">
<tbody>
<tr style="background:#dddddd">
<td>Column Name</td>
<td>Data Type</td>
</tr>
<tr>
<td>subjectID</td>
<td>int</td>
</tr>
<tr>
<td>subjectName</td>
<td>text</td>
</tr>
<tr>
<td>subjectTeacher</td>
<td>text</td>
</tr>
</tbody>
</table>
<p>And make sure you fill some data into the table. You can get this done easily with MSSQL Server Management Studio downloadable from <a href="http://www.microsoft.com/sql/editions/express/default.mspx">http://www.microsoft.com/sql/editions/express/default.mspx</a></li>
<li>So here is my code to the Data Service. Note in the config variable I have given the information about my MSSQL connection.
<pre class="php"><span style="font-weight: bold; color: #000000;">&lt;?php</span>

<span style="font-style: italic; color: #808080;">//Including the Data Services library</span>
<span style="color: #b1b100;">require_once</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"wso2/DataServices/DataService.php"</span><span style="color: #66cc66;">)</span>;

<span style="font-style: italic; color: #808080;">//Including the connection information for my MSSQL Connection</span>
<span style="color: #b1b100;">require_once</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"constants.php"</span><span style="color: #66cc66;">)</span>;

<span style="font-style: italic; color: #808080;">// database configurations</span>
<span style="color: #0000ff;">$config</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span>
		<span style="color: #ff0000;">"db"</span> =&gt; <span style="color: #ff0000;">"mssql"</span>,
		<span style="color: #ff0000;">"username"</span> =&gt; MSSQL_USERNAME
		<span style="color: #ff0000;">"password"</span> =&gt; MSSQL_PASSWORD
		<span style="color: #ff0000;">"dbname"</span> =&gt; <span style="color: #ff0000;">"RESTfulSchool"</span>,
		<span style="color: #ff0000;">"dbhost"</span> =&gt; MSSSQL_SERVER_NAME
		<span style="color: #66cc66;">)</span>;

<span style="color: #0000ff;">$output_format</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span>
                    <span style="color: #ff0000;">"resultElement"</span> =&gt; <span style="color: #ff0000;">"subjects"</span>,
                    <span style="color: #ff0000;">"rowElement"</span> =&gt; <span style="color: #ff0000;">"subject"</span>,
                    <span style="color: #ff0000;">"elements"</span> =&gt; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span>
                            <span style="color: #ff0000;">"name"</span> =&gt; <span style="color: #ff0000;">"subjectName"</span>,
                            <span style="color: #ff0000;">"teacher"</span> =&gt; <span style="color: #ff0000;">"subjectTeacher"</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;

<span style="color: #0000ff;">$sql</span> = <span style="color: #ff0000;">"SELECT subjectName, subjectTeacher FROM Subjects"</span>;

<span style="color: #0000ff;">$get_subjects_op</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"outputFormat"</span> =&gt; <span style="color: #0000ff;">$output_format</span>, <span style="color: #ff0000;">"sql"</span> =&gt; <span style="color: #0000ff;">$sql</span><span style="color: #66cc66;">)</span>;

<span style="color: #0000ff;">$get_subjects_url</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"HTTPMethod"</span> =&gt; <span style="color: #ff0000;">"GET"</span>, <span style="color: #ff0000;">"RESTLocation"</span> =&gt; <span style="color: #ff0000;">"subjects"</span><span style="color: #66cc66;">)</span>;

<span style="font-style: italic; color: #808080;">// list of operations</span>
<span style="color: #0000ff;">$operations</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span>
                <span style="color: #ff0000;">"getSubjects"</span> =&gt; <span style="color: #0000ff;">$get_subjects_op</span>,
                <span style="color: #66cc66;">)</span>;

<span style="font-style: italic; color: #808080;">// list of rest url mappping (operation =&gt; url)</span>
<span style="color: #0000ff;">$restmap</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span>
                <span style="color: #ff0000;">"getSubjects"</span> =&gt; <span style="color: #0000ff;">$get_subjects_url</span>,
                <span style="color: #66cc66;">)</span>;

<span style="font-style: italic; color: #808080;">// creating DSService and reply</span>
<span style="color: #0000ff;">$service</span> = <span style="font-weight: bold; color: #000000;">new</span> DataService<span style="color: #66cc66;">(</span><a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"config"</span> =&gt; <span style="color: #0000ff;">$config</span>, <span style="color: #ff0000;">"operations"</span> =&gt; <span style="color: #0000ff;">$operations</span>, <span style="color: #ff0000;">"RESTMapping"</span>=&gt;<span style="color: #0000ff;">$restmap</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;
<span style="color: #0000ff;">$service</span>-&gt;<span style="color: #006600;">reply</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;

<span style="font-weight: bold; color: #000000;">?&gt;</span></pre>
</li>
<li> You just wrote a SOAP+REST Data Service to expose your MSSQL Data as a Web Service. Now Put this script (say school_service.php) in to the Apache web directory and access it using a browser with the following url.
<pre>http://localhost//school_service.php/subjects</pre>
<p>If you have done every thing right, you should see a nice xml showing your data. Note that here we used REST interface to test our service. You don&#8217;t need to do any thing special to expose it as SOAP. Its SOAP endpoint would be simply</p>
<pre>http://localhost//school_service.php</pre>
</li>
</ul>
<p><strong>Get the WSDL Generation working with MSSQL</strong><br />
If you try to retrieve the WSDL for the above service using this URL</p>
<pre>http://localhost//school_service.php?wsdl</pre>
<p>You will get an error message saying that the meta data retrieval is not supported for this particular driver (MSSQL Driver). For the time being, in order to get rid of this warning you have to disable showing warnings in your PHP programs. You can get it done by editing the php.ini with this entry</p>
<pre>error_reporting = E_ALL &amp; ~E_NOTICE &amp; ~E_WARNING</pre>
<p>But even with this fix, the schema types of the name and teacher entries will be shown as &#8220;xsd:anyType&#8221;. If you want to have a more specific type associated with them, Just change the $output_format variable to the following.</p>
<pre class="php"><span style="color: #0000ff;">$output_format</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span>
                    <span style="color: #ff0000;">"resultElement"</span> =&gt; <span style="color: #ff0000;">"subjects"</span>,
                    <span style="color: #ff0000;">"rowElement"</span> =&gt; <span style="color: #ff0000;">"subject"</span>,
		<span style="color: #ff0000;">    "elements"</span> =&gt; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span>
			<span style="color: #ff0000;">"name"</span> =&gt; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"column"</span> =&gt; <span style="color: #ff0000;">"subjectName"</span>, <span style="color: #ff0000;">"xsdType"</span> =&gt; <span style="color: #ff0000;">"xsd:string"</span><span style="color: #66cc66;">)</span>,
			<span style="color: #ff0000;">"teacher"</span> =&gt; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"column"</span> =&gt; <span style="color: #ff0000;">"subjectTeacher"</span>, <span style="color: #ff0000;">"xsdType"</span> =&gt; <span style="color: #ff0000;">"xsd:string"</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;</pre>
<p>Here instead of giving a string to &#8216;teacher&#8217; and &#8216;name&#8217; entries, we give an array containing both column name and the the custom xsd type we want to appear in the WSDL.  Note that this fix is needed only for databases that doesn&#8217;t provide the meta data interface through the PHP PDO layer. For database like mysql wsdl generation works straight away.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/10/04/mssqlmicrosoft-sql-data-services-in-php/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>WSDL2PHP 2 Minutes Introduction</title>
		<link>http://www.dimuthu.org/blog/2008/09/21/wsdl2php-2-minutes-introduction/</link>
		<comments>http://www.dimuthu.org/blog/2008/09/21/wsdl2php-2-minutes-introduction/#comments</comments>
		<pubDate>Sun, 21 Sep 2008 17:54:43 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[2 minutes guide]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[WSDL]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[xml schema]]></category>
		<category><![CDATA[2 minutes]]></category>
		<category><![CDATA[client]]></category>
		<category><![CDATA[consumers]]></category>
		<category><![CDATA[guide]]></category>
		<category><![CDATA[WSClient]]></category>
		<category><![CDATA[wsdl2php]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=349</guid>
		<description><![CDATA[WSDL2PHP makes the development of web service providers and consumers quick and easy. I wrote a 2 minutes guide on developing web services providers sometimes ago. So lets concentrate on developing web service consumers here. Where is WSDL2PHP? WSDL2PHP script is included in the WSF/PHP packs. You can find the wsdl2php.php script inside the &#8216;scripts&#8217; [...]]]></description>
			<content:encoded><![CDATA[<p>WSDL2PHP makes the development of web service providers and consumers quick and easy. I wrote a <a href="http://www.dimuthu.org/blog/2008/09/08/developing-wsfphp-webservices-with-contract-first-approach-2-minutes-introduction/">2 minutes guide on developing web services providers</a> sometimes ago. So lets concentrate on developing web service consumers here.</p>
<p><strong>Where is WSDL2PHP?</strong></p>
<p>WSDL2PHP script is included in the <a href="http://wso2.org/downloads/wsf/php">WSF/PHP packs</a>. You can find the wsdl2php.php script inside the &#8216;scripts&#8217; directory of any source or binary package. Or you can use the <a title="online wsdl2php tool" href="http://labs.wso2.org/wsf/php/wsdl2phptool.php">online wsd2php tool</a> hosted in <a title="WSF/PHP Demo Site" href="http://labs.wso2.org/wsf/php">WSF/PHP web services DEMO Site</a>.</p>
<p><strong>How to Run the Script?</strong></p>
<p>Here is the command</p>
<pre>/scripts/wsdl2php.php mywsdl.wsdl &gt; myclient.php</pre>
<p><strong>The Code is Generated. How Can I add My Code There?</strong></p>
<p>It is simple. Just search for the comment &#8220;//TODO&#8221;.<br />
Check for an example <a href="http://labs.wso2.org/wsf/php/wsdl2phptool.php?wsdl_url=http%3A%2F%2Flabs.wso2.org%2Fwsf%2Fphp%2Fexample.wsdl&amp;generate_type=client">here</a>.</p>
<p>You have to write custom code for 2 occasions per operation.</p>
<ol>
<li>To Provide Input Parameters</li>
<li>To Handle output parameters.</li>
</ol>
<p><strong>An Example?</strong></p>
<p>Here is the code snippet corresponding to the simpleAdd request for our <a title="Demo WSDL" href="http://labs.wso2.org/wsf/php/example.wsdl">demo WSDL</a>.</p>
<pre class="php">    <span style="color: #0000ff;">$input</span> = <span style="font-weight: bold; color: #000000;">new</span> simpleAdd<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;
    <span style="font-style: italic; color: #808080;">//TODO: fill in the class fields of $input to match your business logic</span>

    <span style="font-style: italic; color: #808080;">// call the operation</span>
    <span style="color: #0000ff;">$response</span> = <span style="color: #0000ff;">$proxy</span>-&gt;<span style="color: #006600;">simpleAdd</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$input</span><span style="color: #66cc66;">)</span>;
    <span style="font-style: italic; color: #808080;">//TODO: Implement business logic to consume $response, which is of type simpleAddResponse</span></pre>
<p>Here is how after I filled my logic in place of TODO comments.</p>
<pre class="php">    <span style="color: #0000ff;">$input</span> = <span style="font-weight: bold; color: #000000;">new</span> simpleAdd<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;
    <span style="font-style: italic; color: #808080;">//DONE: fill in the class fields of $input to match your business logic</span>

    <span style="font-style: italic; color: #808080;">//-------my code----</span>
    <span style="color: #0000ff;">$input</span>-&gt;<span style="color: #006600;">param0</span> = <span style="color: #cc66cc;">2</span>;
    <span style="color: #0000ff;">$input</span>-&gt;<span style="color: #006600;">param1</span> = <span style="color: #cc66cc;">3</span>;
    <span style="font-style: italic; color: #808080;">//------------------</span>

    <span style="font-style: italic; color: #808080;">// call the operation</span>
    <span style="color: #0000ff;">$response</span> = <span style="color: #0000ff;">$proxy</span>-&gt;<span style="color: #006600;">simpleAdd</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$input</span><span style="color: #66cc66;">)</span>;
    <span style="font-style: italic; color: #808080;">//DONE: Implement business logic to consume $response, which is of type simpleAddResponse</span>

    <span style="font-style: italic; color: #808080;">//--------my code-----</span>
    <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #0000ff;">$response</span>-&gt;<span style="color: #006600;">return</span>;
    <span style="font-style: italic; color: #808080;">//--------------------</span></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/09/21/wsdl2php-2-minutes-introduction/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>Axis2/C ADB 2 Minutes Introduction</title>
		<link>http://www.dimuthu.org/blog/2008/09/03/axis2c-adb-2-minitue-introduction/</link>
		<comments>http://www.dimuthu.org/blog/2008/09/03/axis2c-adb-2-minitue-introduction/#comments</comments>
		<pubDate>Wed, 03 Sep 2008 14:14:27 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[2 minutes guide]]></category>
		<category><![CDATA[adb]]></category>
		<category><![CDATA[axis2/c]]></category>
		<category><![CDATA[codegen]]></category>
		<category><![CDATA[tool]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[WSDL]]></category>
		<category><![CDATA[wsdl2c]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[xml schema]]></category>
		<category><![CDATA[2 minutes]]></category>
		<category><![CDATA[guide]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=204</guid>
		<description><![CDATA[Building and Traversing XML are regular tasks for any Web Service developer. We may use DOM, AXIOM or even simple String manipulation functions to do that. Normally this takes a lot of time and effort. And if we are coding in &#8216;C&#8217; it become more tedious as string manipulation in &#8216;C&#8217; is not that straight [...]]]></description>
			<content:encoded><![CDATA[<p>Building and Traversing XML are regular tasks for any Web Service developer. We may use DOM, AXIOM or even simple String manipulation functions to do that. Normally this takes a lot of time and effort. And if we are coding in &#8216;C&#8217; it become more tedious as string manipulation in &#8216;C&#8217; is not that straight forward.</p>
<p>What ADB does is it generates a set of &#8216;C&#8217; functions specially for our XML Schema to build and traverse the XML.<br />
Say you have the following XML Schema. (You need to have it inside a WSDL to generate the code).</p>
<pre>        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:schema</span> <span style="color: #000066;">targetNamespace</span>=<span style="color: #ff0000;">"http://dimuthu.org/adb/demo/2008/sept"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
            <span style="color: #009900;"><span style="font-style: italic; color: #808080;">&lt;!-- demonstrating element--&gt;</span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"myDemo"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
                <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:complexType<span style="font-weight: bold; color: black;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:sequence<span style="font-weight: bold; color: black;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"demo1"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"xs:int"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
                        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"demo2"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"xs:string"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
                    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xs:sequence<span style="font-weight: bold; color: black;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xs:complexType<span style="font-weight: bold; color: black;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xs:element<span style="font-weight: bold; color: black;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:schema</span><span style="font-weight: bold; color: black;">/&gt;</span></span></pre>
<p>For this particular element there will be one adb type (adb_myDemo_t), one source (adb_myDemo.c) and one header (adb_myDemo.h) are generated. Don&#8217;t ever look at the source file (unless you want to hack it) just go through the header, it will have all the function you need to manipulate your ADB.</p>
<p>It will have following set of functions,</p>
<pre>To create and free the object
<ul>
<li>adb_myDemo_create</li>
<li>adb_myDemo_free</li>
</ul>

Getters and Setters to manipulate Data
<ul>
<li>adb_myDemo_get_demo1</li>
<li>adb_myDemo_set_demo1</li>
<li>adb_myDemo_get_demo2</li>
<li>adb_myDemo_set_demo2</li>
</ul>

Build and Parse XML
<ul>
<li>adb_myDemo_serialize</li>
<li>adb_myDemo_deserialize</li>
</ul>
</pre>
<p>First we will check how to build a simple XML using an ADB object.</p>
<pre>    adb_myDemo_t *mydemo = adb_myDemo_create<span style="color: #66cc66;">(</span>env<span style="color: #66cc66;">)</span>;
    adb_myDemo_set_demo1<span style="color: #66cc66;">(</span>mydemo, env, <span style="color: #cc66cc;">3</span><span style="color: #66cc66;">)</span>; <span style="font-style: italic; color: #808080;">/* some arbitrary value */</span>
    adb_myDemo_set_demo2<span style="color: #66cc66;">(</span>mydemo, env, <span style="color: #ff0000;">"some arbitrary string"</span><span style="color: #66cc66;">)</span>;
    axiom_t *xml = adb_myDemo_serialize<span style="color: #66cc66;">(</span>mydemo, env, <span style="font-weight: bold; color: #000000;">NULL</span>, <span style="font-weight: bold; color: #000000;">NULL</span>, AXIS2_TRUE, <span style="font-weight: bold; color: #000000;">NULL</span>, <span style="font-weight: bold; color: #000000;">NULL</span><span style="color: #66cc66;">)</span>;</pre>
<p>So now we have the AXIOM representation of the XML which we just build using ADB.</p>
<pre><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ns0:myDemo</span> xmlns:ns0=<span style="color: #ff0000;">"http://dimuthu.org/adb/demo/2008/sept"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ns0:demo1<span style="font-weight: bold; color: black;">&gt;</span></span></span>3<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/ns0:demo1<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ns0:demo2<span style="font-weight: bold; color: black;">&gt;</span></span></span>some arbitrary string<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/ns0:demo2<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/ns0:myDemo<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>Anyway ADB is easier when you want to navigate through an XML. (you can read data randomly as you preferred). Here we starting from the AXIOM representation of our XML.</p>
<pre>      adb_myDemo_t *mydemo= adb_myDemo_create<span style="color: #66cc66;">(</span> env<span style="color: #66cc66;">)</span>;
      adb_myDemo_deserialize<span style="color: #66cc66;">(</span>mydemo, env, &amp;xml, <span style="font-weight: bold; color: #000000;">NULL</span>, AXIS2_FALSE<span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>
      <span style="color: #993333;">int</span> demo1 = adb_myDemo_get_demo1<span style="color: #66cc66;">(</span>mydemo, env<span style="color: #66cc66;">)</span>;
      <a href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html"><span style="color: #000066;">printf</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"My Demo1 is: %d<span style="font-weight: bold; color: #000099;">\\</span>n"</span>, demo1<span style="color: #66cc66;">)</span>;
      axis2_char_t *demo2 = adb_myDemo_get_demo2<span style="color: #66cc66;">(</span>mydemo, env<span style="color: #66cc66;">)</span>;
      <a href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html"><span style="color: #000066;">printf</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"My Demo2 is: %s<span style="font-weight: bold; color: #000099;">\\</span>n"</span>, demo2<span style="color: #66cc66;">)</span>;</pre>
<p>I have printed the Data contained in the XML with the help of ADB objects.</p>
<p>In ordre to download the Codegen tool with ADB you have to download the <a href="http://ws.apache.org/axis2/download.cgi">Axis2/Java package</a>.</p>
<p>If you want to learn more about ADB, Just go through <a href="http://www.dimuthu.org/blog/2008/07/21/axis2c-adb-codegen-wsdl2c-tutorial-resources/">more Axis2/C Codegen / ADB resources </a>which I have blogged few weeks ago.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/09/03/axis2c-adb-2-minitue-introduction/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Install PHP, WSF/PHP and DataServices in a Shared Hosting Environment</title>
		<link>http://www.dimuthu.org/blog/2008/08/16/install-php-wsfphp-and-dataservices-in-a-shared-hosting-environment/</link>
		<comments>http://www.dimuthu.org/blog/2008/08/16/install-php-wsfphp-and-dataservices-in-a-shared-hosting-environment/#comments</comments>
		<pubDate>Sat, 16 Aug 2008 07:55:00 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[DataServices]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[cgi]]></category>
		<category><![CDATA[data services]]></category>
		<category><![CDATA[DataService]]></category>
		<category><![CDATA[dreamhost]]></category>
		<category><![CDATA[fastcgi]]></category>
		<category><![CDATA[guide]]></category>
		<category><![CDATA[install]]></category>
		<category><![CDATA[lamp]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php.cgi]]></category>
		<category><![CDATA[php.ini]]></category>
		<category><![CDATA[Shared hosting environment]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=123</guid>
		<description><![CDATA[If you have a shared hosting environment you will find it is not straight forward to install WSO2 WSF/PHP + PHP DataServices Library since you have very limited authority on your environment. Here in this post, I&#8217;m explaining the steps I followed in setting up my custom PHP, WSF/PHP Extension and DataServices library for http://ws.dimuthu.org [...]]]></description>
			<content:encoded><![CDATA[<p>If you have a shared hosting environment you will find it is not straight forward to install <a href="http://wso2.org/projects/wsf/php">WSO2 WSF/PHP</a> + <a href="http://labs.wso2.org/wsf/php/resource_view.php?url=DataServices">PHP DataServices Library</a> since you have very limited authority on your environment. Here in this post, I&#8217;m explaining the steps I followed in setting up my custom PHP, WSF/PHP Extension and DataServices library for <a href="http://ws.dimuthu.org">http://ws.dimuthu.org</a> (This is a shared hosting environment from <a href="http://dreamhost.com">dreamhost</a> based on LAMP stack) which I&#8217;m using to expose my blog as a WebService.</p>
<p><strong>Prerequisites:</strong></p>
<ol>
<li>You should be able to run PHP using mod_fastcgi (not using mod_php) in Apache. That allows you to configure your own php environment.</li>
<li>The server configurations managed by the hosting service should allow you to handle .php extension from your own  CGI executable (here it is php.cgi), If not, you can still try with setting some other extension (say .phq or .qhq, anything not .php) to be handled by your php-cgi. Anyway if your hosting service allow you to run CGI then most probably you have this permission.</li>
<li>You should have the access to the shell (using SSH) and should be able to use development libraries(libxml, libxsl, libopenssl) + build tools (make)</li>
<li>There can be some other restrictions that your hosting service has put on you, that I have not experienced with my hosting service. So please check your hosting service support and documentation for possibility of building your own PHP environment.</li>
</ol>
<p><strong>Install PHP:</strong></p>
<p>I have extracted out most of the steps from <a href="http://wiki.dreamhost.com/Custom_PHP.ini">dreamhost documentation on custom php.ini.</a></p>
<ol>
<li> <a href="http://php.net">Download PHP</a> and compile. You should at least enable &#8211;enable-fastcgi &#8211;enable-force-cgi-redirect in the configuration.
<pre>./configure --enable-fastcgi --enable-force-cgi-redirect --with-xsl --with-openssl --prefix=`pwd`/dist
make
make install</pre>
<p>Note: from here on, php source directory is referred as &lt;php_source_directory&gt;<br />
I have installed the php to &lt;php_source_directory&gt;/dist since we mostly don&#8217;t have permission to install it in to default location. (/usr/local). From here on I will be referring php installation directory as &lt;php_install_dir&gt;</li>
<li>create a directory called &#8216;cgi-bin&#8217; to your web document root directory(&lt;document_root_directory&gt;) and copy the &lt;php_source_directory&gt;/dist/bin/php-cgi in to that. (before php version 5.2.1 there is no php-cgi generated, you can just copy the php to the cgi-bin directory). And rename the php-cgi to php.cgi.
<pre>cp &lt;php_install_direcory&gt;/bin/php-cgi &lt;document_root_directory&gt;/cgi-bin/php.cgi</pre>
</li>
<li>copy &lt;php_source_direcory/php.ini-dist to the cgi-bin directory and rename it as php.ini, this can be used to configure your php environment.
<pre>cp &lt;php_source_directory/php.ini-dist &lt;document_root_directory&gt;/cgi-bin/php.ini</pre>
</li>
<li>Create .htaccess file in the cgi-bin directory to allow the access to php-cgi and php.ini files.
<pre><span style="font-weight: bold; color: #c20cb9;">cat</span> &lt;&lt; EOF &gt;&lt;document_root_directory&gt;/cgi-bin/.htaccess
Options +ExecCGI -Indexes +FollowSymLinks
&lt;FilesMatch <span style="color: #ff0000;">"php(.?)<span style="font-weight: bold; color: #000099;">\\</span>.(cgi|ini)$"</span>&gt;
Order Deny,Allow
Deny from All
Allow from <span style="color: #007800;">env=</span>REDIRECT_STATUS
&lt;/FilesMatch&gt;

EOF</pre>
</li>
<li>Create .htaccess file in the root directory redirect all the requests for .php extensions to go through our php-cgi.
<pre><span style="font-weight: bold; color: #c20cb9;">cat</span> &lt;&lt; EOF &gt; &lt;document_root_directory&gt;/.htaccess
AddHandler php-cgi .php
Action php-cgi /cgi-bin/php.cgi
EOF</pre>
<p>If your hosting service doesn&#8217;t allow to handle .php just rename the end of the first line to some other extension.</li>
<li>Check the necessary permissions levels in files.
<pre>chmod 644 &lt;document_root_directory&gt;/.htaccess
chmod 755 &lt;document_root_directory&gt;/cgi-bin
chmod 644 &lt;document_root_directory&gt;/cgi-bin/.htaccess
chmod 644 &lt;document_root_directory&gt;/cgi-bin/php.ini
chmod 755 &lt;document_root_directory&gt;/cgi-bin/php.cgi</pre>
</li>
</ol>
<p>That&#8217;s it. Now your .php files should be run on your own php environment. Just to check whether it is working or not create a phpinfo() file.</p>
<pre><span style="font-weight: bold; color: #c20cb9;">cat</span> &lt;&lt;EOF &gt; phpinfo.php
&lt;?php
phpinfo<span style="font-weight: bold; color: #7a0874;">(</span><span style="font-weight: bold; color: #7a0874;">)</span>;
?&gt;
EOF</pre>
<p>And go to the http://yourdoman.com/phpinfo.php and verify that it is your custom php environment .</p>
<p><strong>Installing WSF/PHP</strong></p>
<ol>
<li><a href="http://wso2.org/downloads/wsf/php">Download WSF/PHP latest version</a> and extract it to any of your preferred directory(&lt;wsf_php_source_directory&gt;).</li>
<li>Set the PATH environment variable to search for your custom php installation first.</li>
<pre>export PATH=&lt;php_install_dir&gt;/bin:$PATH</pre>
<li>From the same shell go to the &lt;wsf_php_source_directory&gt; and compile it.
<pre>./configure
make
make install</pre>
</li>
<li>Now check where you have installed wsf/php. it is in fact the extension dir shown by the php-config command.
<pre>php-config --extension-dir</pre>
<p>I will refer this directory as &lt;php_extension_directory&gt;</li>
<li>Open the &lt;document_root_directory&gt;/cgi-bin/php.ini an set the extension directory, enable wsf extension and set the include path to the wsf scripts directory.cat &lt;&lt;EOF &gt;&gt; &lt;wsf_php_source_directory&gt;/cgi-bin/php.ini
<pre><span style="font-weight: bold; color: #c20cb9;">cat</span> &lt;&lt;EOF &gt;&gt; &lt;wsf_php_source_directory&gt;/cgi-bin/php.ini
<span style="color: #007800;">extension_dir=</span>&lt;php_extension_directory&gt;
<span style="color: #007800;">extension=</span>wsf.so
<span style="color: #007800;">include_path=</span><span style="color: #ff0000;">".:&lt;wsf_php_source_directory&gt;/scripts"</span>

EOF</pre>
<p>If you found that you can only put relative directories in your php.ini (that happens when you don&#8217;t even have the read access to your root directory &#8216;/&#8217;), follow the workaround mentioned in here, <a href="http://phpwebservices.blogspot.com/2008/08/installing-wsfphp-in-third-party.html">http://phpwebservices.blogspot.com/2008/08/installing-wsfphp-in-third-party.html</a></li>
</ol>
<p>That&#8217;s all. Just check the phpinfo (created earlier section) whether your configurations and the wsf extension are loaded correctly. In order to test the functionality copy the wsf/php samples to the web document root and access them from the browser. Go to each sample and verify they function as expected.</p>
<pre>cp /samples &lt;wsf_php_source_directory&gt;/ -R</pre>
<p>And go to http://yourdomain.com/samples and click on each samples. If this not working most probably your localhost to ip mapping is wrong, most probably this problem is there in your shared host. Just go to the samples directory and change the endpoint to the domain name in place of &#8216;localhost&#8217; in each client and try it again.</p>
<p><strong>Installing PHP DataServices</strong>:</p>
<ol>
<li><a href="http://labs.wso2.org/wsf/php/resource_view.php?url=DataServices">Download and unpack PHP DataServices</a>. &lt;php_data_services_directory&gt;</li>
<li>Update the include_path entry in php.ini to DataServices libraries directory as well. So the &lt;wsf_php_source_directory&gt;/cgi-bin/php.ini  file now has the following entry.
<pre>include_path=".:&lt;wsf_php_source_directory&gt;/scripts:&lt;php_data_services_directory&gt;/lib"</pre>
</li>
</ol>
<p>That&#8217; all for the DataService installation. Please read &lt;php_data_services_directory&gt;/README to run the samples. Anyway if you are sure you did followed these simple steps correctly, go on with your DataService  development. Specially if you have wordpress database, you may start straight away with<a href="http://www.dimuthu.org/blog/2008/08/11/make-your-wordpress-blog-a-web-service-in-few-step/"> the making wordpress a DataService</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/08/16/install-php-wsfphp-and-dataservices-in-a-shared-hosting-environment/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Make your WordPress Blog a Web Service in Few Steps</title>
		<link>http://www.dimuthu.org/blog/2008/08/11/make-your-wordpress-blog-a-web-service-in-few-step/</link>
		<comments>http://www.dimuthu.org/blog/2008/08/11/make-your-wordpress-blog-a-web-service-in-few-step/#comments</comments>
		<pubDate>Mon, 11 Aug 2008 03:03:35 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[DataServices]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[blog]]></category>
		<category><![CDATA[data services]]></category>
		<category><![CDATA[DataService]]></category>
		<category><![CDATA[guide]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Steps]]></category>
		<category><![CDATA[Web Service]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=90</guid>
		<description><![CDATA[With PHP DataServices it is just a matter of putting a little configuration php file to make your database available as a web service. I only needed few minutes to make a simple web service from my blog after figuring out my wordpress database structure, http://wpbits.wordpress.com/2007/08/08/a-look-inside-the-wordpress-database/. In this guide, I m exposing the title, date [...]]]></description>
			<content:encoded><![CDATA[<p>With PHP DataServices it is just a matter of putting a little configuration php file to make your database available as a web service. I only needed few minutes to make a simple web service from my blog after figuring out my wordpress database structure, <a href="http://wpbits.wordpress.com/2007/08/08/a-look-inside-the-wordpress-database/">http://wpbits.wordpress.com/2007/08/08/a-look-inside-the-wordpress-database/.</a> In this guide, I m exposing the title, date and the content of each of my blog for my service, But you can extend this more the way you prefer.</p>
<ol>
<li>Download and install <a href="http://wso2.org/downloads/wsf/php">WSF/PHP 1.3.2</a> and <a href="http://labs.wso2.org/wsf/php/downloads/DataServices/DataServices.zip">PHP Data Services Library.</a> If WSF/PHP 2.0 released by the time you are reading this, (it is to be released in this week), you only need to install WSF/PHP, since the DataServices library is packed with WSF/PHP from 2.0.</li>
<li>Drop the following file (Say WordPressService.php) in to any of your web server document directories.
<pre><span style="font-weight: bold; color: #000000;">&lt;?php</span>

<span style="font-style: italic; color: #808080;">// Make sure you put the DataService.php in your include path</span>
<span style="color: #b1b100;">require_once</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"wso2/DataServices/DataService.php"</span><span style="color: #66cc66;">)</span>;

<span style="font-style: italic; color: #808080;">// database configuraitons</span>
<span style="font-style: italic; color: #808080;">// you have to set your database configurations in here..</span>
<span style="font-style: italic; color: #808080;">// These entries can be copy and past from the wp-config.php in your wordpress installation</span>

<span style="color: #0000ff;">$config</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span>
<span style="color: #ff0000;">"db"</span> =&gt; <span style="color: #ff0000;">"mysql"</span>,
<span style="color: #ff0000;">"username"</span>=&gt;DB_USER,
<span style="color: #ff0000;">"password"</span>=&gt; DB_PASSWORD,
<span style="color: #ff0000;">"dbname"</span>=&gt;DB_NAME,
<span style="color: #ff0000;">"dbhost"</span>=&gt;DB_HOST<span style="color: #66cc66;">)</span>;
<span style="font-style: italic; color: #808080;">// output format, plese check the API from http://wso2.org/wiki/display/wsfphp/API+for+Data+Services+Revised</span>
<span style="color: #0000ff;">$outputFormat</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"resultElement"</span> =&gt; <span style="color: #ff0000;">"Posts"</span>,
<span style="color: #ff0000;">"rowElement"</span> =&gt; <span style="color: #ff0000;">"post"</span>,
<span style="color: #ff0000;">"elements"</span> =&gt; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span> <span style="color: #ff0000;">"title"</span> =&gt; <span style="color: #ff0000;">"post_title"</span>,
<span style="color: #ff0000;">"content"</span> =&gt; <span style="color: #ff0000;">"post_content"</span>,
<span style="color: #ff0000;">"date"</span> =&gt; <span style="color: #ff0000;">"post_date"</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;

<span style="font-style: italic; color: #808080;">// sql statment to execute, note that I assume the table prefix is wp_ (so the table name is wp_posts)</span>
<span style="font-style: italic; color: #808080;">// just check $table_prefix variable in the wp-config.php of your wordpress installation</span>
<span style="color: #0000ff;">$sql</span>=<span style="color: #ff0000;">"select post_title, post_content, post_date from wp_posts where post_status='published'"</span>;

<span style="font-style: italic; color: #808080;">// operations is consist of inputFormat (optional), outputFormat(required), sql(sql), input_mapping(optional)</span>
<span style="color: #0000ff;">$operations</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"getPosts"</span>=&gt;array<span style="color: #66cc66;">(</span><span style="color: #ff0000;">"outputFormat"</span>=&gt;<span style="color: #0000ff;">$outputFormat</span>, <span style="color: #ff0000;">"sql"</span>=&gt;<span style="color: #0000ff;">$sql</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;
<span style="color: #0000ff;">$my_data_service</span> = <span style="font-weight: bold; color: #000000;">new</span> DataService<span style="color: #66cc66;">(</span><a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"config"</span>=&gt;<span style="color: #0000ff;">$config</span>,<span style="color: #ff0000;">"operations"</span>=&gt;<span style="color: #0000ff;">$operations</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;

<span style="color: #0000ff;">$my_data_service</span>-&gt;<span style="color: #006600;">reply</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;
<span style="font-weight: bold; color: #000000;">?&gt;</span></pre>
</li>
<li>It is all. Just access the above file from a web browser, you see your service is hosted. Here is the endpoint for my service. <a href="http://ws.dimuthu.org/blog/WordpressService.php">http://ws.dimuthu.org/blog/WordpressService.php</a>. Since I m using WSF/PHP latest svn, I m able to retrieve the wsdl automatically from <a href="http://ws.dimuthu.org/blog/WordpressService.php?wsdl">http://ws.dimuthu.org/blog/WordpressService.php?wsdl</a>. Please wait for WSF/PHP 2.0 release for ?wsdl feature.</li>
<li>To verify whether your service deployed correctly, you may need to write a simple test client. Yea I too wrote one. Since I have the wsdl generated, I just needed to generate the code for the client from the wsdl using wsdl2php tool. There is an online version of the tool in the wsf/php demo site. Here is the generated code for my client, <a href="http://labs.wso2.org/wsf/php/wsdl2phptool.php?wsdl_url=http%3A%2F%2Fws.dimuthu.org%2Fblog%2FWordpressService.php%3Fwsdl">http://labs.wso2.org/wsf/php/wsdl2phptool.php?wsdl_url=http%3A%2F%2Fws.dimuthu.org%2Fblog%2FWordpressService.php%3Fwsdl</a>. I added the following code to the TODO section in handling response,
<pre>    <span style="color: #b1b100;">if</span><span style="color: #66cc66;">(</span><a href="http://www.php.net/is_array"><span style="color: #000066;">is_array</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$response</span>-&gt;<span style="color: #006600;">post</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>
        <span style="color: #b1b100;">foreach</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$response</span>-&gt;<span style="color: #006600;">post</span> <span style="color: #b1b100;">as</span> <span style="color: #0000ff;">$post</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>

            <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">"&lt;h2&gt;"</span>.<span style="color: #0000ff;">$post</span>-&gt;<span style="color: #006600;">title</span> . <span style="color: #ff0000;">" - "</span>.<span style="color: #0000ff;">$post</span>-&gt;<span style="color: #006600;">date</span>.<span style="color: #ff0000;">"&lt;/h2&gt;"</span>;
            <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">"&lt;p&gt;"</span>;
            <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #0000ff;">$post</span>-&gt;<span style="color: #006600;">content</span>;
            <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">"&lt;/p&gt;"</span>;

            <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">"&lt;hr/&gt;"</span>;
        <span style="color: #66cc66;">}</span>
    <span style="color: #66cc66;">}</span></pre>
<p>Check my Web Service client for the above service here, <a href="http://ws.dimuthu.org/blog/WordpressClient.php">http://ws.dimuthu.org/blog/WordpressClient.php</a>.</li>
</ol>
<p>Now I can call for my blog from any web service enabled platform.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/08/11/make-your-wordpress-blog-a-web-service-in-few-step/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Nested Queries with PHP Data Services</title>
		<link>http://www.dimuthu.org/blog/2008/08/04/nested-queries-with-php-data-services/</link>
		<comments>http://www.dimuthu.org/blog/2008/08/04/nested-queries-with-php-data-services/#comments</comments>
		<pubDate>Mon, 04 Aug 2008 19:33:46 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[DataServices]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[data services]]></category>
		<category><![CDATA[DataService]]></category>
		<category><![CDATA[guide]]></category>
		<category><![CDATA[nested queires]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=78</guid>
		<description><![CDATA[We use the term &#8216;DataService&#8217; when we expose a database as a web service. WSO2 has a separate product for the DataService space which was earlier shipped bundled with WSAS. There you write a configuration xml explaining what data to be exposed in your database and drop it in the WSAS java app server and [...]]]></description>
			<content:encoded><![CDATA[<p>We use the term &#8216;DataService&#8217; when we expose a database as a web service. WSO2 has a <a href="http://wso2.org/projects/solutions/data-services/java">separate product</a> for the DataService space which was earlier shipped bundled with WSAS. There you write a configuration xml explaining what data to be exposed in your database and drop it in the WSAS java app server and you get the DataServices deployed without much effort. Couple of months ago we published <a href="http://labs.wso2.org/wsf/php/resource_view.php?url=DataServices">PHP DataServices</a> library that allow you do deploy Your DataService within a popular LAMP or WAMP stack. With the WSF/PHP 2.0.0 release, you can have the PHP DataService library bundled with the release, hopefully within next couple of weeks.</p>
<p>One of the main problem DataService developers face is how to design an elegant web service API that will provide the requested information from a row database straightaway. Because when we normalize a database, the very closely related data are spread in different tables just keeping the association with foreign keys. So in order to retrieve the useful information database developers have to write multiple queries to the database. Is that same with DataServices?, Do you have to write multiple web service requests to return some useful data?</p>
<p>No. You don&#8217;t. You have Nested Queries to save you. With nested queries you can configure your DataServices, so all the relevent information can be extracted and send as a single SOAP message. I will take a demonstration to explain this.</p>
<p>Say you are working for a company that manufacture or sell electrical equipments, say TVs. And your boss is asking you to prepare a whole list of customers who ordered good from them. He want order information (like order date, status of the order) plus the name of the customers in the list.</p>
<p>Here is the table structure that you have.<br />
<strong>Orders</strong></p>
<table border="1" width="300">
<tbody>
<tr>
<td>ORDERNUMBER</td>
<td>ORDERDATE</td>
<td>STATUS</td>
<td>CUSTOMERID</td>
</tr>
</tbody>
</table>
<p><strong>Customers</strong></p>
<table border="1" width="300">
<tbody>
<tr>
<td>CUSTOMERID</td>
<td>CUSTOMERNAME</td>
</tr>
</tbody>
</table>
<p>From this you have to find a list of orders with order date, status (available in Orders table) and ordered customer information available in Customers table. As you may seen you have to query both the tables to get the required data.</p>
<p>First you have to decide a service operation that you going to expose as a web service. Operation is uniquely identified by its name. We will give our operation the name &#8220;getOrders&#8221;. In fact in our PHP Data Service API we treat a Operation same as a query. In general operation/query has following properties associated with it. Note for the complete API please check <a href="http://wso2.org/wiki/display/wsfphp/API+for+Data+Services+Revised">this Oxygen Tank Page</a>.<br />
<strong>Properties of Data Service Operation/Query</strong></p>
<table border="1" width="100%">
<tbody>
<tr>
<td>inputFormat</td>
<td>This is the map of input element or input parameter to the corresponding type. For our operation there is no input. So we are not setting it here.</td>
</tr>
<tr>
<td>outputFormat</td>
<td>This is a little tricky option. You have to set several configuration under this.</p>
<table border="1">
<tbody>
<tr>
<td>resultElement</td>
<td>The name of the wrapper response element. We will give the name &#8220;<em>Orders</em>&#8221; here.</td>
</tr>
<tr>
<td>rowElement</td>
<td>The name we give to wrap the each row of the result. If we give this value something like &#8220;<em>Order</em>&#8220;, then the result xml will be like,</p>
<pre><span><span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;orders</span></span></span></span><span style="font-weight: bold; color: black;">&gt;</span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;order<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    order 1 details
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/order<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;order<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    next order details
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/order<span style="font-weight: bold; color: black;">&gt;</span></span></span>

  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;order<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    etc
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/order<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/orders<span style="font-weight: bold; color: black;">&gt;</span>
</span></span></pre>
</td>
</tr>
<tr>
<td>elements</td>
<td>The name of elements that is going to be in the response XML map to the real names of columns in the actual query result.<br />
For an example if I give this the following value.</p>
<pre><span style="color: #000066;">array</span><span style="color: #66cc66;">(</span><span><span style="color: #ff0000;"><span style="font-weight: bold; color: #000099;">"</span></span></span><span style="color: #ff0000;">Order_number<span style="font-weight: bold; color: #000099;">"</span> =&gt; <span style="font-weight: bold; color: #000099;">"</span>ORDERNUMBER<span style="font-weight: bold; color: #000099;">"</span>,
      <span style="font-weight: bold; color: #000099;">"</span>Order_date<span style="font-weight: bold; color: #000099;">"</span> =&gt; <span style="font-weight: bold; color: #000099;">"</span>ORDERDATE<span style="font-weight: bold; color: #000099;">"</span>,
      <span style="font-weight: bold; color: #000099;">"</span>Status<span style="font-weight: bold; color: #000099;">"</span> =&gt; <span style="font-weight: bold; color: #000099;">"</span>STATUS<span style="font-weight: bold; color: #000099;">"</span>);</span></pre>
<p>The portion of the response will be like this,</p>
<pre><span><span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;order</span></span></span></span><span style="font-weight: bold; color: black;">&gt;</span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;Order_number<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    3
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/Order_number<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;Order_date<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    2008-06-09
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/Order_date<span style="font-weight: bold; color: black;">&gt;</span></span></span>

  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;Status<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    Shipped
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/Status<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/order<span style="font-weight: bold; color: black;">&gt;</span>
</span></span></pre>
</td>
</tr>
<tr>
<td>queries</td>
<td>Array of queries, (The correct term is nested queries). So here you can set the response to be the result of another query. In fact in order to retrieve the customer name for the corresponding order we are going to write a nested query. Just think a operation that take the customerId as a parameter and return the customer data.</p>
<pre>getCustomer<span style="color: #66cc66;">(</span>customerId<span style="color: #66cc66;">)</span></pre>
<p>You have to build this operation/query from the stat as we are just building the &#8216;getOrders&#8217; query</td>
</tr>
<tr>
<td>attributes,  texts, elementsOrder</td>
<td>Some other configuration options. we are not using it in here, but by the name you can have an idea what they are for.</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td>sql</td>
<td>The standard sql query corresponding to the operation. In our case it is</p>
<pre><span style="font-weight: bold; color: #993333;">SELECT</span> o.ORDERNUMBER,o.ORDERDATE, o.<span style="font-weight: bold; color: #993333;">STATUS</span>,o.CUSTOMERNUMBER <span style="font-weight: bold; color: #993333;">FROM</span> ds.Orders o</pre>
</td>
</tr>
<tr>
<td>inputMapping</td>
<td>Finally this describe how the names of the input elements are mapped to the names of input parameters. Since &#8216;getOrders&#8217; operation doesn&#8217;t have input parameters, this is not going to be used in this particular situation.</td>
</tr>
</tbody>
</table>
<p>So as I described in the queries section you have to write the whole thing for the getCustomer operation as well.</p>
<pre><span style="color: #0000ff;">$getCustomer</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span>
    "inputFormat" =&gt; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span>"customerNumber" =&gt; "INTEGER"<span style="color: #66cc66;">)</span>,
    "outputFormat" =&gt; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span>

            "resultElement" =&gt; "Customers",
            "rowElement" =&gt; "Customer",
            "elements" =&gt; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span>"name" =&gt; "CUSTOMERNAME"<span style="color: #66cc66;">)</span>
            <span style="color: #66cc66;">)</span>,
    "sql" =&gt; "select c.CUSTOMERNAME from ds.Customers c where c.CUSTOMERNUMBER = ?",
    "inputMapping" =&gt; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span>"CUSTOMERNUMBER" =&gt; "customerNumber"<span style="color: #66cc66;">)</span>

    <span style="color: #66cc66;">)</span>;</pre>
<p>And here is the getOrders operation/query that actually use the getCustomer as a part of it.</p>
<pre><span style="color: #0000ff;">$getOrders</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span>
    "outputFormat" =&gt; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span>
        "resultElement" =&gt; "Orders",
        "rowElement" =&gt; "Order",
        "elements" =&gt;  <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span>

            "Order_number" =&gt; "ORDERNUMBER",
            "Order_date" =&gt; "ORDERDATE",
            "Status" =&gt; "STATUS"<span style="color: #66cc66;">)</span>,
         "queries" =&gt;  <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$getCustomer</span><span><span style="color: #66cc66;">)
</span></span>  <span style="color: #66cc66;">       )</span>,
    "sql" =&gt; "select c.CUSTOMERNAME from ds.Customers c where c.CUSTOMERNUMBER = ?"
    <span style="color: #66cc66;">)</span>;</pre>
<p>Then we will to define the operations array which we are going feed to the DataService class. Note that now we have two operations <em>getOrders</em> and <em>getCustomer</em>. From that I used getCustomer to help the building of <em>getOrders</em>. And I don&#8217;t want to publish <em>getCustomer</em> as a separate operation. Simply the boss doesn&#8217;t ask for that operation <img src='http://www.dimuthu.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . So my operation map is like this,</p>
<pre><span style="color: #0000ff;">$operations</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span>"getOrders" =&gt; <span style="color: #0000ff;">$getOrders</span><span style="color: #66cc66;">)</span>;</pre>
<p>This operation map will be given as a constructor argument of DataService class. If you are familiar with WSF/PHP WSService class, there is no much different between these two classes. You can give all the options available in the <a href="http://wso2.org/project/wsf/php/1.3.2/docs/api_content.html#service">WSService</a> class to the DataService class. Say you want to encrypt the messages, just use the &#8220;policy&#8221; and the &#8220;securityToken&#8221; options. So with DataService class you have the luxury of using WS-Security as well as WS-Reliable Messaging for free.</p>
<p>To finish this post I will put the complete code for the above scenario. You can check the same service option in action in the  <a href="http://labs.wso2.org/wsf/php/demo.php?name=DataServices&amp;demo=DataServices/samples/demo.php&amp;src=DataServices/">WSF/PHP Demo site</a> (Try the demo4).</p>
<pre><span style="font-weight: bold; color: #000000;">&lt;?php</span>
<span style="font-style: italic; color: #808080;">// include the DataService library.</span>
<span style="font-style: italic; color: #808080;">// NOTE: this path is valid only from wsf/php 2.0.0</span>
<span style="color: #b1b100;">require_once</span><span style="color: #66cc66;">(</span>"wso2/DataServices/DataService.php"<span style="color: #66cc66;">)</span>;

<span style="font-style: italic; color: #808080;">// set the configurations</span>
<span style="color: #0000ff;">$config</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span>"db" =&gt; "<a href="http://www.php.net/mysql"><span style="color: #000066;">mysql"</span></a>,
   "username" =&gt; "dimuthu",
   "password" =&gt; "thiswillnotbeasecretanymore",
   "dbname" =&gt; "ds",
   "dbhost" =&gt; "localhost"<span style="color: #66cc66;">)</span>;

<span style="font-style: italic; color: #808080;">// getCustomer Query - this used by the getOrders query/operation</span>
<span style="color: #0000ff;">$getCustomer</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span>
    "inputFormat" =&gt; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span>"customerNumber" =&gt; "INTEGER"<span style="color: #66cc66;">)</span>,
    "outputFormat" =&gt; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span>

            "resultElement" =&gt; "Customers",
            "rowElement" =&gt; "Customer",
            "elements" =&gt; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span>"name" =&gt; "CUSTOMERNAME"<span style="color: #66cc66;">)</span>
            <span style="color: #66cc66;">)</span>,
    "sql" =&gt; "select c.CUSTOMERNAME from ds.Customers c where c.CUSTOMERNUMBER = ?",
    "inputMapping" =&gt; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span>"CUSTOMERNUMBER" =&gt; "customerNumber"<span style="color: #66cc66;">)</span>

    <span style="color: #66cc66;">)</span>;

<span style="font-style: italic; color: #808080;">// The operation/query getOrders - Read the complete blog to see what </span>
<span style="font-style: italic; color: #808080;">// each of these option stand for</span>
<span style="color: #0000ff;">$getOrders</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span>
    "outputFormat" =&gt; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span>
        "resultElement" =&gt; "Orders",
        "rowElement" =&gt; "Order",
        "elements" =&gt;  <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span>

            "Order_number" =&gt; "ORDERNUMBER",
            "Order_date" =&gt; "ORDERDATE",
            "Status" =&gt; "STATUS"<span style="color: #66cc66;">)</span>,
         "queries" =&gt;  <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$getCustomer</span><span><span style="color: #66cc66;">)
</span></span>  <span style="color: #66cc66;">       )</span>,
    "sql" =&gt; "select c.CUSTOMERNAME from ds.Customers c where c.CUSTOMERNUMBER = ?"
    <span style="color: #66cc66;">)</span>;

<span style="font-style: italic; color: #808080;">// operation array</span>
<span style="color: #0000ff;">$operations</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span>"getOrders" =&gt; <span style="color: #0000ff;">$getOrders</span><span style="color: #66cc66;">)</span>;

<span style="font-style: italic; color: #808080;">// create the DataService object and reply</span>
<span style="color: #0000ff;">$ds</span> = <span style="font-weight: bold; color: #000000;">new</span> DataService<span style="color: #66cc66;">(</span><a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span>"operations" =&gt; <span style="color: #0000ff;">$operations</span>,
          "config" =&gt; <span style="color: #0000ff;">$config</span>,
          "serviceName" =&gt; NextedQuerySample<span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;

<span style="color: #0000ff;">$ds</span>-&gt;<span style="color: #006600;">reply</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;

<span style="font-weight: bold; color: #000000;">?&gt;</span></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/08/04/nested-queries-with-php-data-services/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

