<?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/"
	>

<channel>
	<title>Dimuthu's Blog</title>
	<atom:link href="http://www.dimuthu.org/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dimuthu.org</link>
	<description>Waiting for your comments</description>
	<pubDate>Mon, 05 Jan 2009 13:06:55 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<image>
  <link>http://www.dimuthu.org</link>
  <url>http://www.dimuthu.org/favicon.ico</url>
  <title>Dimuthu's Blog</title>
</image>
		<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[DataServices]]></category>

		<category><![CDATA[REST]]></category>

		<category><![CDATA[RESTful]]></category>

		<category><![CDATA[SOA]]></category>

		<category><![CDATA[SQL]]></category>

		<category><![CDATA[Tutorial/Guide]]></category>

		<category><![CDATA[WSDL]]></category>

		<category><![CDATA[database]]></category>

		<category><![CDATA[design]]></category>

		<category><![CDATA[php]]></category>

		<category><![CDATA[web services]]></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 both SOAP and RESTful form.
Use [...]]]></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>
		</item>
		<item>
		<title>RESTful PHP Web Services - 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[REST]]></category>

		<category><![CDATA[RESTful]]></category>

		<category><![CDATA[SOA]]></category>

		<category><![CDATA[design]]></category>

		<category><![CDATA[php]]></category>

		<category><![CDATA[review]]></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 - 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 - 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 - Resource Oriented Services, chapter6- Resource Oriented Clients and Services with Zend Framework and probably the chapter 7 - 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>
		</item>
		<item>
		<title>PHP Web Services - 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[SOA]]></category>

		<category><![CDATA[Tutorial/Guide]]></category>

		<category><![CDATA[php]]></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>
		</item>
		<item>
		<title>Making Good SOA Great - EBook From WSO2</title>
		<link>http://www.dimuthu.org/blog/2008/12/24/making-good-soa-great-ebook-from-wso2/</link>
		<comments>http://www.dimuthu.org/blog/2008/12/24/making-good-soa-great-ebook-from-wso2/#comments</comments>
		<pubDate>Wed, 24 Dec 2008 17:53:12 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
		
		<category><![CDATA[SOA]]></category>

		<category><![CDATA[carbon]]></category>

		<category><![CDATA[wso2]]></category>

		<category><![CDATA[component]]></category>

		<category><![CDATA[componentinzation]]></category>

		<category><![CDATA[ebook]]></category>

		<category><![CDATA[middleware]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=856</guid>
		<description><![CDATA[WSO2 has released an ebook &#8220;Making Good SOA Great -  The WSO2 Story of Componentization&#8221; explaining how componentizations of middleware will improve the adaption of SOA in an enterprise IT system. And it introduces how you implement it in real systems using  WSO2 carbon, the introducing WSO2 product of componentized SOA middleware.
You can [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://wso2.com/">WSO2</a> has released an ebook &#8220;<a href="http://wso2.org/project/carbon/making_good_soa_great.pdf">Making Good SOA Great -  The WSO2 Story of Componentization</a>&#8221; explaining how componentizations of middleware will improve the adaption of SOA in an enterprise IT system. And it introduces how you implement it in real systems using  WSO2 carbon, the introducing WSO2 product of componentized SOA middleware.</p>
<p>You can see the presentation introducing WSO2 carbon from here,<br />
<a title="Permanent Link to Introduction to WSO2 Carbon - Componentized SOA Platform" rel="bookmark" href="http://www.dimuthu.org/blog/2008/12/21/introduction-to-wso2-carbon-componentized-soa-platform/">Introduction to WSO2 Carbon - Componentized SOA Platform</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/12/24/making-good-soa-great-ebook-from-wso2/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Security Considerations in Firefox When Accessing Different Domains</title>
		<link>http://www.dimuthu.org/blog/2008/12/22/security-considerations-in-firefox-when-accessing-different-domains/</link>
		<comments>http://www.dimuthu.org/blog/2008/12/22/security-considerations-in-firefox-when-accessing-different-domains/#comments</comments>
		<pubDate>Mon, 22 Dec 2008 18:14:57 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
		
		<category><![CDATA[firefox]]></category>

		<category><![CDATA[javascript]]></category>

		<category><![CDATA[security]]></category>

		<category><![CDATA[domains]]></category>

		<category><![CDATA[external domains]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=843</guid>
		<description><![CDATA[If you are a web developer you may have experienced that there are many situations that you need to access remote domains for data sources. For an example if you are building a weather mashup, you may like to connect to some weather forecasting services like  http://www.weather.gov or http://weather.cnn.com/weather/forecast.jsp. Mostly these services are very simple, [...]]]></description>
			<content:encoded><![CDATA[<p>If you are a web developer you may have experienced that there are many situations that you need to access remote domains for data sources. For an example if you are building a weather mashup, you may like to connect to some weather forecasting services like  <a href="http://www.weather.gov">http://www.weather.gov</a> or <a href="http://weather.cnn.com/weather/forecast.jsp">http://weather.cnn.com/weather/forecast.jsp</a>. Mostly these services are very simple, so you can build these services from Javascript  itself. (FYI you can use the blog post, I wrote sometime back, <a href="http://www.dimuthu.org/blog/2008/12/11/calling-simple-web-services-from-javascript/">Calling Simple Web Services From Javascript</a>.) But browsers doesn&#8217;t make it this much straight forward.</p>
<p>For an example if you try running the following code, which basically do a simple AJAX call to an external domain,</p>
<pre class="javascript">    <span style="font-style: italic; color: #009900;">// some external domain</span>
    <span style="font-weight: bold; color: #003366;">var</span> url = <span style="color: #3366cc;">"http://test.dimuthu.org"</span>;

    <span style="font-style: italic; color: #009900;">// doing the ajax call</span>
    <span style="font-weight: bold; color: #003366;">var</span> req = <span style="font-weight: bold; color: #003366;">new</span> XMLHttpRequest<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;

    req.<span style="color: #000066;">open</span><span style="color: #66cc66;">(</span><span style="color: #3366cc;">"GET"</span>, url, <span style="font-weight: bold; color: #003366;">true</span><span style="color: #66cc66;">)</span>;
    req.<span style="color: #006600;">onreadystatechange</span> = <span style="font-weight: bold; color: #003366;">function</span> <span style="color: #66cc66;">(</span>e<span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>
        <span style="font-weight: bold; color: #000066;">if</span> <span style="color: #66cc66;">(</span>req.<span style="color: #006600;">readyState</span> == <span style="color: #cc0000;">4</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>
            <span style="font-weight: bold; color: #000066;">if</span><span style="color: #66cc66;">(</span>req.<span style="color: #000066;">status</span> == <span style="color: #cc0000;">200</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>
                <span style="color: #000066;">alert</span><span style="color: #66cc66;">(</span>req.<span style="color: #006600;">responseText</span><span style="color: #66cc66;">)</span>;
            <span style="color: #66cc66;">}</span>
        <span style="color: #66cc66;">}</span>
    <span style="color: #66cc66;">}</span>

    req.<span style="color: #006600;">send</span><span style="color: #66cc66;">(</span><span style="font-weight: bold; color: #003366;">null</span><span style="color: #66cc66;">)</span>;</pre>
<p>You will get a security exception from the Firefox (opera too gives a similar exception).</p>
<pre><span style="color: #ff0000;">uncaught exception: Access to restricted URI denied (NS_ERROR_DOM_BAD_URI)</span></pre>
<p>In order to avoid this, you have do some special work.</p>
<ol>
<li>You need to add the following code before doing any AJAX request to external domains, This will give the script special privileges to access any domain through XMLHttpRequest object.
<pre class="javascript">    <span style="font-weight: bold; color: #000066;">try</span> <span style="color: #66cc66;">{</span>
        netscape.<span style="color: #006600;">security</span>.<span style="color: #006600;">PrivilegeManager</span>.<span style="color: #006600;">enablePrivilege</span><span style="color: #66cc66;">(</span><span style="color: #3366cc;">"UniversalBrowserRead"</span><span style="color: #66cc66;">)</span>;
    <span style="color: #66cc66;">}</span> <span style="font-weight: bold; color: #000066;">catch</span> <span style="color: #66cc66;">(</span>e<span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>
        <span style="color: #000066;">alert</span><span style="color: #66cc66;">(</span><span style="color: #3366cc;">"Permission UniversalBrowserRead denied."</span><span style="color: #66cc66;">)</span>;
    <span style="color: #66cc66;">}</span></pre>
</li>
<li> If your script always jump to the exception, you have to configure your browser to allow the above setting. You can do this by going to the &#8220;about:config&#8221; page in Firefox (Just type the &#8220;about:config&#8221; in the url field and hit Enter) where it shows a list of configurations, there you need to set &#8220;signed.applets.codebase_principal_support&#8221; field to &#8220;true&#8221;. By default this field is set to false in Firefox 3.0</li>
</ol>
<p>After you completed above 2 steps, the page will show you an warning message saying that it is asking more privileges, in which the client have to click the &#8220;allow&#8221; button to continue.</p>
<p>This procedure is not much difficult to setup, but still it will be really painful for an average user, so it is better you avoid this as much as possible in your code.</p>
<p>The main reason this special setup is arranged in Firefox (and most of the other browsers) is attackers can run malicious scripts in some page which you trust, (for an example from one of your email message) and send your private data to some other domain that you don&#8217;t know and don&#8217;t trust.</p>
<p>Apart from XMLHttpRequest another famous way of accessing different domains from a web page is using framesets or iframes. using this technique, You can show an external web page inside yours as it is one part of that.</p>
<p>Before Firefox 3.0 and IE 7.0 you were able to change that external page (appearance or the content) according to your need when it is shown in a frame or iframe. This was possible to do by manipulating the DOM of that external page. But with Firefox 3.0 and IE 7.0 it is impossible. That is you still you can show an external page inside your web page, but you can&#8217;t change anything of it even it shows inside your page. Because it doesn&#8217;t allow you to access the DOM of that external page. See this issue is discussed in details at here, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=397828">https://bugzilla.mozilla.org/show_bug.cgi?id=397828</a></p>
<p>With this improvement, you can&#8217;t call the <a href="http://developer.mozilla.org/en/docs/DOM:window.document">window.document</a> if the page of the window is from external domain.</p>
<p>The reason to this limitation is apparent, if you ever thought of modifying external pages and put it in your web page, you will be able feel many security holes in there. You can show some web based email login page in one of iframe, and fool some users. If that web based email application is not changed by the iframe container, it won&#8217;t be a problem, but how it is changed to submit your username, password to the parent site by updating the submit event (onclick attribute) of the DOM of that external page.</p>
<p>In fact Firefox and most of the browsers are trying to protect your from all these security attacks by restricting lot of functionalities of the browsers. They are doing what they can do it in the client side, but you don&#8217;t know what exactly happens in the server side since it is always a black box. The all the restriction mentioned above (i.e. accessing remote services, changing and showing an external web page) can be done in very simple PHP or .NET code in server side. So it is right that you should use the right tools, but more important thing is you are aware of these attacks and you selectively browse web while avoiding them</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/12/22/security-considerations-in-firefox-when-accessing-different-domains/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Introduction to WSO2 Carbon - Componentized SOA Platform</title>
		<link>http://www.dimuthu.org/blog/2008/12/21/introduction-to-wso2-carbon-componentized-soa-platform/</link>
		<comments>http://www.dimuthu.org/blog/2008/12/21/introduction-to-wso2-carbon-componentized-soa-platform/#comments</comments>
		<pubDate>Sun, 21 Dec 2008 13:48:13 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
		
		<category><![CDATA[DataServices]]></category>

		<category><![CDATA[SOA]]></category>

		<category><![CDATA[Tutorial/Guide]]></category>

		<category><![CDATA[carbon]]></category>

		<category><![CDATA[web services]]></category>

		<category><![CDATA[wso2]]></category>

		<category><![CDATA[introduction]]></category>

		<category><![CDATA[slideshow]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=837</guid>
		<description><![CDATA[&#8220;WSO2 carbon is a componentized, customizable SOA Platform, You can adapt the middleware to your enterprise architecture, rather than adapt your architecture to the middleware&#8221;.
The Carbon Story
]]></description>
			<content:encoded><![CDATA[<p>&#8220;WSO2 carbon is a componentized, customizable SOA Platform, You can adapt the middleware to your enterprise architecture, rather than adapt your architecture to the middleware&#8221;.</p>
<div id="__ss_855666" style="width: 425px; text-align: left;"><a style="font:14px Helvetica,Arial,Sans-serif;display:block;margin:12px 0 3px 0;text-decoration:underline;" title="The Carbon Story" href="http://www.slideshare.net/wso2.org/the-carbon-story-presentation-855666?type=powerpoint">The Carbon Story</a><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="355" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="src" value="http://static.slideshare.net/swf/ssplayer2.swf?doc=thecarbonstory-1229575799996446-2&amp;stripped_title=the-carbon-story-presentation-855666" /><embed type="application/x-shockwave-flash" width="425" height="355" src="http://static.slideshare.net/swf/ssplayer2.swf?doc=thecarbonstory-1229575799996446-2&amp;stripped_title=the-carbon-story-presentation-855666" allowscriptaccess="always" allowfullscreen="true"></embed></object></div>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/12/21/introduction-to-wso2-carbon-componentized-soa-platform/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Wordpress Database - Relationship with Tags, Catagories and Posts</title>
		<link>http://www.dimuthu.org/blog/2008/12/20/wordpress-database-relationship-with-tags-catagories-and-posts/</link>
		<comments>http://www.dimuthu.org/blog/2008/12/20/wordpress-database-relationship-with-tags-catagories-and-posts/#comments</comments>
		<pubDate>Sat, 20 Dec 2008 16:11:39 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
		
		<category><![CDATA[Tutorial/Guide]]></category>

		<category><![CDATA[database]]></category>

		<category><![CDATA[design]]></category>

		<category><![CDATA[php]]></category>

		<category><![CDATA[wordpress]]></category>

		<category><![CDATA[catgoary]]></category>

		<category><![CDATA[posts]]></category>

		<category><![CDATA[tag]]></category>

		<category><![CDATA[taxonomy]]></category>

		<category><![CDATA[term]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=825</guid>
		<description><![CDATA[Wordpress has a very simple database schema. And it is well documented. You can access the complete description of the wordpress core database from here, http://codex.wordpress.org/Database_Description.
Anyway first time I looked at the database I was confused with the term and the term_taxonomy table, why we need two tables for term and taxonomies. In fact in [...]]]></description>
			<content:encoded><![CDATA[<p>Wordpress has a very simple database schema. And it is well documented. You can access the complete description of the wordpress core database from here, <a href="http://codex.wordpress.org/Database_Description">http://codex.wordpress.org/Database_Description</a>.</p>
<p>Anyway first time I looked at the database I was confused with the term and the term_taxonomy table, why we need two tables for term and taxonomies. In fact in wordpress, the table &#8216;posts&#8217; is associated with the table &#8216;term_taxonomy&#8217; and not the table &#8216;term&#8217; itself. In the term taxonomy table the terms are associated to a link category, post category or a tag. So the associations of posts to a tag or category is something like this.</p>
<div id="attachment_828" class="wp-caption alignnone" style="width: 510px"><a href="http://www.dimuthu.org/wp-content/uploads/2008/12/wp_term_post_association.jpeg"><img class="size-full wp-image-828" title="wp_term_post_association" src="http://www.dimuthu.org/wp-content/uploads/2008/12/wp_term_post_association.jpeg" alt="wp_term_post association" width="500" height="136" /></a><p class="wp-caption-text">wp_term_post association</p></div>
<p>So in a case you try querying for posts with a given tag it will be like this. (Note that I have skipped the optional database table prefix which is by default &#8216;wp_&#8217;)</p>
<pre class="sql"><span style="font-weight: bold; color: #993333;">SELECT</span> post_title,
       post_content,
       post_date
<span style="font-weight: bold; color: #993333;">FROM</span> posts p,
     terms t,
     term_relationships r,
     term_taxonomy tt
<span style="font-weight: bold; color: #993333;">WHERE</span> p.post_status=<span style="color: #ff0000;">'publish'</span> <span style="font-weight: bold; color: #993333;">AND</span>
      tt.taxonomy = <span style="color: #ff0000;">'post_tag'</span> <span style="font-weight: bold; color: #993333;">AND</span>
      p.id=r.object_id <span style="font-weight: bold; color: #993333;">AND</span>
      r.term_taxonomy_id=tt.term_taxonomy_id <span style="font-weight: bold; color: #993333;">AND</span>
      tt.term_id = t.term_id <span style="font-weight: bold; color: #993333;">AND</span> t.name <span style="font-weight: bold; color: #993333;">LIKE</span> ?</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/12/20/wordpress-database-relationship-with-tags-catagories-and-posts/feed/</wfw:commentRss>
		</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[DataServices]]></category>

		<category><![CDATA[SOA]]></category>

		<category><![CDATA[SQL]]></category>

		<category><![CDATA[Tutorial/Guide]]></category>

		<category><![CDATA[data services]]></category>

		<category><![CDATA[design]]></category>

		<category><![CDATA[php]]></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 (&#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>
		</item>
		<item>
		<title>Sending Encrypted Binary Messages With PHP Web Services</title>
		<link>http://www.dimuthu.org/blog/2008/12/14/sending-encrypted-binary-messages-with-php-web-services/</link>
		<comments>http://www.dimuthu.org/blog/2008/12/14/sending-encrypted-binary-messages-with-php-web-services/#comments</comments>
		<pubDate>Sun, 14 Dec 2008 17:51:04 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
		
		<category><![CDATA[SOA]]></category>

		<category><![CDATA[Tutorial/Guide]]></category>

		<category><![CDATA[php]]></category>

		<category><![CDATA[security]]></category>

		<category><![CDATA[web services]]></category>

		<category><![CDATA[wsf/php]]></category>

		<category><![CDATA[wso2]]></category>

		<category><![CDATA[Attachment]]></category>

		<category><![CDATA[base64]]></category>

		<category><![CDATA[encryption]]></category>

		<category><![CDATA[MIME]]></category>

		<category><![CDATA[mtom]]></category>

		<category><![CDATA[policy]]></category>

		<category><![CDATA[secuirty token]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=797</guid>
		<description><![CDATA[Web services has made the communication between heterogeneous environments (say PHP with .NET  or Java) a reality. It has defines standards for communicate not only with texts but also with binaries. And more importantly you can keep these communication confidential using encrypted messages according to your requirement. In this post, we will look at how [...]]]></description>
			<content:encoded><![CDATA[<p>Web services has made the communication between heterogeneous environments (say PHP with .NET  or Java) a reality. It has defines standards for communicate not only with texts but also with binaries. And more importantly you can keep these communication confidential using encrypted messages according to your requirement. In this post, we will look at how we can implement such a system with PHP in one side.</p>
<p>In web services we can send/receive binary messages in two basic forms.</p>
<ol>
<li>Setting the binary inside the SOAP message. - Binary should be converted to base64 to make sure the SOAP body contains only texts. Since base64 converted data span longer than the binary data, we call this form as non-optimized way of sending binaries.</li>
<li>Setting the binary outside the SOAP message - Binary would be sent as a MIME part in the message. And some element inside SOAP body keeps a reference to the binary using the MIME id. MTOM is a standard for referencing the MIME from inside the SOAP body. Since the binary is encoded, this will keep the message optimum with the binaries.</li>
</ol>
<p>In <a href="http://wso2.org/projects/wsf/php">WSF/PHP</a> you can use any of these methods as you prefer. Lets forget about the encryption for now. We will check how we can send binaries in both of the above mentioned forms.</p>
<pre class="php"><span style="font-style: italic; color: #808080;">// first the request xml. Note tht xop:Include element that is referring the attachment with the id "myid1".</span>
<span style="color: #0000ff;">$reqPayloadString</span> = &lt;&lt;&lt;XML
&lt;ns1:upload xmlns:ns1=<span style="color: #ff0000;">"http://wso2.org/wsfphp/samples/mtom"</span>&gt;
               &lt;ns1:fileName&gt;test.jpg&lt;/ns1:fileName&gt;
               &lt;ns1:image xmlmime:contentType=<span style="color: #ff0000;">"image/jpeg"</span> xmlns:xmlmime=<span style="color: #ff0000;">"http://www.w3.org/2004/06/xmlmime"</span>&gt;
                  &lt;xop:<span style="color: #b1b100;">Include</span> xmlns:xop=<span style="color: #ff0000;">"http://www.w3.org/2004/08/xop/include"</span> href=<span style="color: #ff0000;">"cid:myid1"</span>&gt;&lt;/xop:Include&gt;
               &lt;/ns1:image&gt;
&lt;/ns1:upload&gt;
XML;

try <span style="color: #66cc66;">{</span>
    <span style="color: #0000ff;">$f</span> = <a href="http://www.php.net/file_get_contents"><span style="color: #000066;">file_get_contents</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"my_binary_file.jpg"</span><span style="color: #66cc66;">)</span>;

    <span style="font-style: italic; color: #808080;">// here in the attachments option we define the binaries</span>
    <span style="font-style: italic; color: #808080;">// corresponding to the id defined in the above XML</span>
    <span style="color: #0000ff;">$reqMessage</span> = <span style="font-weight: bold; color: #000000;">new</span> WSMessage<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$reqPayloadString</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/simple_upload_service.php"</span>,
                                      <span style="color: #ff0000;">"action"</span> =&gt; <span style="color: #ff0000;">"http://wso2.org/upload"</span>,
                                      <span style="color: #ff0000;">"attachments"</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;">"myid1"</span> =&gt; <span style="color: #0000ff;">$f</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;

    <span style="font-style: italic; color: #808080;">// creating the WSClient</span>
    <span style="font-style: italic; color: #808080;">// here the option useMTOM will decide whether the</span>
    <span style="font-style: italic; color: #808080;">// attachment is set MTOM or base64</span>
    <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;">"useWSA"</span> =&gt; <span style="font-weight: bold; color: #000000;">TRUE</span>,
                                 <span style="color: #ff0000;">"useMTOM"</span> =&gt; <span style="font-weight: bold; color: #000000;">TRUE</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;

    <span style="font-style: italic; color: #808080;">// sending the message and retrieving the response</span>
    <span style="color: #0000ff;">$resMessage</span> = <span style="color: #0000ff;">$client</span>-&gt;<span style="color: #006600;">request</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$reqMessage</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 <span style="font-weight: bold; color: #000099;">\\</span>n"</span>, <span style="color: #0000ff;">$resMessage</span>-&gt;<span style="color: #006600;">str</span><span style="color: #66cc66;">)</span>;

<span style="color: #66cc66;">}</span> catch <span style="color: #66cc66;">(</span>Exception <span style="color: #0000ff;">$e</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>

    <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span><span style="color: #0000ff;">$e</span> instanceof WSFault<span style="color: #66cc66;">)</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;">"Soap Fault: %s<span style="font-weight: bold; color: #000099;">\\</span>n"</span>, <span style="color: #0000ff;">$e</span>-&gt;<span style="color: #006600;">Reason</span><span style="color: #66cc66;">)</span>;
    <span style="color: #66cc66;">}</span> <span style="color: #b1b100;">else</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;">"Message = %s<span style="font-weight: bold; color: #000099;">\\</span>n"</span>,<span style="color: #0000ff;">$e</span>-&gt;<span style="color: #006600;">getMessage</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;
    <span style="color: #66cc66;">}</span>
<span style="color: #66cc66;">}</span></pre>
<p>As mentioned in the inline comment we can choose the preferred form of sending binary using the &#8220;useMTOM&#8221; option. if it is true, the binary is set as a MTOM, (referencing from the body) or if it is set false, the binary will be set as a base64 binary within the SOAP body.<br />
To encrypt the message you only need to write few additional lines. First you define your policy that you need to encrypt this message using a WSPolicy object. Then the security token including the service public key and your private key. You need to give these two option as a constructor argument in WSClient. Here is that little additional code you need to write to add the encryption.</p>
<pre class="php">    <span style="font-style: italic; color: #808080;">// loading the keys</span>
    <span style="color: #0000ff;">$rec_cert</span> = ws_get_cert_from_file<span style="color: #66cc66;">(</span><span style="color: #ff0000;">"receiving_server.cert"</span><span style="color: #66cc66;">)</span>;
    <span style="color: #0000ff;">$pvt_key</span> = ws_get_key_from_file<span style="color: #66cc66;">(</span><span style="color: #ff0000;">"my_private_key.pem"</span><span style="color: #66cc66;">)</span>;

    <span style="font-style: italic; color: #808080;">// here we defines the policies and create WSPolicy object</span>
    <span style="color: #0000ff;">$sec_array</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"encrypt"</span> =&gt; <span style="font-weight: bold; color: #000000;">TRUE</span>,
                       <span style="color: #ff0000;">"algorithmSuite"</span> =&gt; <span style="color: #ff0000;">"Basic256Rsa15"</span>,
                       <span style="color: #ff0000;">"securityTokenReference"</span> =&gt; <span style="color: #ff0000;">"IssuerSerial"</span><span style="color: #66cc66;">)</span>;

    <span style="color: #0000ff;">$policy</span> = <span style="font-weight: bold; color: #000000;">new</span> WSPolicy<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;">"security"</span> =&gt; <span style="color: #0000ff;">$sec_array</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;

    <span style="font-style: italic; color: #808080;">// defining Security Tokens</span>
    <span style="color: #0000ff;">$sec_token</span> = <span style="font-weight: bold; color: #000000;">new</span> WSSecurityToken<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;">"privateKey"</span> =&gt; <span style="color: #0000ff;">$pvt_key</span>,
                                           <span style="color: #ff0000;">"receiverCertificate"</span> =&gt; <span style="color: #0000ff;">$rec_cert</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;

    <span style="font-style: italic; color: #808080;">// modifing WSClient with adding WSPolicy and WSSecurityToken object</span>
    <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;">"useWSA"</span> =&gt; <span style="font-weight: bold; color: #000000;">TRUE</span>,
                                 <span style="color: #ff0000;">"useMTOM"</span> =&gt; <span style="font-weight: bold; color: #000000;">TRUE</span>,
                                 <span style="color: #ff0000;">"policy"</span> =&gt; <span style="color: #0000ff;">$policy</span>,
                                 <span style="color: #ff0000;">"securityToken"</span> =&gt; <span style="color: #0000ff;">$sec_token</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;</pre>
<p>You can implement the receiving side of the message similar to the sending side that we just described above. The most important thing is it doesn&#8217;t need to be written in PHP. It can be a Java code or .NET code.If you already have web services that use encrypted binary messaging, the above php code can be use out of the box to communicate with it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/12/14/sending-encrypted-binary-messages-with-php-web-services/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Calling Simple Web Services From Javascript</title>
		<link>http://www.dimuthu.org/blog/2008/12/11/calling-simple-web-services-from-javascript/</link>
		<comments>http://www.dimuthu.org/blog/2008/12/11/calling-simple-web-services-from-javascript/#comments</comments>
		<pubDate>Thu, 11 Dec 2008 12:00:59 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
		
		<category><![CDATA[SOA]]></category>

		<category><![CDATA[Tutorial/Guide]]></category>

		<category><![CDATA[javascript]]></category>

		<category><![CDATA[mashup server]]></category>

		<category><![CDATA[php]]></category>

		<category><![CDATA[web services]]></category>

		<category><![CDATA[mashup]]></category>

		<category><![CDATA[SOAP]]></category>

		<category><![CDATA[web applications]]></category>

		<category><![CDATA[WSRequest]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=785</guid>
		<description><![CDATA[If you are a web developer, you may have found many occasions you have to create simple mashups for your web site. There you call web services or data services to fill the content of the web page. Most of the time we call web services from a server side script, since there are many [...]]]></description>
			<content:encoded><![CDATA[<p>If you are a web developer, you may have found many occasions you have to create simple mashups for your web site. There you call web services or data services to fill the content of the web page. Most of the time we call web services from a server side script, since there are many server side technologies like Java, PHP, .NET support web services.</p>
<p>But sometime it is in vain that you call your server scripts for a simple web service request. In fact You can use the famous XMLHttpRequest object to do the same thing from the client side itself. But you may need to prepare the complete SOAP envelope (Yea with SOAP headers, if required) in your hand to send it through XMLHttpRequest.</p>
<p>Another option is to  use the WSRequest script (<a href="http://mooshup.com/js/wso2/WSRequest.js">http://mooshup.com/js/wso2/WSRequest.js</a>). We normally use this script in the <a href="http://wso2.org/projects/mashup">WSO2 Mashup Server</a> to call the mashups designed in the serverside using stub. (The server side mashup is also mostly written in Javascript). We can use this script stand alone to call remote web services as well.</p>
<p>It introduce you the WSRequest class. It is exactly similar to the famous XMLHttpRequest class we used in  AJAX. In stead of plain message over HTTP like in the case of XMLHttpRequest, WSRequest send and receive messages in SOAP form. Here is its API in brief.</p>
<pre class="javascript"><span style="font-weight: bold; color: #003366;">var</span> WSRequest = <span style="font-weight: bold; color: #003366;">function</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>
    <span style="font-style: italic; color: #009900;">//----------------------------------------------------</span>
    <span style="font-style: italic; color: #009900;">// the public properties - equivalent to XMLHTTPRequest</span>
    <span style="font-style: italic; color: #009900;">//-----------------------------------------------------</span>
    <span style="font-weight: bold; color: #000066;">this</span>.<span style="color: #006600;">readyState</span> = <span style="color: #cc0000;">0</span>;
    <span style="font-weight: bold; color: #000066;">this</span>.<span style="color: #006600;">responseText</span> = <span style="font-weight: bold; color: #003366;">null</span>;
    <span style="font-weight: bold; color: #000066;">this</span>.<span style="color: #006600;">responseXML</span> = <span style="font-weight: bold; color: #003366;">null</span>;
    <span style="font-weight: bold; color: #000066;">this</span>.<span style="color: #006600;">error</span> = <span style="font-weight: bold; color: #003366;">null</span>;  <span style="font-style: italic; color: #009900;">// equivalent to httpErrorCode</span>
    <span style="font-weight: bold; color: #000066;">this</span>.<span style="color: #006600;">onreadystatechange</span> = <span style="font-weight: bold; color: #003366;">null</span>;
    <span style="font-weight: bold; color: #000066;">this</span>.<span style="color: #006600;">proxyAddress</span> = <span style="font-weight: bold; color: #003366;">null</span>;
    <span style="font-weight: bold; color: #000066;">this</span>.<span style="color: #006600;">proxyEngagedCallback</span> = <span style="font-weight: bold; color: #003366;">null</span>
<span style="color: #66cc66;">}</span>

<span style="font-style: italic; color: #009900;">//----------------------------------------------------</span>
<span style="font-style: italic; color: #009900;">// the public operations - equivalent to XMLHTTPRequest</span>
<span style="font-style: italic; color: #009900;">//-----------------------------------------------------</span>

<span style="font-style: italic; color: #009900;">/**
 * @description Prepare a Web Service Request .
 * @method open
 * @param {hash} options,
 *   possible options: possible values for the option
 *            useSOAP : false/true/1.1/1.2
 *            useWSA : true/false/1.0/submission
 *            useWSS : true/false (only for usernametoken &amp; timestamp)
 *
 * @param {string} URL
 * @param {boolean} asyncFlag
 * @param {string} username
 * @param {string} password
 */</span>
WSRequest.<span style="color: #006600;">prototype</span>.<span style="color: #000066;">open</span> = <span style="font-weight: bold; color: #003366;">function</span><span style="color: #66cc66;">(</span>options, URL, asnycFlag, username, password<span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>.. <span style="color: #66cc66;">}</span>

<span style="font-style: italic; color: #009900;">/**
 * @description Send the payload to the Web Service.
 * @method send
 * @param {dom} response xml payload
 */</span>
WSRequest.<span style="color: #006600;">prototype</span>.<span style="color: #006600;">send</span> = <span style="font-weight: bold; color: #003366;">function</span><span style="color: #66cc66;">(</span>payload<span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>.. <span style="color: #66cc66;">}</span></pre>
<p>I wrote a simple javascript/html demo which calls the data service that I published for my blog. This service is written using <a href="http://wso2.org/projects/wsf/php">WSF/PHP</a> Data Services. Check the demo and client, service sources  from the following links.</p>
<table border="0">
<tbody>
<tr>
<td class="first">AJAX Tag Search</td>
<td class="second"><a href="http://ws.dimuthu.org/blog/WordpressTagSearchJSClientNoAuth.html">Demo</a> |  <a href="http://ws.dimuthu.org/blog/WordpressTagSearchServiceNoAuth.php?wsdl">WSDL</a><a> | </a><a href="http://ws.dimuthu.org/source.php?src=tag.search.NoAuthclient">Client</a> |  <a href="http://ws.dimuthu.org/source.php?src=tag.search.NoAuthservice">Service</a></td>
<td class="third">Demonstrates how you use SOAP Data Services using WSRequest object to retrieve the data asynchronously from javascript</td>
</tr>
</tbody>
</table>
<p>There You can see, how easy to write an AJAX like page for call web services using the WSRequest javascript class.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/12/11/calling-simple-web-services-from-javascript/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 6.173 seconds -->
<!-- Cached page served by WP-Cache -->
