<?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; web services</title>
	<atom:link href="http://www.dimuthu.org/tag/web-services/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dimuthu.org</link>
	<description>Waiting for your comments</description>
	<lastBuildDate>Wed, 07 Jul 2010 12:42:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
<image>
  <link>http://www.dimuthu.org</link>
  <url>http://www.dimuthu.org/favicon.ico</url>
  <title>Dimuthu's Blog</title>
</image>
		<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>0</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[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 [...]]]></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>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[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>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Detect Replay Attacks In to Your PHP Web Service</title>
		<link>http://www.dimuthu.org/blog/2008/11/17/detect-replay-attacks-in-to-your-php-web-service/</link>
		<comments>http://www.dimuthu.org/blog/2008/11/17/detect-replay-attacks-in-to-your-php-web-service/#comments</comments>
		<pubDate>Mon, 17 Nov 2008 17:47:11 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<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[replay detect]]></category>
		<category><![CDATA[replay detection]]></category>
		<category><![CDATA[ws-security]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=631</guid>
		<description><![CDATA[Replay attack is a common kind of attack, the hackers are using to break the security of a web service. If you can intercept one soap message while it is transferring through the wire, you can replay that message to the server again and again. Since the original message may have already encrypted, signed and [...]]]></description>
			<content:encoded><![CDATA[<p>Replay attack is a common kind of attack, the hackers are using to break the security of a web service.</p>
<p>If you can intercept one soap message while it is transferring through the wire, you can replay that message to the server again and again. Since the original message may have already encrypted, signed and contain valid authentication credentials the replaying messages will also be able to pass all the security tests and fool the server and do enormous damages to the business. For an example think of replying a soap message that a client is conducting a payment with a e-commerce service. The service may tend to charge the client multiple times for each request which break the integrity of the business.</p>
<p>So it is no doubt when ever you thinking of designing an enterprise web service application, you should give attention to &#8216;Replay Detection&#8217; more seriously.</p>
<p>One solution is you can handle the replay detection inside the business logic itself. If you do this for the above mentioned e-commerce like services, you will keep all the session ids and make sure only one payment is possible for one session. But this may need some really careful design of the application logic.</p>
<p>The other solution is to let your web service framework to handle the &#8216;Replay Detection&#8217;. That will clearly separate the security aspects from the business aspects of your service. And it will give you more flexibility in configuring your security requirements. And the other advantage is it will detect &#8216;Replay Attacks&#8217; well before hitting the business logic, making the web service perform well.</p>
<p><a href="http://wso2.org/projects/wsf/php">WSF/PHP </a>allows you to detect replay attacks using WS-Addressing and WS-Username token headers. WS-Addressing headers contains a message id which can be considered as unique to a soap message and ws-security headers contains created time of the message which can be used to calculate the age of the message and derive its validity.</p>
<p>WSF/PHP provide web service developer a callback with the &#8216;message id&#8217; and the &#8216;message created time&#8217;  per each message. In the callback you can store this message id and created time in a database, and check them against all the incoming soap messages. If it found duplicate entries, you can consider it as a replay attack.</p>
<p>Here is an example draft of the above scenario written using WSF/PHP.</p>
<pre class="php"><span style="font-style: italic; color: #808080;">/* replay detection callback */</span>
<span style="font-weight: bold; color: #000000;">function</span> replay_detect_callback<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$msg_id</span>, <span style="color: #0000ff;">$time_created</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>
    <span style="font-style: italic; color: #808080;">/* Here is the pseudo code of the logic

    query for the $msg_id and $time_created for the database.
    if already exist
      return FALSE;
    else
      Insert message id and time created to the database
    return TRUE */</span>
<span style="color: #66cc66;">}</span>

<span style="color: #0000ff;">$security_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="font-style: italic; color: #808080;"> </span>
                      <span style="color: #ff0000;">"replayDetectionCallback"</span> =&gt; <span style="color: #ff0000;">"replay_detect_callback"</span>,
                      <span style="color: #ff0000;">"enableReplayDetect"</span> =&gt; <span style="font-weight: bold; color: #000000;">TRUE</span>,<span style="color: #66cc66;">
                      </span><span style="font-style: italic; color: #808080;">/* Other tokens */</span><span style="color: #66cc66;"> </span><span><span style="color: #66cc66;">)</span></span><span style="color: #66cc66;">)</span>;

<span style="color: #0000ff;">$svr</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;">"securityToken"</span> =&gt; <span style="color: #0000ff;">$security_token</span>,<span style="color: #66cc66;">
                      </span><span style="font-style: italic; color: #808080;">/* Other options*/</span><span style="color: #66cc66;"> </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></pre>
<p>So if you use this code in the service you can happily detect any replays of an old message and avoid possible damages. But remember this security check will work only if the replaying message contain the same message id and the created time as the original one. It is possible that an intruder not only intercept the message, but also change these fields and replay it in to your server. Such replays will not be detected from this code.</p>
<p>The solution is to sign each SOAP requests. If a client sign a message with his private key, the server can confirm that the message is not altered while it is on the wire. So if intruder replay a signed message, either it will fail the replay detection test (if it is replaying without changing the message id and created time) or it will fail validating the signature (if the message id and the created time is altered).</p>
<p>So if you implement a replay detection test with a signature test, you can eliminate all the replay attacks to your service (at least theoretically <img src='http://www.dimuthu.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/11/17/detect-replay-attacks-in-to-your-php-web-service/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Sending Custom SOAP Headers in PHP Web Services</title>
		<link>http://www.dimuthu.org/blog/2008/11/03/sending-custom-soap-headers-in-php-web-services/</link>
		<comments>http://www.dimuthu.org/blog/2008/11/03/sending-custom-soap-headers-in-php-web-services/#comments</comments>
		<pubDate>Mon, 03 Nov 2008 17:24:12 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[WSDL]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[xml schema]]></category>
		<category><![CDATA[custom headers]]></category>
		<category><![CDATA[Sending]]></category>
		<category><![CDATA[SOAP headers]]></category>
		<category><![CDATA[WSHeader]]></category>
		<category><![CDATA[WSMessage]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=572</guid>
		<description><![CDATA[Few months ago, I blogged about How you represent custom headers in a WSDL. In there I mentioned, WSF/PHP is going to support sending and handling custom SOAP headers with the 2.0 release which was released early September. Today I will write how how to use this new feature in your Web Service Client. In [...]]]></description>
			<content:encoded><![CDATA[<p>Few months ago, I blogged about <a href="http://www.dimuthu.org/blog/2008/08/21/how-to-build-custom-soap-headers-in-wsdl-using-axis2c-and-wsfphp/">How you represent custom headers in a WSDL</a>. In there I mentioned, <a href="http://wso2.org/projects/wsf/php">WSF/PHP</a> is going to support sending and handling custom SOAP headers with the 2.0 release which was released early September. Today I will write how how to use this new feature in your Web Service Client.</p>
<p>In order to do the comparison I will show you how you could send Custom SOAP headers before WSF/PHP 2.0.</p>
<p><strong>Preparing Custom SOAP Headers Manually<br />
</strong></p>
<p>Before 2.0 you have to prepare the custom SOAP headers manually. For that you could use the WSHeader object.</p>
<p>Say you want to create the following message for your WSDL. (I excluded the headers and payload namespaces for the clarity)</p>
<pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;soapenv:Envelope</span> <span style="color: #000066;">xmlns:soapenv</span>=<span style="color: #ff0000;">"http://www.w3.org/2003/05/soap-envelope"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
   <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;soapenv:Header<span style="font-weight: bold; color: black;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;Header1<span style="font-weight: bold; color: black;">&gt;</span></span></span>
         <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;string<span style="font-weight: bold; color: black;">&gt;</span></span></span>test1<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/string<span style="font-weight: bold; color: black;">&gt;</span></span></span>
         <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;int<span style="font-weight: bold; color: black;">&gt;</span></span></span>5<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/int<span style="font-weight: bold; color: black;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/Header1<span style="font-weight: bold; color: black;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;Header2<span style="font-weight: bold; color: black;">&gt;</span></span></span>
         <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;int<span style="font-weight: bold; color: black;">&gt;</span></span></span>6<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/int<span style="font-weight: bold; color: black;">&gt;</span></span></span>
         <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;string<span style="font-weight: bold; color: black;">&gt;</span></span></span>test2<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/string<span style="font-weight: bold; color: black;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/Header2<span style="font-weight: bold; color: black;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/soapenv:Header<span style="font-weight: bold; color: black;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;soapenv:Body<span style="font-weight: bold; color: black;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;echo<span style="font-weight: bold; color: black;">&gt;</span></span></span>Hello<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/echo<span style="font-weight: bold; color: black;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/soapenv:Body<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/soapenv:Envelope<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>Here is how you prepare it using WSMessage and WSHeader objects.</p>
<pre class="php"><span style="font-style: italic; color: #808080;">// request payload</span>
<span style="color: #0000ff;">$requestPayloadString</span> = &lt;&lt;&lt;XML
<span style="color: #ff0000;">&lt;echo&gt;Hello&lt;/echo&gt;</span>
XML;

<span style="font-style: italic; color: #808080;">// creation of two headers</span>
<span style="color: #0000ff;">$header1</span> = <span style="font-weight: bold; color: #000000;">new</span> WSHeader<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;">"name"</span> =&gt; <span style="color: #ff0000;">"Header1"</span>,
			<span style="color: #ff0000;">"data"</span> =&gt; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span>
				<span style="font-weight: bold; color: #000000;">new</span> WSHeader<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;">"name"</span> =&gt; <span style="color: #ff0000;">"string"</span>,
						<span style="color: #ff0000;">"data"</span> =&gt; <span style="color: #ff0000;">"test1"</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>,
				<span style="font-weight: bold; color: #000000;">new</span> WSHeader<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;">"name"</span> =&gt; <span style="color: #ff0000;">"int"</span>,
						<span style="color: #ff0000;">"data"</span> =&gt; <span style="color: #ff0000;">"5"</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>;

<span style="color: #0000ff;">$header2</span> = <span style="font-weight: bold; color: #000000;">new</span> WSHeader<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;">"name"</span> =&gt; <span style="color: #ff0000;">"Header2"</span>,
			<span style="color: #ff0000;">"data"</span> =&gt; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span>
				<span style="font-weight: bold; color: #000000;">new</span> WSHeader<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;">"name"</span> =&gt; <span style="color: #ff0000;">"int"</span>,
						<span style="color: #ff0000;">"data"</span> =&gt; <span style="color: #ff0000;">"6"</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>,
				<span style="font-weight: bold; color: #000000;">new</span> WSHeader<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;">"name"</span> =&gt; <span style="color: #ff0000;">"string"</span>,
						<span style="color: #ff0000;">"data"</span> =&gt; <span style="color: #ff0000;">"test2"</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>;

<span style="font-style: italic; color: #808080;">// you prepare the soap message = request payload + two input headers</span>
<span style="color: #0000ff;">$request_msg</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;">"inputHeaders"</span> =&gt; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$header1</span>, <span style="color: #0000ff;">$header2</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;

<span style="font-style: italic; color: #808080;">// create the WSClient with the endpoint</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;">"to"</span> =&gt; <span style="color: #ff0000;">"http://localhost/header_echo_service.php"</span> <span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;

<span style="font-style: italic; color: #808080;">// do the request with the WSMessage instance as the request argument</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;">$request_msg</span><span style="color: #66cc66;">)</span>;

<span style="font-style: italic; color: #808080;">// print the response</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>As you can see you are preparing hierarchical tree of WSHeaders to prepare the SOAP message. Anyway after 2.0 you don&#8217;t need to write this much of code to get the work done.</p>
<p><strong>Preparing Custom SOAP Headers in WSDL Mode</strong></p>
<p>If you have a WSDL it is so easy to start by generating the initial code from the WSDL2PHP tool. If I take the WSDL from <a href="http://www.dimuthu.org/blog/2008/08/21/how-to-build-custom-soap-headers-in-wsdl-using-axis2c-and-wsfphp/">my old post about custom headers in WSDL </a>WSDL2PHP tool will generate the following set of classes.</p>
<pre class="php"><span style="font-weight: bold; color: #000000;">class</span> Header1 <span style="color: #66cc66;">{</span>

    <span style="font-style: italic; color: #808080;">/**
     * @var string
     */</span>
    <span style="font-weight: bold; color: #000000;">public</span> <span style="color: #0000ff;">$string</span>;

    <span style="font-style: italic; color: #808080;">/**
     * @var int
     */</span>
    <span style="font-weight: bold; color: #000000;">public</span> <span style="color: #0000ff;">$int</span>;

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

<span style="font-weight: bold; color: #000000;">class</span> Header2 <span style="color: #66cc66;">{</span>

    <span style="font-style: italic; color: #808080;">/**
     * @var int
     */</span>
    <span style="font-weight: bold; color: #000000;">public</span> <span style="color: #0000ff;">$int</span>;

    <span style="font-style: italic; color: #808080;">/**
     * @var string
     */</span>
    <span style="font-weight: bold; color: #000000;">public</span> <span style="color: #0000ff;">$string</span>;

<span style="color: #66cc66;">}</span></pre>
<p>And you will get the following piece of code with the Note &#8220;TODO&#8221; where you need to fill the input fields and retrive the output values from the operation.</p>
<pre class="php">    <span style="font-style: italic; color: #808080;">// create input object and set values</span>
    <span style="font-style: italic; color: #808080;">//TODO: fill $input with (data type: string) data to match your business logic</span>

    <span style="color: #0000ff;">$header_in0</span> = <span style="font-weight: bold; color: #000000;">new</span> Header1<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;
    <span style="font-style: italic; color: #808080;">// TODO: fill in the class fields of $header_in0 object which is of type Header1 to match your business logic</span>

    <span style="color: #0000ff;">$header_in1</span> = <span style="font-weight: bold; color: #000000;">new</span> Header2<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;
    <span style="font-style: italic; color: #808080;">// TODO: fill in the class fields of $header_in1 object which is of type Header2 to match your business logic</span>

    <span style="font-style: italic; color: #808080;">// call the operation</span>
    <span style="color: #0000ff;">$response</span> = <span style="color: #0000ff;">$proxy</span>-&gt;<span style="color: #006600;">echoString</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$input</span>, <span style="color: #0000ff;">$header_in0</span>, <span style="color: #0000ff;">$header_in1</span>, &amp;<span style="color: #0000ff;">$header_out0</span>, &amp;<span style="color: #0000ff;">$header_out1</span><span style="color: #66cc66;">)</span>;
    <span style="font-style: italic; color: #808080;">//TODO: Implement business logic to consume $response, which is of type string</span>

    <span style="font-style: italic; color: #808080;">// TODO: Implement business logic to consume $header_out0 object, which is of type class Header1</span>

    <span style="font-style: italic; color: #808080;">// TODO: Implement business logic to consume $header_out1 object, which is of type class Header2</span></pre>
<p>After I follow the guidelines in the comment, My code looks so simple and little like this,</p>
<pre class="php">    <span style="font-style: italic; color: #808080;">// create input object and set values</span>
    <span style="color: #0000ff;">$input</span> = <span style="color: #ff0000;">"Hello"</span>; <span style="font-style: italic; color: #808080;">// I filled $input with a string</span>

    <span style="color: #0000ff;">$header_in0</span> = <span style="font-weight: bold; color: #000000;">new</span> Header1<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>; <span style="font-style: italic; color: #808080;">// I m filling the header1</span>
    <span style="color: #0000ff;">$header_in0</span>-&gt;<span style="color: #006600;">string</span> = <span style="color: #ff0000;">"test1"</span>;
    <span style="color: #0000ff;">$header_in0</span>-&gt;<span style="color: #006600;">int</span> = <span style="color: #cc66cc;">5</span>;

    <span style="color: #0000ff;">$header_in1</span> = <span style="font-weight: bold; color: #000000;">new</span> Header2<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>; <span style="font-style: italic; color: #808080;">// now the header2;</span>
    <span style="color: #0000ff;">$header_in1</span>-&gt;<span style="color: #006600;">string</span> = <span style="color: #ff0000;">"test2"</span>;
    <span style="color: #0000ff;">$header_in1</span>-&gt;<span style="color: #006600;">int</span> = <span style="color: #cc66cc;">6</span>;

    <span style="font-style: italic; color: #808080;">// call the operation</span>
    <span style="color: #0000ff;">$response</span> = <span style="color: #0000ff;">$proxy</span>-&gt;<span style="color: #006600;">echoString</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$input</span>, <span style="color: #0000ff;">$header_in0</span>, <span style="color: #0000ff;">$header_in1</span>, &amp;<span style="color: #0000ff;">$header_out0</span>, &amp;<span style="color: #0000ff;">$header_out1</span><span style="color: #66cc66;">)</span>;

    <span style="font-style: italic; color: #808080;">// echoing the response payload which of type string</span>
    <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #0000ff;">$response</span>;

    <span style="font-style: italic; color: #808080;">// echoing the $header_out0 object, which is of type class Header1</span>
    <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">"output header0 contains {$header_out0-&gt;string} and {$header_out0-&gt;int}"</span>;

    <span style="font-style: italic; color: #808080;">// echoing the $header_out1 object, which is of type class Header2</span>
    <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">"output header1 contains {$header_out1-&gt;string} and {$header_out1-&gt;int}"</span>;</pre>
<p>There the headers are PHP class objects. You fill the public variables of the classes and pass them to the &#8216;echoString&#8217; operation. Although it looks like it call just a php function named &#8216;echoString&#8217;, it actually invoke the web service operation named &#8216;echoString&#8217;, with the request payload and custom SOAP headers. It returns the response payload value + the output headers to the references we passed as the last 2 arguments.</p>
<p>So with WSF/PHP 2.0 you can use WSDL mode and WSDL2PHP tool to send payload with custom headers with a little and quick code.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/11/03/sending-custom-soap-headers-in-php-web-services/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Book on RESTful PHP Web Services</title>
		<link>http://www.dimuthu.org/blog/2008/10/21/book-on-restful-php-web-services/</link>
		<comments>http://www.dimuthu.org/blog/2008/10/21/book-on-restful-php-web-services/#comments</comments>
		<pubDate>Tue, 21 Oct 2008 18:01:52 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[REST]]></category>
		<category><![CDATA[RESTful]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[Book]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=531</guid>
		<description><![CDATA[Samisa Abeysinghe who is the director of engineering at WSO2 and one of the key leaders of the WSF/PHP project has published a book titled RESTful PHP Web Services. In Samisa&#8217;s Blog He describes the structure and the content of the book in his own words. If you are developing RESTful web services in PHP, [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://samisa-abeysinghe.blogspot.com/">Samisa Abeysinghe </a>who is the director of engineering at WSO2 and one of the key leaders of the <a href="http://wso2.org/projects/wsf/php">WSF/PHP project</a> has published a book titled <a href="http://www.packtpub.com/restful-php-web-services/book">RESTful PHP Web Services</a>.</p>
<div class="wp-caption aligncenter" style="width: 550px"><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="540" height="666" /></a><p class="wp-caption-text">RESTful PHP Web Services - Samisa Abeysinghe</p></div>
<p>In <a href="http://samisa-abeysinghe.blogspot.com/2008/10/restful-php-web-services-book.html">Samisa&#8217;s Blog</a> He describes the structure and the content of the book in his own words.</p>
<p>If you are developing RESTful web services in PHP, you will find this book will be a great reference.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/10/21/book-on-restful-php-web-services/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Demo on Consuming Flickr, Yahoo and Amazon Search Web Services</title>
		<link>http://www.dimuthu.org/blog/2008/10/19/demo-on-consuming-flickr-yahoo-and-amazon-search-web-services/</link>
		<comments>http://www.dimuthu.org/blog/2008/10/19/demo-on-consuming-flickr-yahoo-and-amazon-search-web-services/#comments</comments>
		<pubDate>Sun, 19 Oct 2008 10:27:37 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[REST]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[amazon]]></category>
		<category><![CDATA[flickr]]></category>
		<category><![CDATA[public web services]]></category>
		<category><![CDATA[yahoo]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=506</guid>
		<description><![CDATA[WSF/PHP Demo Site contains number of sample web service applications which demonstrate the different features of WSF/PHP. From these demos, Mashup Search Demo demonstrate  the use of  publicly available web services to create a search mashup in your web site. This demo consists of 3 public web services namely Flickr, Yahoo and Amazon. Flickr Yahoo [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://labs.wso2.org/wsf/php">WSF/PHP Demo Site</a> contains number of sample web service applications which demonstrate the different features of <a href="http://wso2.org/projects/wsf/php">WSF/PHP</a>. From these demos, <a href="http://labs.wso2.org/wsf/php/resource_view.php?url=SearchMashup">Mashup Search Demo</a> demonstrate  the use of  publicly available web services to create a search mashup in your web site.</p>
<p><a href="http://labs.wso2.org/wsf/php/resource_view.php?url=SearchMashup">This demo</a> consists of 3 public web services namely Flickr, Yahoo and Amazon.</p>
<table border="1" >
<tbody>
<tr style="background: #aaaaaa">
<td></td>
<td>Flickr</td>
<td>Yahoo</td>
<td>Amazon</td>
</tr>
<tr>
<td style="background:#cccccc">Service Documentation Page</td>
<td><a href="http://www.flickr.com/services/api/">Flickr API Docs<br />
</a></td>
<td><a href="http://developer.yahoo.com/search/">Yahoo API Docs<br />
</a></td>
<td><a href="http://docs.amazonwebservices.com/AWSEcommerceService/2005-10-05/">Amazon API Docs<br />
</a></td>
</tr>
<tr>
<td style="background:#cccccc">REST/SOAP</td>
<td>REST</td>
<td>REST</td>
<td>SOAP and REST</td>
</tr>
<tr>
<td style="background:#cccccc">Registration for Key</td>
<td><a href="http://www.flickr.com/services/api/keys/apply/">Flickr API registration<br />
</a></td>
<td><a href="http://developer.yahoo.com/wsregapp/">Yahoo API registration<br />
</a></td>
<td><a href="http://www.amazon.com/gp/aws/registration/registration-form.html">Amazon API Registration<br />
</a></td>
</tr>
<tr>
<td style="background:#cccccc">Source code for sample consumer</td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fmashup_demo%2Fflickr_demo.php">Flickr Demo Source<br />
</a></td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fmashup_demo%2Fyahoo_demo.php&amp;aschild=1">Yahoo Demo Source<br />
</a></td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fmashup_demo%2Famazon_demo.php">Amazon Demo Source<br />
</a></td>
</tr>
<tr>
<td style="background:#cccccc">PHP class used</td>
<td>FlickrClient</td>
<td>YahooClient</td>
<td>AmazonClient</td>
</tr>
<tr>
<td style="background:#cccccc">Available Operations</td>
<td>
<ul>
<li>photosTextSearch</li>
<li>photosTagSearch</li>
</ul>
</td>
<td>
<ul>
<li>webSearch</li>
<li>newsSearch</li>
<li>imageSearch</li>
<li>localSearch</li>
</ul>
</td>
<td>
<ul>
<li>itemSearch</li>
<li>itemLookup</li>
</ul>
</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/10/19/demo-on-consuming-flickr-yahoo-and-amazon-search-web-services/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WSF/PHP Webinar</title>
		<link>http://www.dimuthu.org/blog/2008/09/25/wsfphp-webinar/</link>
		<comments>http://www.dimuthu.org/blog/2008/09/25/wsfphp-webinar/#comments</comments>
		<pubDate>Thu, 25 Sep 2008 19:45:09 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[web services]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[enterprise]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[webinar]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=389</guid>
		<description><![CDATA[WSO2 WSF/PHP Webinar slides are now online. It basically contains an introduction to the WSF/PHP project, the features in its last week hot release and its enterprise applications. WSF PHP 2.0.0 Webinar Sep 2008 You can watch the video of the Webinar from here. Visit the WSF/PHP Webinar Page for more details.]]></description>
			<content:encoded><![CDATA[<p>WSO2 WSF/PHP Webinar slides are now online. It basically contains an introduction to the <a href="http://wso2.org/projects/wsf/php">WSF/PHP project</a>, the features in its last week hot release and its enterprise applications.</p>
<div id="__ss_614951" 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="WSF PHP 2 Webinar Sep 2008" href="http://www.slideshare.net/wso2.org/wsf-php-2-webinar-sep-2008-presentation?type=powerpoint">WSF PHP 2.0.0 Webinar Sep 2008</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=wsfphp-2webinarsep2008-1222235353223305-9&amp;stripped_title=wsf-php-2-webinar-sep-2008-presentation" /><embed type="application/x-shockwave-flash" width="425" height="355" src="http://static.slideshare.net/swf/ssplayer2.swf?doc=wsfphp-2webinarsep2008-1222235353223305-9&amp;stripped_title=wsf-php-2-webinar-sep-2008-presentation" allowscriptaccess="always" allowfullscreen="true"></embed></object></div>
<p><img style="visibility: hidden; width: 0px; height: 0px;" src="http://counters.gigya.com/wildfire/IMP/CXNID=2000002.0NXC/bT*xJmx*PTEyMjIzNzEyMjQ5ODQmcHQ9MTIyMjM3MTIzNjIzNCZwPTEwMTkxJmQ9Jm49Jmc9MiZ*PSZvPTI5ZjRjODZhMjY4ODRlYmY4NmJhYmZlYjczNmY1MWNm.gif" border="0" alt="" width="0" height="0" /></p>
<p>You can watch the video of the Webinar from <a href="https://wso2.on.intercall.com/confmgr/view_stored_doc.jsp?docId=91793182194209045364724076360&amp;docType=recording">here</a>. Visit the <a href="http://wso2.org/library/webinars/introducing-enterprise-web-services-wso2-wsf-php-2-0-0">WSF/PHP Webinar Page</a> for more details.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/09/25/wsfphp-webinar/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Send Binary With Web Services in PHP &#8211; 2 Minutes Introduction</title>
		<link>http://www.dimuthu.org/blog/2008/09/22/send-binary-with-web-services-in-php-2-minutes-introduction/</link>
		<comments>http://www.dimuthu.org/blog/2008/09/22/send-binary-with-web-services-in-php-2-minutes-introduction/#comments</comments>
		<pubDate>Mon, 22 Sep 2008 17:14:53 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[2 minutes guide]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[WSDL]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[xml schema]]></category>
		<category><![CDATA[2 minutes]]></category>
		<category><![CDATA[base64]]></category>
		<category><![CDATA[binary]]></category>
		<category><![CDATA[mtom]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[SWA]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=358</guid>
		<description><![CDATA[In PHP you have several ways of sending binary data. It can be primarily categorized in to non-optimized method (send as base64 binary) and optimized method (send as MTOM or SWA). Here I m talking about how to send binaries in above mentioned methods starting from a WSDL. WSDL Think you have a WSDL with [...]]]></description>
			<content:encoded><![CDATA[<p>In PHP you have several ways of sending binary data. It can be primarily categorized in to non-optimized method (send as base64 binary) and optimized method (send as MTOM or SWA). Here I m talking about how to send binaries in above mentioned methods starting from a WSDL.</p>
<p><strong>WSDL</strong></p>
<p>Think you have a WSDL with the following XML Schema.</p>
<pre class="xml">            <span style="color: #009900;"><span style="font-style: italic; color: #808080;">&lt;!-- Here is my submitPerson method-&gt;</span>
</span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"submitPerson"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
                <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:complexType<span style="font-weight: bold; color: black;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:sequence<span style="font-weight: bold; color: black;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"name"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"xs:string"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
                        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"age"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"xs:int"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
                        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"photo"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"xs:base64Binary"</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">/&gt;</span></span>
<span style="color: #009900;">                    <span style="font-weight: bold; color: black;">&lt;/xs:sequence<span style="font-weight: bold; color: black;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xs:complexType<span style="font-weight: bold; color: black;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xs:element<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>The submit Person method submit the name,age and a photo which is a type of base64Binary.</p>
<p><strong>Generated Class</strong></p>
<p>After generating php class for this piece of code using <a href="http://labs.wso2.org/wsf/php/wsdl2phptool.php">wsdl2php</a> you will have  the following class.</p>
<pre class="php"><span style="font-weight: bold; color: #000000;">class</span> submitPerson <span style="color: #66cc66;">{</span>

    <span style="font-style: italic; color: #808080;">/**
     * @var string
     */</span>
    <span style="font-weight: bold; color: #000000;">public</span> <span style="color: #0000ff;">$name</span>;

    <span style="font-style: italic; color: #808080;">/**
     * @var int
     */</span>
    <span style="font-weight: bold; color: #000000;">public</span> <span style="color: #0000ff;">$age</span>;

    <span style="font-style: italic; color: #808080;">// You need to set only one from the following two vars</span>

    <span style="font-style: italic; color: #808080;">/**
     * @var Plain Binary
     */</span>
    <span style="font-weight: bold; color: #000000;">public</span> <span style="color: #0000ff;">$photo</span>;

    <span style="font-style: italic; color: #808080;">/**
     * @var base64Binary
     */</span>
    <span style="font-weight: bold; color: #000000;">public</span> <span style="color: #0000ff;">$photo_encoded</span>;

<span style="color: #66cc66;">}</span></pre>
<p>So it is very easy to fill the class with your own data. Note that you only need to fill one of the &#8216;photo&#8217; or &#8216;photo_encoded&#8217; fields. If you have binary already converted to base64 then you can use the &#8216;photo_encoded&#8217; field where as if you only have the row binary just use the &#8216;photo&#8217; field. Here are my values for this particular example.</p>
<pre class="php"><span style="color: #0000ff;">$person</span> = <span style="font-weight: bold; color: #000000;">new</span> submitPerson<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;
<span style="color: #0000ff;">$person</span>-&gt;<span style="color: #006600;">name</span> = <span style="color: #ff0000;">"xxxx yyy"</span>;
<span style="color: #0000ff;">$person</span>-&gt;<span style="color: #006600;">age</span> = <span style="color: #cc66cc;">35</span>;
<span style="color: #0000ff;">$person</span>-&gt;<span style="color: #006600;">photo</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;">"/photo/xxxyyy"</span><span style="color: #66cc66;">)</span>;</pre>
<p><strong>Sending Binary as MTOM</strong></p>
<p>Here is the code you need to send the above structure as a MTOM message.</p>
<pre class="php"><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;">"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;">// anyway useMTOM is default to TRUE for WSClient</span>
<span style="color: #0000ff;">$proxy</span> = <span style="color: #0000ff;">$client</span>-&gt;<span style="color: #006600;">getProxy</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;

<span style="color: #0000ff;">$response</span> = <span style="color: #0000ff;">$proxy</span>-&gt;<span style="color: #006600;">submitPerson</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$person</span><span style="color: #66cc66;">)</span>;</pre>
<p><strong>Sending Binary as Base64 Encoded string<br />
</strong></p>
<p>You only need to change one option. That is setting &#8220;useMTOM&#8221; to FALSE will send the binary as Base64.</p>
<pre class="php"><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;">"useMTOM"</span> =&gt; <span style="font-weight: bold; color: #000000;">FALSE</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;
<span style="color: #0000ff;">$proxy</span> = <span style="color: #0000ff;">$client</span>-&gt;<span style="color: #006600;">getProxy</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;

<span style="color: #0000ff;">$response</span> = <span style="color: #0000ff;">$proxy</span>-&gt;<span style="color: #006600;">submitPerson</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$person</span><span style="color: #66cc66;">)</span>;</pre>
<p><strong>SWA (SOAP With Attachments) </strong><br />
You can send the binary data as SWA by setting the &#8220;useMTOM&#8221; option to &#8220;SWA&#8221;. SWA is also a binary optimized method of sending attachments, but unlike with MTOM you can&#8217;t integrate security or reliability with this approach.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/09/22/send-binary-with-web-services-in-php-2-minutes-introduction/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SOA Way of Writing PHP</title>
		<link>http://www.dimuthu.org/blog/2008/09/20/soa-way-of-writing-php/</link>
		<comments>http://www.dimuthu.org/blog/2008/09/20/soa-way-of-writing-php/#comments</comments>
		<pubDate>Sat, 20 Sep 2008 20:08:41 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[DataServices]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[data services]]></category>
		<category><![CDATA[distributed]]></category>
		<category><![CDATA[Figures]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[Traditionl]]></category>
		<category><![CDATA[WS-*]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=331</guid>
		<description><![CDATA[Traditional way of Writing PHP Let me draw a component diagram of a typical traditional(conventional) PHP web application. With this design you get the advantages of the client-server architecture and the MVC design pattern. Advantages of the Traditional Approach You can connect to the server from anywhere that has the connectivity to the centralized server. [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Traditional way of Writing PHP</strong><br />
Let me draw a component diagram of a typical traditional(conventional) PHP web application.<a href="http://www.dimuthu.org/wp-content/uploads/2008/09/mvc.jpg"><img class="size-full wp-image-335" style="border:0px" title="MVC Architecture Model" src="http://www.dimuthu.org/wp-content/uploads/2008/09/mvc.jpg" alt="MVC Architecture Model" /></a></p>
<p>With this design you get the advantages of the client-server architecture and the MVC design pattern.</p>
<p><strong>Advantages of the Traditional Approach</strong></p>
<ul>
<li> You can connect to the server from anywhere that has the connectivity to the centralized server. Say you process purchase orders in your application. Sails agents, customers around the world can connect to the application from their computers and do purchase orders. (Because of the Client-Server Architecture)<a href="http://www.dimuthu.org/wp-content/uploads/2008/09/star_network1.jpg"><img class="size-full wp-image-336" style="border:0px" title="client-server architecture" src="http://www.dimuthu.org/wp-content/uploads/2008/09/star_network1.jpg" alt="client-server architecture" /></a></li>
<li> Doing Changes to the inside of the components (Model, View and Controller) are relatively easy , because of the separation of the logics. But if changes affect to inter-communication of each component then it become harder because of the low granularity. (check disadvantages)</li>
</ul>
<p>Are their any disadvantages of this approach?<br />
Yes. There are plenty of them. Actually it is lot more than the advantages list.</p>
<p><strong>Disadvantages of the Traditional Approach</strong></p>
<ul>
<li><strong>More Server load:</strong> The only server is responsible for maintenance of all the components. And there is no straight forward way to distribute these components in a network.</li>
<li> <strong>No Interoperability:</strong> Can I replace the PHP Presentation layer with a .NET, C, Java Desktop Application with this design? No. PHP components (Model, View, Controller) are communicated in PHP code level through php function calls or may be through PHP object interactions, If you want to integrate .NET/Java to replace one component, you have to change all these function calls, object passings with each components.<br />
<a href="http://www.dimuthu.org/wp-content/uploads/2008/09/nointeroperable.jpg"><img class="size-full wp-image-337" style="border:0px" title="non-interoperability" src="http://www.dimuthu.org/wp-content/uploads/2008/09/nointeroperable.jpg" alt="non-interoperability" /></a></li>
<li> <strong>Fine Grained Interfaces</strong>: Even when I want to replace some component with another PHP implementation, it is still very difficult to integrate to the running system because of the fine-grained interfaces (Lot of small operations) used in the inter-component communication.<br />
Mostly this issue comes when integrating new business component to existing business logic within the controller logic. The below is just a figure to demonstrate what is meant by fine-grained interface.<br />
<a href="http://www.dimuthu.org/wp-content/uploads/2008/09/finegrained.jpg"><img class="size-full wp-image-339" style="border:0px" title="fine-grained-services" src="http://www.dimuthu.org/wp-content/uploads/2008/09/finegrained.jpg" alt="fine-grained-services" /></a><br />
This causes the application to be slow (more message exchange =&gt; more time on the wire =&amp;t; lesser speed), more traffic to the server and most importantly very hard to make interfaces consistent. (There can be many additions and removals of small operations over the time). Check <a href="http://www.ibm.com/developerworks/library/ws-soa-granularity/index.html">this</a> for learn more about the granularity.</li>
<li> <strong>Business Process Automation (BPA) is impossible:</strong> Your partner companies can not purchase your products through their systems. Because they are only given a browser interface, which need human interaction. You should provide some remote interface to allow their computers to talk to your systems.<br />
<a href="http://www.dimuthu.org/wp-content/uploads/2008/09/manualsystem.jpg"><img class="size-full wp-image-340" style="border:0px" title="bpa-impossibility" src="http://www.dimuthu.org/wp-content/uploads/2008/09/manualsystem.jpg" alt="bpa-impossibility" /></a><br />
For BPA, interoperability is really important. Because your partner company may run on completely different platform and use completely different languages. I already proved traditional design will not suit to situation where interoperability is need.</li>
<li> <strong>Lack of security:</strong> With the above approach you have to depend on the transport level security, which is handled by your OS. There can be applications (malicious codes) run top of your OS which have back doors to these information. So for business critical messages you need to have message level security (application to application security) which secure the messages by application itself .</li>
<li> <strong>Lack of reliability:</strong> In any case if the connection is lost, will my messages completely lost?. Here too you depend on the transport level reliability which you don&#8217;t have much control of.</li>
</ul>
<p>So now lets turn to our main topic.</p>
<p><strong>SOA Way of Writing PHP</strong></p>
<p><a href="http://www.dimuthu.org/wp-content/uploads/2008/09/soa_model.jpg"><img class="size-full wp-image-341" style="border:0px" title="SOA Model" src="http://www.dimuthu.org/wp-content/uploads/2008/09/soa_model.jpg" alt="SOA Model" /></a></p>
<p>With SOA, you application is no longer presenting the &#8216;View&#8217; component directly. Instead it provides your business operations as a Web Service. You may implement a View with PHP using this web service. This approach allows you to implement View not only in PHP but also in other languages like .NET, Java or C as web application or desktop applications.</p>
<p>The business logic access the Data Layer through a Data Service. Simmilarly It can use third party Data services, Web Services to extract out the Data needed in the business process.</p>
<p>Let&#8217;s see how it helps you to solve the problems arouse in the traditional approach.</p>
<ul>
<li><strong>Less Server load</strong>: The SOA components are natively distributed. You don&#8217;t need to process the View and the Data in the same server you process the Buisness Logic.</li>
<li><strong>High Interoperability:</strong> SOA communication happens through Web Services which is a standard protocol. There are implementations for web services in many languages and for many platforms. You can replace any components with any implementation you prefer. For an example you may first write your business logic in PHP, And as the server load goes high, you can write the buisness module in native language (&#8216;C&#8217;) and easily intergreate to the system, without being bother of changing other components.</li>
<li><strong>Coarse grained Interfaces:</strong> The latest web services standards (e.g. WSDL 2.0) enforce the use of documents for messaging rather than invoking remote procedures. This causes the system to be consistent, maintainable and more responsive.</li>
<li><strong>Business Process Automation:</strong> Web service provide a platform to machine to machine communication. With the availability of interoperability two companies who use different implementations can communicate easily</li>
<li><strong>Security:</strong> With a WS-Security implementation you can get message level security in your application. For PHP developers there were no implementation or library that can provide  WS-Security sometime ago. But as <a href="http://wso2.org/projects/wsf/php">WSF/PHP</a> is launched with many implementations for WS-* stack, that gap was closed.</li>
<li><strong>Reliability</strong>: With the WS-Reliable Messaging you can make sure a reliable communication at the application layer. You can use WSF/PHP to do reliable messaging in PHP</li>
</ul>
<p>As your business get more complicated you can divide the logic too in to several service components as you do with data and view components. This allows you to extend your application very easily. Here is a rough design of an enterprise SOA application that you may have seen in Java and .NET paradigms. And it is time to see more of these in PHP space as well.</p>
<p><a href="http://www.dimuthu.org/wp-content/uploads/2008/09/soa_design.jpg"><img class="size-full wp-image-345" style="border:0px" title="SOA design" src="http://www.dimuthu.org/wp-content/uploads/2008/09/soa_design.jpg" alt="SOA design" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/09/20/soa-way-of-writing-php/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
