<?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; wsf/php</title>
	<atom:link href="http://www.dimuthu.org/tag/wsfphp/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>WSO2 Web Services Framework for PHP 2.1.0 Released</title>
		<link>http://www.dimuthu.org/blog/2010/07/07/wso2-web-services-framework-for-php-2-1-0-released/</link>
		<comments>http://www.dimuthu.org/blog/2010/07/07/wso2-web-services-framework-for-php-2-1-0-released/#comments</comments>
		<pubDate>Wed, 07 Jul 2010 12:42:52 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[release]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=1099</guid>
		<description><![CDATA[WSO2 just released a newer version of the popular web services framework for php (WSF/PHP). It has lot of bug fixes + performance improvement.  And it now support PHP 5.3. So you can use wsf/php with the latest php version. You can download the new release from http://wso2.org/downloads/wsf/php.]]></description>
			<content:encoded><![CDATA[<p>WSO2 just released a newer version of the popular web services framework for php (WSF/PHP). It has lot of bug fixes + performance improvement.  And it now support PHP 5.3. So you can use wsf/php with the latest php version.</p>
<p>You can download the new release from <a href="http://wso2.org/downloads/wsf/php">http://wso2.org/downloads/wsf/php</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2010/07/07/wso2-web-services-framework-for-php-2-1-0-released/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PHP Web Services: Webinar From WSO2 And Zend</title>
		<link>http://www.dimuthu.org/blog/2010/05/19/php-web-services-webinar-from-wso2-and-zend/</link>
		<comments>http://www.dimuthu.org/blog/2010/05/19/php-web-services-webinar-from-wso2-and-zend/#comments</comments>
		<pubDate>Wed, 19 May 2010 13:30:25 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[SOA]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[webinar]]></category>
		<category><![CDATA[zend]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=1088</guid>
		<description><![CDATA[WSO2 and Zend jointly present a webinar titling &#8220;PHP Web Services: Why You Should Care&#8221; on 26th of May, 2010. The webinar will mainly focus on the following aspects, • Understand Web services development best practices • Discuss Web service myths and pitfalls • Learn about prominent PHP Web services extensions • Watch a demo [...]]]></description>
			<content:encoded><![CDATA[<p>WSO2 and Zend jointly present a webinar titling &#8220;<a href="http://wso2.org/library/webinars/2010/05/webinar-php-web-services-you-should-care">PHP Web Services: Why You Should Care</a>&#8221; on 26th of May, 2010. The webinar will mainly focus on the following aspects,<br />
• Understand Web services development best practices<br />
• Discuss Web service myths and pitfalls<br />
• Learn about prominent PHP Web services extensions<br />
• Watch a demo of building Web Services with both the Zend Framework and WSO2 Web Services Framework for PHP.</p>
<p>You can find more information about the webinar and the link to registration here, <a href="http://wso2.org/library/webinars/2010/05/webinar-php-web-services-you-should-care">http://wso2.org/library/webinars/2010/05/webinar-php-web-services-you-should-care</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2010/05/19/php-web-services-webinar-from-wso2-and-zend/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>WSF/PHP Code First Approach: Returning an Array of String</title>
		<link>http://www.dimuthu.org/blog/2010/01/08/wsfphp-code-first-approach-returning-an-array-of-string/</link>
		<comments>http://www.dimuthu.org/blog/2010/01/08/wsfphp-code-first-approach-returning-an-array-of-string/#comments</comments>
		<pubDate>Fri, 08 Jan 2010 02:05:12 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[WSDL]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[xml schema]]></category>
		<category><![CDATA[code first]]></category>
		<category><![CDATA[wsdl generation]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=1060</guid>
		<description><![CDATA[Here is a problem that many people have asked me how to do it. &#8220;Returning an array of string&#8221; with the code first approach. The API or WSDL generation annotation guide, http://wso2.org/project/wsf/php/2.0.0/docs/wsdl_generation_api.html contain all the things required in details. Here is an example of a service that return an array of string. &#60;?php /** splitMe [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a problem that many people have asked me how to do it. &#8220;Returning an array of string&#8221; with the code first approach. The API or WSDL generation annotation guide, <a href="http://wso2.org/project/wsf/php/2.0.0/docs/wsdl_generation_api.html">http://wso2.org/project/wsf/php/2.0.0/docs/wsdl_generation_api.html</a> contain all the things required in details. Here is an example of a service that return an array of string.</p>
<pre><span style="color: #000000; font-weight: bold;">&lt;?php</span>

<span style="color: #808080; font-style: italic;">/** splitMe function
 * @param string $string_to_split string to split
 * (maps to the xs:string XML schema type )
 * @return array of string $result split to array
 *(maps to the xs:double XML schema type )
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> splitMe<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$string_to_split</span><span style="color: #66cc66;">)</span>
<span style="color: #66cc66;">{</span>
    <span style="color: #b1b100;">return</span> <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"result"</span> =&gt; <a href="http://www.php.net/split"><span style="color: #000066;">split</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">":"</span>, <span style="color: #0000ff;">$string_to_split</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;

<span style="color: #66cc66;">}</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;">"splitMe"</span>=&gt;<span style="color: #ff0000;">"splitMe"</span><span style="color: #66cc66;">)</span>;
<span style="color: #0000ff;">$opParams</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"splitMe"</span>=&gt;<span style="color: #ff0000;">"MIXED"</span><span style="color: #66cc66;">)</span>;

<span style="color: #0000ff;">$svr</span> = <span style="color: #000000; font-weight: bold;">new</span> WSService<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;">"operations"</span>=&gt;<span style="color: #0000ff;">$operations</span>,
                           <span style="color: #ff0000;">"bindingStyle"</span>=&gt;<span style="color: #ff0000;">"doclit"</span>,
                           <span style="color: #ff0000;">"opParams"</span>=&gt;<span style="color: #0000ff;">$opParams</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;

<span style="color: #0000ff;">$svr</span>-&gt;<span style="color: #006600;">reply</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;
<span style="color: #000000; font-weight: bold;">?&gt;</span>
</pre>
<p>Note that the annotation corresponding to the return value.</p>
<pre> * @return array of spring $result split to array
</pre>
<p>This will generate an schema with an element of maxOccurs=&#8217;unbounded&#8217;. Note that you can get the wsdl from the &#8216;serviceurl?wsdl&#8217;.</p>
<pre><span style="font-weight: bold; color: black;">&lt;xsd:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"splitMeResponse"</span><span style="font-weight: bold; color: black;">&gt;</span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xsd:complexType<span style="font-weight: bold; color: black;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xsd:sequence<span style="font-weight: bold; color: black;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xsd:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"result"</span> <span style="color: #000066;">maxOccurs</span>=<span style="color: #ff0000;">"unbounded"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"xsd:string"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xsd:sequence<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xsd:complexType<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xsd:element<span style="font-weight: bold; color: black;">&gt;</span>
</span></span></pre>
<p>Now just generate a client for this service using wsdl2php and try invoke it. You will get an array of string as the response.</p>
<pre>    <span style="color: #0000ff;">$input</span> = <span style="color: #000000; font-weight: bold;">new</span> splitMe<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;
    <span style="color: #0000ff;">$input</span>-&gt;<span style="color: #006600;">string_to_split</span> = <span style="color: #ff0000;">"a:b:c:d"</span>;

 
    <span style="color: #808080; font-style: italic;">// call the operation</span>
    <span style="color: #0000ff;">$response</span> = <span style="color: #0000ff;">$proxy</span>-&gt;<span style="color: #006600;">splitMe</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$input</span><span style="color: #66cc66;">)</span>;
    <a href="http://www.php.net/print_r"><span style="color: #000066;">print_r</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$response</span><span style="color: #66cc66;">)</span>;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2010/01/08/wsfphp-code-first-approach-returning-an-array-of-string/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Article Introducing PHP Data Services</title>
		<link>http://www.dimuthu.org/blog/2009/01/05/article-introducing-php-data-services/</link>
		<comments>http://www.dimuthu.org/blog/2009/01/05/article-introducing-php-data-services/#comments</comments>
		<pubDate>Mon, 05 Jan 2009 13:06:55 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[database]]></category>
		<category><![CDATA[DataServices]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[RESTful]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[SQL]]></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]]></category>
		<category><![CDATA[introduction]]></category>
		<category><![CDATA[SOAP]]></category>
		<category><![CDATA[WS-*]]></category>
		<category><![CDATA[ws-security]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=900</guid>
		<description><![CDATA[Now you can view the article I wrote titling &#8220;Introduction to PHP Data Services&#8220;. There I explain how you can design and implement Data Services in PHP using WSF/PHP Data Services Library. This article covers, Designing your Data Service API. Writing the Data Service. Deploying and Testing Data Service. Make the Data Service available in [...]]]></description>
			<content:encoded><![CDATA[<p>Now you can view the article I wrote titling &#8220;<a href="http://wso2.org/library/articles/introduction-php-data-services">Introduction to PHP Data Services</a>&#8220;. There I explain how you can design and implement Data Services in PHP using <a href="http://wso2.org/projects/wsf/php">WSF/PHP</a> Data Services Library.</p>
<p>This article covers,</p>
<ol>
<li>Designing your Data Service API.</li>
<li>Writing the Data Service.</li>
<li>Deploying and Testing Data Service.</li>
<li>Make the Data Service available in both SOAP and RESTful form.</li>
<li>Use of WS-* features in your Data Service.</li>
</ol>
<p>If you are thinking of adapting SOA in to your database backed PHP applications, this article will be a good starting point.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2009/01/05/article-introducing-php-data-services/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RESTful PHP Web Services &#8211; Book Review</title>
		<link>http://www.dimuthu.org/blog/2009/01/01/restful-php-web-services-book-review/</link>
		<comments>http://www.dimuthu.org/blog/2009/01/01/restful-php-web-services-book-review/#comments</comments>
		<pubDate>Thu, 01 Jan 2009 05:22:46 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[design]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[RESTful]]></category>
		<category><![CDATA[review]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[Book]]></category>
		<category><![CDATA[clients]]></category>
		<category><![CDATA[services]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=865</guid>
		<description><![CDATA[PHP is one of the famous choice, when it comes to develop a web site. As the web evolve with the emerge of web service, REST (REpresentational State Transfer) concepts, the PHP language is also adapted to the new requirements specially with the availability of new SOA (Service Oriented Architecture), REST frameworks and libraries. Anyway [...]]]></description>
			<content:encoded><![CDATA[<p>PHP is one of the famous choice, when it comes to develop a web site. As the web evolve with the emerge of web service, REST (REpresentational State Transfer) concepts, the PHP language is also adapted to the new requirements specially with the availability of new SOA (Service Oriented Architecture), REST frameworks and libraries. Anyway there were hardly any guides, references or samples that properly describe the methodologies of developing REST applications using PHP.</p>
<p>The book &#8220;<a href="http://www.packtpub.com/restful-php-web-services/book">RESTful PHP Web Services</a>&#8216; by <a href="http://samisa-abeysinghe.blogspot.com/">Samisa Abeysinghe</a> certainly fill this gap. It can be used as a step by step guideline for newbies to learn the concepts and write simple RESTful PHP applications and Mashups. And even experienced developers would find this a great reference to keep nearby while working with RESTful Web Services in PHP. And it has lot of code samples, utility functions that developers can use it in their applications.</p>
<p><a href="http://www.packtpub.com/restful-php-web-services/book"><img title="RESTful PHP Web Services - Samisa Abeysinghe" src="http://images.packtpub.com/images/full/1847195520.jpg" alt="RESTful PHP Web Services - Samisa Abeysinghe" width="200" /></a></p>
<p><strong>About the Author</strong></p>
<p><a href="http://samisa-abeysinghe.blogspot.com/">Samisa Abeysinghe</a> is a well recognized name in the web services world. He lead the development of <a href="http://ws.apache.org/axis2/c/">Apache Axis2/C</a> and <a href="http://wso2.org/projects/wsf/php">WSO2 WSF/PHP</a>, two famous open source web service frameworks for &#8216;C&#8217; and PHP. In addition to his deep knowledge in the subject, his experience in involving with the community and the enterprise for years and working as a lecturer in universities, should have influenced a lot in writing this book.</p>
<p><strong>The Arrangement and the Content</strong></p>
<p>The <a href="http://www.packtpub.com/article/restful-php-web-services-table-of-contents">arrangement of the book</a> is done really well to make sure the reader can go through it in the right sequence. All the content is bundled just within 200 pages. So you don&#8217;t need to allocate a lot of time to go through the whole book. It is organized into 7 chapters and two appendixes which are mostly independent from each other.</p>
<p>The first chapter is completely devoted to explain the concepts of RESTful web services. It basically explains what is RESTful web service and why it is needed. And it briefly mentions about the currently available REST Frameworks for PHP.</p>
<p>The second chapter introduce some PHP codes that do REST web service requests and handles the XML responses using both DOM and SimpleXML APIs. And in the third chapter it shows more code samples specially about consuming real world web services like BBC, Yahoo and an earthquakes information service. Theses codes are written as mashups mostly combining two services to produce more meaningful information.</p>
<p>The forth chapter is about  designing and writing web service providers. Its counterpart, writing web service consumers is described in the chapter five. There it demonstrate a library system that operate using RESTful webservices. You can map this example to any system that you may like to develop to run with RESTful web services.  The chapter five of the book is available as a free download, <a href="http://www.dimuthu.org/wp-content/uploads/2008/12/restful-php-webservices_sample-chapter.pdf">RESTful PHP Web Services &#8211; Chapter 5</a>.</p>
<p>The forth and fifth chapters are not using any framework to write the sample codes on consuming and providing web services. But in the sixth chapter it shows the use of <a href="http://framework.zend.com/">Zend framework</a> to do write them. There it rewrites the same example (The RESTful library system) in MVC (Model -View &#8211; Controller) approach using the functionalities of Zend framework. (In fact the View in the service is omitted).</p>
<p>The seventh chapter is about debugging web services. Debugging is a much needed step in any software development cycle. So if you are a newbie, you should read this chapter before start writing any of your own code. This introduces tools and methodologies to make your debugging easy and effective.</p>
<p>The book contains two appendixes. They are too really useful as the chapters of the book. In the first appendix it explains another REST web service framework, <a href="http://wso2.org/projects/wsf/php">WSO2 Web Services Framework for PHP (WSF/PHP)</a>. To demonstrate it uses, some selected functionalities of the example library system (that is mentioned in chapters 4, 5, 6) is re-implemented using WSF/PHP. And it shows you how you can convert this RESTful system to a SOAP system in a minute. The second appendix provides you a code of a class (RESTClient), that you can use in consuming web services very effectively.</p>
<p><strong>Recommended Readers<br />
</strong></p>
<p>This book assume you have some knowledge in PHP. But it doesn&#8217;t require you to know anything related to web services, REST or XML. As you read the first few chapters, you will have a good understanding on the concepts and the basic applications of REST and XML using PHP. And the later chapters will guide to get deeper knowledge in writing complex and real world applications.</p>
<p>If you are a professional developer, you can skip the introduction chapters and jump directly to where you need to refer. For an example, if you use this book as a reference in designing and developing RESTful web service providers, you can directly read the chapter4 &#8211; Resource Oriented Services, chapter6- Resource Oriented Clients and Services with Zend Framework and probably the chapter 7 &#8211; Debugging Web Services.</p>
<p>This book contains the same example system (the library system) written in three different approaches, first without using any framework support, second using the Zend Framework, third using WSF/PHP. Each of them has its own pros and cons. So if you want to determine the approach more suitable to your requirements, or thinking of migrating from one to another, this book will be an ideal resource for you.</p>
<p>As you may have already noticed, this book contains lot of code samples. All the concepts are followed by simple code samples that explain the concept. In appendix it gives you a complete code for RESTClient class that you can use to call any REST service. Apart from the code of the example library system written using different frameworks, it has lot of codes for calling public web service APIs. And the explanation of the code is also done really well.</p>
<p>So it is clear this book is more targetting readers who like to implement PHP RESTful Systems in practice. And it covers enough concepts that you needed to know in writing practicle applications. So this book can take you from the zero knowlege to a deeper knowlege of RESTful PHP Web Services.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2009/01/01/restful-php-web-services-book-review/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP Web Services &#8211; Authentication Based on Client&#8217;s IP</title>
		<link>http://www.dimuthu.org/blog/2008/12/27/php-web-services-authentication-based-on-clients-ip/</link>
		<comments>http://www.dimuthu.org/blog/2008/12/27/php-web-services-authentication-based-on-clients-ip/#comments</comments>
		<pubDate>Sat, 27 Dec 2008 10:34:10 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[$_SERVER]]></category>
		<category><![CDATA[authenticate]]></category>
		<category><![CDATA[IP]]></category>
		<category><![CDATA[REMOTE_ADDR]]></category>
		<category><![CDATA[REMOTE_HOST]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=862</guid>
		<description><![CDATA[Explains with code samples how a PHP web service can be written to authenticate clients based on their IPs.]]></description>
			<content:encoded><![CDATA[<p>Same as web pages, web services also sometime require  client authentication. The most frequent way of authentication is the use of WS-Security Username token which authenticate clients based on the username and passwords. There can be situations where clients need to be authenticated based on its IP or its domain.</p>
<p>If you are writing web services from PHP (Using some PHP web service framework like <a href="http://wso2.org/projects/wsf/php">WSF/PHP</a>), You can use the PHP variables, <em>$_SERVER["REMOTE_ADDR"]</em> and <em>$_SERVER["REMOTE_HOST"]</em> to find the clients ip within the service logic code. If the client&#8217;s IP is static you can directly use the $_SERVER["REMOTE_ADDR"] and if it is dynamic you can use the $_SERVER["REMOTE_HOST"] which will be derived by reverse DNS look of the clients IP.</p>
<p>Here is one example of the use of these $_SERVER[] variables inside service logic.</p>
<pre class="php"> 
<span style="color: #000000; font-weight: bold;">function</span> members_only_func<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$in_message</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>

<span style="color: #808080; font-style: italic;">    // getting the clients IP.</span>
    <span style="color: #0000ff;">$remote_addr</span> = <span style="color: #0000ff;">$_SERVER</span><span style="color: #66cc66;">[</span><span style="color: #ff0000;">"REMOTE_ADDR"</span><span style="color: #66cc66;">]</span>;

    <span style="color: #b1b100;">if</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$remote_addr</span> == <span style="color: #ff0000;">"67.205.26.154"</span> ||
       <span style="color: #0000ff;">$remote_addr</span> == <span style="color: #ff0000;">"124.43.59.95"</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>
       <span style="color: #808080; font-style: italic;">// generates the message for authenticated clients.</span>

       <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$valid_out_message</span>;
    <span style="color: #66cc66;">}</span>

    <span style="color: #808080; font-style: italic;">// otherwise throw an exception</span>
    throw <span style="color: #000000; font-weight: bold;">new</span> WSFault<span style="color: #66cc66;">(</span><span style="color: #ff0000;">"Sender"</span>, <span style="color: #ff0000;">"Failed to Authenticate"</span><span style="color: #66cc66;">)</span>;
<span style="color: #66cc66;">}</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;">"membersOnlyOp"</span> =&gt; <span style="color: #ff0000;">"members_only_func"</span><span style="color: #66cc66;">)</span>;

<span style="color: #0000ff;">$service</span> = <span style="color: #000000; font-weight: bold;">new</span> WSService<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;">"operations"</span> =&gt; <span style="color: #0000ff;">$operations</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>;</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/12/27/php-web-services-authentication-based-on-clients-ip/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Data Services Best Practices</title>
		<link>http://www.dimuthu.org/blog/2008/12/18/data-services-best-practices/</link>
		<comments>http://www.dimuthu.org/blog/2008/12/18/data-services-best-practices/#comments</comments>
		<pubDate>Thu, 18 Dec 2008 17:39:48 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[data services]]></category>
		<category><![CDATA[DataServices]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[best practises]]></category>
		<category><![CDATA[coupling]]></category>
		<category><![CDATA[granularity]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[wsf/php]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=803</guid>
		<description><![CDATA[In simple term, data services are exposing data as web services. Anyway it is not a complete definition. Actually there are situations where we use data services not only to read data, but also to create, update or delete data. So it is better say data services are doing CRUD (Create, Read, Update, Delete) operations [...]]]></description>
			<content:encoded><![CDATA[<p>In simple term, data services are exposing data as web services. Anyway it is not a complete definition. Actually there are situations where we use data services not only to read data, but also to create, update or delete data. So it is better say data services are doing CRUD (Create, Read, Update, Delete) operations for data through web services. Simply it is like providing a web service interface for the database.</p>
<p>Anyway exposing  a database directly as a web service is like violating the first principles of software engineering. It will tightly couple the database structure with the interface, so whenever you do a simple change to the database schema, you will have to change the web service interface which will no doubt break all the clients depending on it.</p>
<p>So first of all, you have to design the service interface independent of the database schema you have. Most of the time you will able to find some query that would map the service interface to the database schema.</p>
<p>For an example think of publishing data in database table (say for table name &#8220;Games&#8221;) like this.</p>
<table border="1">
<tbody>
<tr>
<th style="background:#cccccc" colspan="7">Teams</th>
</tr>
<tr style="background:#cccccc">
<td>GameID</td>
<td>Venue</td>
<td>Date</td>
<td>Team1</td>
<td>Team2</td>
<td>Team1Score</td>
<td>Team2Score</td>
</tr>
<tr>
<td>1</td>
<td>xxx stadium</td>
<td>2008-12-18</td>
<td>Italy</td>
<td>Sweden</td>
<td>34</td>
<td>33</td>
</tr>
<tr>
<td>2</td>
<td>yyy stadium</td>
<td>2008-12-19</td>
<td>France</td>
<td>Spain</td>
<td>51</td>
<td>50</td>
</tr>
</tbody>
</table>
<p>You will directly able to map these data to data service. So the response payload for a &#8220;getGames&#8221; operation would be something like,</p>
<pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;getGamesResponse<span style="font-weight: bold; color: black;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;Game<span style="font-weight: bold; color: black;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;Venue<span style="font-weight: bold; color: black;">&gt;</span></span></span>
         xxx stadium
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/Venue<span style="font-weight: bold; color: black;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;Date<span style="font-weight: bold; color: black;">&gt;</span></span></span>
         2008-12-18
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/date<span style="font-weight: bold; color: black;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;Team1<span style="font-weight: bold; color: black;">&gt;</span></span></span>
          Italy
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/Team1<span style="font-weight: bold; color: black;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;Team2<span style="font-weight: bold; color: black;">&gt;</span></span></span>
          Sweden
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/Team2<span style="font-weight: bold; color: black;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;Team1Score<span style="font-weight: bold; color: black;">&gt;</span></span></span>
          34
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/Team1Score<span style="font-weight: bold; color: black;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;Team2Score<span style="font-weight: bold; color: black;">&gt;</span></span></span>
          33
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/Team2Score<span style="font-weight: bold; color: black;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/Game<span style="font-weight: bold; color: black;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;Game<span style="font-weight: bold; color: black;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;Venue<span style="font-weight: bold; color: black;">&gt;</span></span></span>
         yyy stadium
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/Venue<span style="font-weight: bold; color: black;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;Date<span style="font-weight: bold; color: black;">&gt;</span></span></span>
         2008-12-19
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/date<span style="font-weight: bold; color: black;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;Team1<span style="font-weight: bold; color: black;">&gt;</span></span></span>
          France
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/Team1<span style="font-weight: bold; color: black;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;Team2<span style="font-weight: bold; color: black;">&gt;</span></span></span>
          Spain
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/Team2<span style="font-weight: bold; color: black;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;Team1Score<span style="font-weight: bold; color: black;">&gt;</span></span></span>
          51
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/Team1Score<span style="font-weight: bold; color: black;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;Team2Score<span style="font-weight: bold; color: black;">&gt;</span></span></span>
          50
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/Team2Score<span style="font-weight: bold; color: black;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/Game<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/</span></span><span><span><span style="color: #009900;"><span style="font-weight: bold; color: black;">getGamesResponse</span></span></span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;"><span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>You can get this done with a SQL query simply as this,</p>
<pre class="sql"><span style="font-weight: bold; color: #993333;">SELECT</span> * <span style="font-weight: bold; color: #993333;">FROM</span> <span style="color: #ff0000;">`Games`</span></pre>
<p>Say later if you decided to restructure the database table so the new database schema would be like this,</p>
<pre>
<table border="1">
<tbody>
<tr>
<th style="background:#cccccc" colspan="3">Games</th>
</tr>
<tr style="background:#cccccc">
<td>GameId</td>
<td>Venue</td>
<td>Date</td>
</tr>
<tr>
<td>1</td>
<td>xxx stadium</td>
<td>2008-12-18</td>
</tr>
<tr>
<td>1</td>
<td>yyy stadium</td>
<td>2008-12-19</td>
</tr>
</tbody>
</table>
</pre>
<pre>
<table border="1">
<tbody>
<tr>
<th style="background:#cccccc" colspan="3">GamesTeams</th>
</tr>
<tr style="background:#cccccc">
<td>GameId</td>
<td>TeamId</td>
<td>score</td>
</tr>
<tr>
<td>1</td>
<td>1</td>
<td>70</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>33</td>
</tr>
<tr>
<td>2</td>
<td>1</td>
<td>51</td>
</tr>
<tr>
<td>2</td>
<td>3</td>
<td>50</td>
</tr>
</tbody>
</table>
</pre>
<table border="1">
<tbody>
<tr>
<th style="background:#cccccc" colspan="3">Teams</th>
</tr>
<tr style="background:#cccccc">
<td>TeamId</td>
<td>Name</td>
<td>Coach</td>
</tr>
<tr>
<td>1</td>
<td>Italy</td>
<td>Mr. ABC</td>
</tr>
<tr>
<td>1</td>
<td>Canada</td>
<td>Mr. PQR</td>
</tr>
<tr>
<td>2</td>
<td>Spain</td>
<td>Mr. XYZ</td>
</tr>
</tbody>
</table>
<p><em>(Note here the Games and Teams are associated in the GamesTeams table.)</em></p>
<p>You can still use a query like the one in following to provide the same service interface, because it returns the same result set as the earlier one.</p>
<pre class="sql">   <span style="font-weight: bold; color: #993333;">SELECT</span> Games.Venue,
              Games.Date,
              Team1.Name <span style="font-weight: bold; color: #993333;">AS</span> Team1,
              Team2.Name <span style="font-weight: bold; color: #993333;">AS</span> Team2,
              GameTeam1.Score <span style="font-weight: bold; color: #993333;">AS</span> Score1,
              GameTeam2.Score <span style="font-weight: bold; color: #993333;">AS</span> Score2
         <span style="font-weight: bold; color: #993333;">FROM</span> Teams Team1,
              Teams Team2,
              GamesTeams GameTeam1,
              GamesTeams GameTeam2,
              Games
        <span style="font-weight: bold; color: #993333;">WHERE</span> GameTeam1.gameId = Games.gameId  <span style="font-weight: bold; color: #993333;">AND</span>
              GameTeam2.gameId = Games.gameId <span style="font-weight: bold; color: #993333;">AND</span>
              GameTeam1.teamId = Team1.teamId <span style="font-weight: bold; color: #993333;">AND</span>
              GameTeam2.teamId = Team2.teamId <span style="font-weight: bold; color: #993333;">AND</span>
              Team1.teamId &lt;&gt; Team2.teamId <span style="font-weight: bold; color: #993333;">AND</span>
              Team1.name=?</pre>
<p>This allows you to keep the service interface unchanged, regardless of the changes you done to the database schema.</p>
<p>In addition to that, we can uses the features of the data service libraries to give meaningful names for the response elements. If we take above example itself, say you want to rename &#8216;Score1&#8242; to &#8216;Team1-Score&#8217; and &#8216;Score2&#8242; to &#8216;Team2-Score&#8217;. But the dash character (&#8216;-&#8217;) cannot be used as a variable in a database query. But you can provide that in the map of sql name to element name when you are writing the data service.</p>
<p>If you are using <a href="http://wso2.org/projects/wsf/php">WSF/PHP</a> php data services Here is how you provide that mapping,</p>
<pre class="php"><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;">"getGamesResponse"</span>,
                      <span style="color: #ff0000;">"rowElement"</span> =&gt; <span style="color: #ff0000;">"game"</span>,  <span style="font-style: italic; color: #808080;">// this is the repeating wrapper element for each game</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;">"Venue"</span> =&gt; <span style="color: #ff0000;">"Venue"</span>, <span style="font-style: italic; color: #808080;">// this is the mapping of xml name =&gt; sql name</span>
                                           <span style="color: #ff0000;">"Date"</span> =&gt; <span style="color: #ff0000;">"Date"</span>,
                                           <span style="color: #ff0000;">"Team1"</span> =&gt; <span style="color: #ff0000;">"Team1"</span>,
                                           <span style="color: #ff0000;">"Team2"</span> =&gt; <span style="color: #ff0000;">"Team2"</span>,
                                           <span style="color: #ff0000;">"Team1-score"</span> =&gt; <span style="color: #ff0000;">"Score1"</span>, <span style="font-style: italic; color: #808080;">// we are using different names for sql and xml</span>
                                           <span style="color: #ff0000;">"Team2-score"</span> =&gt; <span style="color: #ff0000;">"Score2"</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;</pre>
<p>If you write it using <a href="http://wso2.org/projects/solutions/data-services/java">Java Data Services</a>, you can use do this with the following configuration xml,</p>
<pre class="xml">        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;result</span> <span style="color: #000066;">element</span>=<span style="color: #ff0000;">"getGamesResponse"</span> <span style="color: #000066;">rowName</span>=<span style="color: #ff0000;">"game"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"Venue"</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">"Venu"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"Date"</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">"Date"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"Team1"</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">"Team1"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"Team2"</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">"Team2"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"Team1-Score"</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">"Score1"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"Team2-Score"</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">"Score2"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/result<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>Another consideration, when talking about the best practices of designing web services or data services is the granularity of the service interface. We say a web service is fine grained if the service contains tons of small operations. The opposite of that is the coarse grained services, which contains large but few operations. And it is recommended to use the later approach, you can see why from the following example.</p>
<p>Lets say you are developing a web service to upload some information. In order to upload the information first the user have to be authenticated and then the content should be validated. Then only he can submit the actual information. Say you design a fine grained web service for that. So it has three operations.</p>
<ol>
<li>authenticateUser</li>
<li>validateContent</li>
<li>submitInformation</li>
</ol>
<p>If you design a coarse grained service interface it will be just the &#8216;uploadInformation&#8217; operation. And all the three operation defined earlier will be called within the service logic and the clients will not be aware of that.</p>
<p>So here are some disadvantages that I see in the fine grained interface design compared with coarse grained design.</p>
<ol>
<li>The coupling is too high. Since the client is linked with the service in three adapters. Say you decided to change the service so that you first validate the content and depending on the content it sometime bypasses the authentication. You can&#8217;t do this with the former approach (fine grained approach) without changing the clients. But if it were designed as a coarse grained service (just one uploadInformation operation), the client need not to be changed.</li>
<li>Two much time consumed for the transmission. Since we used three web service calls to do a single task the latency of the operation will largely depend on the network latency which will no doubt is comparatively very low. So the performance of the operation is degraded.</li>
<li>The clients can bypass some steps!, Say in your fine grained service, some client bypass the authentication and validateContent steps and jump directly to the sumbitContent operation. In fact you have to write special code to make sure the clients call the service in the correct sequence, otherwise it will be a big security hole.</li>
</ol>
<p>So I think these three points will be enough to explain why you should try to design a coarse grained interface for your web service.</p>
<p>You can apply these principle when you write data services as well. Lets take the same example explained above. Say there is another table that keep the scoring shots of each game like the one in following.</p>
<table border="1">
<tbody>
<tr>
<th style="background:#cccccc" colspan="7">ScoringShots</th>
</tr>
<tr style="background:#cccccc">
<td>GameID</td>
<td>Time</td>
<td>ScoringTeam</td>
<td>ScoringPlayer</td>
</tr>
</tbody>
</table>
<p>Here also you can keep the operation like &#8216;getGames&#8217; which we defined in the above section. That operation only provide the basic information like the winner and the scores. So if the clients want to know about scoring shots as well, he have to call another operation, say getScoringShots(game) that will return the scoring shots results for a given game. If in practice the clients only need to know about scoring shots of few selected games, then this approach is ok.<br />
But say normally clients need to know about the scoring shots of each and every games. Then they have to call the operation &#8216;getScoringShots&#8217; multiple times. That&#8217;s when the lesson we just learn about the granularity can be applied. We can actually provide another operation, say &#8216;getGamesDetailed&#8217; that actually bundle the details of scoring shots for all games with other information about the game. Here is snip of the response XML, I&#8217;m talking about.</p>
<pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;getGamesDetailedResponse<span style="font-weight: bold; color: black;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;Game<span style="font-weight: bold; color: black;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;Venue<span style="font-weight: bold; color: black;">&gt;</span></span></span>
         xxx stadium
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/Venue<span style="font-weight: bold; color: black;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;Date<span style="font-weight: bold; color: black;">&gt;</span></span></span>
         2008-12-18
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/date<span style="font-weight: bold; color: black;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;Team1<span style="font-weight: bold; color: black;">&gt;</span></span></span>
          Italy
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/Team1<span style="font-weight: bold; color: black;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;Team2<span style="font-weight: bold; color: black;">&gt;</span></span></span>
          Sweden
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/Team2<span style="font-weight: bold; color: black;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;Team1Score<span style="font-weight: bold; color: black;">&gt;</span></span></span>
          34
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/Team1Score<span style="font-weight: bold; color: black;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;Team2Score<span style="font-weight: bold; color: black;">&gt;</span></span></span>
          33
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/Team2Score<span style="font-weight: bold; color: black;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="font-style: italic; color: #808080;">&lt;!-- additionally we have ScoringShots element --&gt;</span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ScoringShots<span style="font-weight: bold; color: black;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;Shot<span style="font-weight: bold; color: black;">&gt;</span></span></span>
              <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;Time<span style="font-weight: bold; color: black;">&gt;</span></span></span> xxx <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/Time<span style="font-weight: bold; color: black;">&gt;</span></span></span>
              <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ScoringPlayer<span style="font-weight: bold; color: black;">&gt;</span></span></span> xxx <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/ScoringPlayer<span style="font-weight: bold; color: black;">&gt;</span></span></span>
              <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ScoringTeam<span style="font-weight: bold; color: black;">&gt;</span></span></span> xxx <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/ScoringTeam<span style="font-weight: bold; color: black;">&gt;</span></span></span>
              <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;Score<span style="font-weight: bold; color: black;">&gt;</span></span></span> xxx <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/Score<span style="font-weight: bold; color: black;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/Shot<span style="font-weight: bold; color: black;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;Shot<span style="font-weight: bold; color: black;">&gt;</span></span></span>
              <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;Time<span style="font-weight: bold; color: black;">&gt;</span></span></span> yyy <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/Time<span style="font-weight: bold; color: black;">&gt;</span></span></span>
              <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ScoringPlayer<span style="font-weight: bold; color: black;">&gt;</span></span></span> yyy <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/ScoringPlayer<span style="font-weight: bold; color: black;">&gt;</span></span></span>
              <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ScoringTeam<span style="font-weight: bold; color: black;">&gt;</span></span></span> yyy <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/ScoringTeam<span style="font-weight: bold; color: black;">&gt;</span></span></span>
              <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;Score<span style="font-weight: bold; color: black;">&gt;</span></span></span> yyy <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/Score<span style="font-weight: bold; color: black;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/Shot<span style="font-weight: bold; color: black;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/ScoringShots<span style="font-weight: bold; color: black;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/Game<span style="font-weight: bold; color: black;">&gt;</span></span></span>

   <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;Game<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-style: italic; color: #808080;">&lt;!-- Another game details are mentioned here --&gt;</span></span>
   <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/Game<span style="font-weight: bold; color: black;">&gt;</span></span></span>

   <span style="color: #009900;"><span style="font-style: italic; color: #808080;">&lt;!-- More Games --&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/getGamesDetailedResponse<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>You can generate this kind of response using the nested query support of the data services libraries.<br />
You can checkout more details about nested queries in php data services from <a href="http://www.dimuthu.org/blog/2008/08/04/nested-queries-with-php-data-services/">my old post about php data service API.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/12/18/data-services-best-practices/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>PHP Data Services with PostgreSQL</title>
		<link>http://www.dimuthu.org/blog/2008/12/07/php-data-services-with-postgresql/</link>
		<comments>http://www.dimuthu.org/blog/2008/12/07/php-data-services-with-postgresql/#comments</comments>
		<pubDate>Sun, 07 Dec 2008 12:56:19 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[2 minutes guide]]></category>
		<category><![CDATA[DataServices]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[SQL]]></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[data services]]></category>
		<category><![CDATA[DataService]]></category>
		<category><![CDATA[pdo_pgsql]]></category>
		<category><![CDATA[pgsql]]></category>
		<category><![CDATA[postgresql]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=771</guid>
		<description><![CDATA[LAMP (Linux + Apache + Mysql + PHP) stack powers many servers in the Internet today. For a LAMP  server, PostgreSQL could be the first alternative to Mysql. Similar to PHP + MySQL,  PHP + PostgreSQL too can be easily used in to host data services. Here are the steps to do it. If you [...]]]></description>
			<content:encoded><![CDATA[<p>LAMP (Linux + Apache + Mysql + PHP) stack powers many servers in the Internet today. For a LAMP  server, PostgreSQL could be the first alternative to Mysql. Similar to PHP + MySQL,  PHP + PostgreSQL too can be easily used in to host data services. Here are the steps to do it.</p>
<ol>
<li> If you already don&#8217;t have Apache + PHP + PostgreSQL download them from the following locations. Apache &#8211; <a href="http://httpd.apache.org/download.cgi">http://httpd.apache.org/download.cgi</a>, PHP &#8211; <a href="http://php.net">http://php.net</a> and PostgreSQL &#8211; <a href="http://www.postgresql.org/download/">http://www.postgresql.org/download/</a></li>
<li> You have to enable the PHP pdo_pgsql, pdo and pgsql plugins. Read <a href="http://www.php.net/manual/en/pgsql.setup.php">here </a>for the instructions to setup these libraries. (For an example: if you are windows you have to set the system &#8216;PATH&#8217; variable to the &lt;postgresql_installed_dir&gt;/bin directory.</li>
<li> If you already don&#8217;t have <a href="http://wso2.org/projects/wsf/php">WSF/PHP,</a> download and install it according to the guidelines provided in <a href="http://wso2.org/project/wsf/php/2.0.0/docs/install_guide.html">wsf/php installation guide</a>.<em>NOTE: You can check pdo_pgsql and wsf/php has properly installed with the help of phpinfo() function.</em></li>
<li> Now lets start with creating a sample Database table. For this example I created a database called &#8216;workshop&#8217;, schema called &#8216;workshop&#8217; and inside there the table &#8216;Employee&#8217; with the following schema.<br />
<table border="1">
<tbody>
<tr style="background: #dddddd">
<td>Column Name</td>
<td>Column Type</td>
</tr>
<tr>
<td>employId</td>
<td>integer</td>
</tr>
<tr>
<td>name</td>
<td>character varying</td>
</tr>
<tr>
<td>email</td>
<td>character varying</td>
</tr>
<tr>
<td>jobTitle</td>
<td>character varying</td>
</tr>
<tr>
<td>project</td>
<td>character varying</td>
</tr>
</tbody>
</table>
<p><em>Note: You can use <a href="http://phppgadmin.sourceforge.net/">phpPgAdmin</a> (web based) or <a href="http://www.pgadmin.org/">pgAdmin III </a>to create tables from GUI </em></li>
<li> Then you can write a small php script to expose the data in the above table as a web service.
<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 (i.e. PGSQUL USERNAME</span>
<span style="font-style: italic; color: #808080;">// and PGSQL_PASSWORD) for my PGSQL 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;">"pgsql"</span>,
		<span style="color: #ff0000;">"username"</span> =&gt; PGSQL_USERNAME,
		<span style="color: #ff0000;">"password"</span> =&gt; PGSQL_PASSWORD,
		<span style="color: #ff0000;">"dbname"</span> =&gt; <span style="color: #ff0000;">"workshop"</span>,
		<span style="color: #ff0000;">"dbhost"</span> =&gt; <span style="color: #ff0000;">"localhost"</span>
		<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;">"employees"</span>,
                    <span style="color: #ff0000;">"rowElement"</span> =&gt; <span style="color: #ff0000;">"employee"</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;">"id"</span> =&gt; <span style="color: #ff0000;">"employeeId"</span>,
                            <span style="color: #ff0000;">"name"</span> =&gt; <span style="color: #ff0000;">"name"</span>,
                            <span style="color: #ff0000;">"email"</span> =&gt; <span style="color: #ff0000;">"email"</span>,
                            <span style="color: #ff0000;">"jobTitle"</span> =&gt; <span style="color: #ff0000;">"jobTitle"</span>,
                            <span style="color: #ff0000;">"project"</span> =&gt; <span style="color: #ff0000;">"project"</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;

<span style="color: #0000ff;">$sql</span> = <span style="color: #ff0000;">"SELECT * FROM workshop.Employees"</span>;

<span style="color: #0000ff;">$get_employees_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_employees_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;">"employees"</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;">"getEmployees"</span> =&gt; <span style="color: #0000ff;">$get_employees_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;">"getEmployees"</span> =&gt; <span style="color: #0000ff;">$get_employees_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>;</pre>
<pre class="php"><span style="font-weight: bold; color: #000000;">?&gt;</span></pre>
</li>
<li> We just wrote a PostgreSQL Data Services that provides its service as both REST and SOAP form. To deploy this service, We just need to copy this in to the web root directory. And the web URL for the script will be the endpoint to the web service.</li>
<li>We can test the service either by calling its SOAP interface, which we may need to write a small SOAP client or by calling its REST interface, which only need a GET request from the browser. Say my script name is &#8220;my_dataservice.php&#8221; and I&#8217;ve put it in the web root directory, then the URL to call the REST interface of the service is
<pre>http://localhost/my_dataservice.php/employees</pre>
</li>
</ol>
<p><strong>WSDL Generation for PostgreSQL Data Service</strong><br />
You can get the WSDL for the service from the URL formed adding the suffix &#8220;?wsdl&#8221; (or &#8220;?wsdl2&#8243; to wsdl v2.0)  to the service URL,</p>
<pre>http://localhost/my_dataservice.php?wsdl</pre>
<p>Here all the schema data types are shown as xsd:anyType, which may not be the behavior that you want. In fact you can provide the schema data types to the fields from the code itself. Lets change the $outputFormat variable to provide the schema information as well using the following code snip.</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;">"employees"</span>,
                    <span style="color: #ff0000;">"rowElement"</span> =&gt; <span style="color: #ff0000;">"employee"</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;">"id"</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;">"employeeId"</span>,
		    			  <span style="color: #ff0000;">"xsdType"</span> =&gt; <span style="color: #ff0000;">"xsd:int"</span><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;">"name"</span>,
		    			  <span style="color: #ff0000;">"xsdType"</span> =&gt; <span style="color: #ff0000;">"xsd:string"</span><span style="color: #66cc66;">)</span>,
			    <span style="color: #ff0000;">"email"</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;">"email"</span>,
		    			  <span style="color: #ff0000;">"xsdType"</span> =&gt; <span style="color: #ff0000;">"xsd:string"</span><span style="color: #66cc66;">)</span>,
			    <span style="color: #ff0000;">"jobTitle"</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;">"jobTitle"</span>,
		    			  <span style="color: #ff0000;">"xsdType"</span> =&gt; <span style="color: #ff0000;">"xsd:string"</span><span style="color: #66cc66;">)</span>,
			    <span style="color: #ff0000;">"project"</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;">"project"</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>Note that you provide the xsd type for each field explicitly. In fact this change is not needed for mysql pdo extension since it allows identifying field types programatically. Since this feature is not available in all the other pdo drivers, we have to explicitly give xsd type information for them.</p>
<p>If you wan to provide data services with SQLite or MSSQL, You can check my other posts on <a href="http://www.dimuthu.org/blog/2008/10/04/mssqlmicrosoft-sql-data-services-in-php/">MSSQL(Microsoft SQL) Data Services In PHP</a> and <a href="http://www.dimuthu.org/blog/2008/10/05/data-services-with-sqlite-in-php/">Data Services with SQLite in PHP</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/12/07/php-data-services-with-postgresql/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Steps to Convert a SQL Query to a Data Service</title>
		<link>http://www.dimuthu.org/blog/2008/11/27/steps-to-convert-sql-query-to-a-data-service/</link>
		<comments>http://www.dimuthu.org/blog/2008/11/27/steps-to-convert-sql-query-to-a-data-service/#comments</comments>
		<pubDate>Thu, 27 Nov 2008 17:48:31 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[DataServices]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[data service]]></category>
		<category><![CDATA[sql query]]></category>
		<category><![CDATA[Web Service]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=741</guid>
		<description><![CDATA[With WSF/PHP Data Service library, you can convert a SQL query to a Data Service very easily in few steps. Decide your SQL query first, For the query you may require some input parameters, and you have to decide what should be returned by the query, Say your query is $sql_query = "SELECT name, age, [...]]]></description>
			<content:encoded><![CDATA[<p>With <a href="http://wso2.org/projects/wsf/php">WSF/PHP</a> Data Service library, you can convert a SQL query to a Data Service very easily in few steps.</p>
<ol>
<li>Decide your SQL query first, For the query you may require some input parameters, and you have to decide what should be returned by the query, Say your query is
<pre><span style="color: #0000ff;">$sql_query</span> = <span style="color: #ff0000;">"SELECT name, age, email FROM users where country = ?"</span>;</pre>
<p>Then the &#8220;country&#8221; is our input parameter and the name, age, email are our return values.</li>
<li>Define the input Format. For the above query it will be something like,
<pre class="php"><span style="color: #0000ff;">$inputFormat</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"country"</span> =&gt; <span style="color: #ff0000;">"INT"</span><span style="color: #66cc66;">)</span>;</pre>
</li>
<li>Define the output format. We are giving the name &#8220;Users&#8221; for the out most wrapper element and the name &#8220;user&#8221; for the wrapper element of each user. Here is how we define it,
<pre class="php"><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;">"users"</span>,
                <span style="color: #ff0000;">"rowElement"</span> =&gt; <span style="color: #ff0000;">"user"</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;">"name"</span>,
                            <span style="color: #ff0000;">"age"</span> =&gt; <span style="color: #ff0000;">"age"</span>,
                            <span style="color: #ff0000;">"email"</span> =&gt; <span style="color: #ff0000;">"email"</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;</pre>
<p>For this output format, our expected result payload would be like,</p>
<pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;users<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;user<span style="font-weight: bold; color: black;">&gt;</span></span></span>
     <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;name<span style="font-weight: bold; color: black;">&gt;</span></span></span>xxx<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/name<span style="font-weight: bold; color: black;">&gt;</span></span></span>
     <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;age<span style="font-weight: bold; color: black;">&gt;</span></span></span>23<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/age<span style="font-weight: bold; color: black;">&gt;</span></span></span>
     <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;email<span style="font-weight: bold; color: black;">&gt;</span></span></span>xxx@xxx.xx<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/email<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/user<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;user<span style="font-weight: bold; color: black;">&gt;</span></span></span>
     <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;name<span style="font-weight: bold; color: black;">&gt;</span></span></span>yyy<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/name<span style="font-weight: bold; color: black;">&gt;</span></span></span>
     <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;age<span style="font-weight: bold; color: black;">&gt;</span></span></span>23<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/age<span style="font-weight: bold; color: black;">&gt;</span></span></span>
     <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;email<span style="font-weight: bold; color: black;">&gt;</span></span></span>yyy@yyy.yy<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/email<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/user<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  ....
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/users<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
</li>
<li> Define your operation using the sql query, input and output formats.
<pre class="php"><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;">"getUsersByCountry"</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;">"inputFormat"</span> =&gt; <span style="color: #0000ff;">$inputFormat</span>,
                              <span style="color: #ff0000;">"sql"</span> =&gt; <span style="color: #0000ff;">$sql_query</span>,
                              <span style="color: #ff0000;">"outputFormat"</span> =&gt; <span style="color: #0000ff;">$outputFormat</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;</pre>
</li>
<li> Define your database configuration in an array like this,
<pre class="php"><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="font-style: italic; color: #808080;">// your db engine</span>
    <span style="color: #ff0000;">"username"</span> =&gt; <span style="color: #ff0000;">"myname"</span>, <span style="font-style: italic; color: #808080;">// name &amp; password for the db server</span>
    <span style="color: #ff0000;">"password"</span> =&gt; <span style="color: #ff0000;">"mypasswd"</span>,
    <span style="color: #ff0000;">"dbname"</span> =&gt; <span style="color: #ff0000;">"db"</span>, <span style="font-style: italic; color: #808080;">// the db</span>
    <span style="color: #ff0000;">"dbhost"</span> =&gt; <span style="color: #ff0000;">"localhost"</span><span style="color: #66cc66;">)</span>;</pre>
</li>
<li> Create a DataService instance using the database configuration and the operations we just created. And call DataServices reply method.
<pre class="php"><span style="color: #0000ff;">$ds_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;">$ds_service</span>-&gt;<span style="color: #006600;">reply</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</pre>
</li>
</ol>
<p>That is it. You just exposed your query as a web service. The PHP script URL will be the endpoint URL for the web service.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/11/27/steps-to-convert-sql-query-to-a-data-service/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>5 Facts About WS-Addressing Action in WSF/PHP</title>
		<link>http://www.dimuthu.org/blog/2008/11/26/5-facts-about-ws-addressing-action-in-wsfphp/</link>
		<comments>http://www.dimuthu.org/blog/2008/11/26/5-facts-about-ws-addressing-action-in-wsfphp/#comments</comments>
		<pubDate>Wed, 26 Nov 2008 17:55:29 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[SOA]]></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[action]]></category>
		<category><![CDATA[dispatching]]></category>
		<category><![CDATA[SOAP action]]></category>
		<category><![CDATA[ws-addressing]]></category>
		<category><![CDATA[WSClient]]></category>
		<category><![CDATA[WSMessage]]></category>
		<category><![CDATA[WSService]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=734</guid>
		<description><![CDATA[WS-Addressing Action is used by web services to dispatch the operation for an incoming request SOAP message. It is one way of dispatching operations in WSF/PHP and it base Apach Axis2/C, other ways are SOAP action based dispatching which covers in my early blog &#8220;The Use of SOAP Action with WSF/PHP&#8220;,  Body based dispatching and [...]]]></description>
			<content:encoded><![CDATA[<ol>
<li> WS-Addressing Action is used by web services to dispatch the operation for an incoming request SOAP message. It is one way of dispatching operations in <a href="http://wso2.org/projects/wsf/php">WSF/PHP</a> and it base <a href="http://ws.apache.org/axis2/c/">Apach Axis2/C</a>, other ways are SOAP action based dispatching which covers in my early blog &#8220;<a href="http://www.dimuthu.org/blog/2008/11/25/the-use-of-soap-action-with-wsfphp/">The Use of SOAP Action with WSF/PHP</a>&#8220;,  Body based dispatching and URI based dispatching.</li>
<li>In WSF/PHP client, we can enable the addressing by setting the &#8220;action&#8221; field in the request <a href="http://wso2.org/project/wsf/php/2.0.0/docs/api_content.html#message">WSMessage</a> instance and setting &#8220;useWSA&#8221;=&gt; TRUE in the <a href="http://wso2.org/project/wsf/php/2.0.0/docs/api_content.html#client">WSClient</a> instance. Here is an example.
<pre class="php"><span style="color: #0000ff;">$requestPayloadString</span> = &lt;&lt;&lt;XML
&lt;ns1:echoString xmlns:ns1=<span style="color: #ff0000;">"http://wso2.org/wsfphp/samples"</span>&gt;
   &lt;text&gt;Hello World!&lt;/text&gt;
&lt;/ns1:echoString&gt;
XML;

<span style="color: #0000ff;">$client</span> = <span style="font-weight: bold; color: #000000;">new</span> WSClient<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;">"to"</span> =&gt; <span style="color: #ff0000;">"http://localhost/samples/echo_service.php"</span>,
                             <span style="color: #ff0000;">"useWSA"</span> =&gt; <span style="font-weight: bold; color: #000000;">TRUE</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;

<span style="color: #0000ff;">$requestMessage</span> = <span style="font-weight: bold; color: #000000;">new</span> WSMessage<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$requestPayloadString</span>,
	    <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"action"</span> =&gt; <span style="color: #ff0000;">"http://localhost/samples/echo_service/echoString"</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;

<span style="color: #0000ff;">$responseMessage</span> = <span style="color: #0000ff;">$client</span>-&gt;<span style="color: #006600;">request</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$requestMessage</span><span style="color: #66cc66;">)</span>;

<a href="http://www.php.net/printf"><span style="color: #000066;">printf</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"Response = %s &lt;br&gt;"</span>, <a href="http://www.php.net/htmlspecialchars"><span style="color: #000066;">htmlspecialchars</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$responseMessage</span>-&gt;<span style="color: #006600;">str</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;</pre>
<p>If you doesn&#8217;t set &#8220;useWSA&#8221; =&gt; TRUE explicitly, the client will send the action as a SOAP action rather than a WSA Action. The above is the same example I used in <a href="http://www.dimuthu.org/blog/2008/11/25/the-use-of-soap-action-with-wsfphp/">demonstrating SOAP action</a> with just the addition of &#8220;useWSA&#8221; option.</li>
<li> You can select WS-Addressing version among &#8220;submission&#8221; which .NET support by default and &#8220;1.0&#8243;, just by mention it in the &#8220;useWSA&#8221; field.<br />
I.e.</p>
<table border="1px">
<tbody>
<tr>
<td>&#8220;useWSA&#8221; =&gt; &#8220;submission&#8221;</td>
<td>Then the namespaces are having the values defined in the submission specification of WS-Addressing.</td>
</tr>
<tr>
<td>&#8220;useWSA&#8221; =&gt; 1.0</td>
<td>Then the namespace are having the values defined in the WS-Addressing 1.0 spec.</td>
</tr>
</tbody>
</table>
</li>
<li>In the option &#8220;actions&#8221; in the WSService, we can provide the action to operation map, so the service will direct the SOAP messages  to the correct operation by looking at the WS-Addressing action of the SOAP message.<br />
Here is a sample code that use action to dispatch the operation.</p>
<pre class="php"><span style="font-weight: bold; color: #000000;">function</span> echoStringFunc<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$inMessage</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>
    <span style="font-style: italic; color: #808080;">// logic of echoString operation</span>
<span style="color: #66cc66;">}</span>

<span style="font-weight: bold; color: #000000;">function</span> echoIntFunc<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$inMessage</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>
    <span style="font-style: italic; color: #808080;">// logic of echoInt operation</span>
<span style="color: #66cc66;">}</span>

<span style="font-style: italic; color: #808080;">// we will take echoString and echoInt as tow 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;">"echoString"</span> =&gt; <span style="color: #ff0000;">"echoStringFunction"</span>,
                    <span style="color: #ff0000;">"echoInt"</span> =&gt; <span style="color: #ff0000;">"echoIntFunction"</span><span style="color: #66cc66;">)</span>;

<span style="font-style: italic; color: #808080;">// soap action to operation map</span>
<span style="color: #0000ff;">$actions</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"http://localhost/samples/echo_service/echoString"</span> =&gt; <span style="color: #ff0000;">"echoString"</span>,
                 <span style="color: #ff0000;">"http://localhost/samples/echo_service/echoInt"</span> =&gt; <span style="color: #ff0000;">"echoInt"</span><span style="color: #66cc66;">)</span>;

<span style="font-style: italic; color: #808080;">// creating the service with the operations and actions set</span>
<span style="color: #0000ff;">$service</span> = <span style="font-weight: bold; color: #000000;">new</span> WSService<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;">"operations"</span> =&gt; <span style="color: #0000ff;">$operations</span>,
                               <span style="color: #ff0000;">"actions"</span> =&gt; <span style="color: #0000ff;">$actions</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>;</pre>
<p>Note that this code is same as the code I post in a previous blog &#8220;<a href="http://www.dimuthu.org/blog/2008/11/25/the-use-of-soap-action-with-wsfphp/">The Use of SOAP Action with WSF/PHP</a>&#8221; which uses SOAP action to dispatch the operation. In fact WSService will adjust to dispatch SOAP messages, so if there is a SOAP action in the message, it will be dispatched using that, and if it contains WS-Addressing action, it will used to do dispatching without the need of writing a single additional line of code. Note that this same code for both &#8220;submission&#8221; and &#8220;1.0&#8243; WS-Addressing versions.</li>
<li>In a WSDL 1.1, WS-Addressing action can be declared in the message element in the portType section.
<pre class="xml">    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;wsdl:portType</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"echoPortType"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;wsdl:operation</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"echoString"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;wsdl:input</span> <span style="color: #000066;">message</span>=<span style="color: #ff0000;">"ns0:echoStringRequest"</span> <span style="color: #000066;">wsaw:Action</span>=<span style="color: #ff0000;">"http://localhost/samples/echo_service/echoString"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;wsdl:output</span> <span style="color: #000066;">message</span>=<span style="color: #ff0000;">"ns0:echoStringResponse"</span> <span style="color: #000066;">wsaw:Action</span>=<span style="color: #ff0000;">"http://localhost/samples/echo_service/echoStringResponse"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/wsdl:operation<span style="font-weight: bold; color: black;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;wsdl:operation</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"echoInt"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;wsdl:input</span> <span style="color: #000066;">message</span>=<span style="color: #ff0000;">"ns0:echoIntRequest"</span> <span style="color: #000066;">wsaw:Action</span>=<span style="color: #ff0000;">"http://localhost/samples/echo_service/echoInt"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;wsdl:output</span> <span style="color: #000066;">message</span>=<span style="color: #ff0000;">"ns0:echoIntResponse"</span> <span style="color: #000066;">wsaw:Action</span>=<span style="color: #ff0000;">"http://localhost/samples/echo_service/echoIntResponse"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/wsdl:operation<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/wsdl:portType<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>When you use WSF/PHP in wsdl mode, it will pick the action declared in the WSDL and set it in the SOAP message, if you have enabled the addressing for the WSClient by setting non-null value for &#8220;useWSA&#8221; option.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/11/26/5-facts-about-ws-addressing-action-in-wsfphp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

