<?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; 2 minutes</title>
	<atom:link href="http://www.dimuthu.org/tag/2-minutes/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dimuthu.org</link>
	<description>Waiting for your comments</description>
	<lastBuildDate>Wed, 21 Dec 2011 05:39:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<image>
  <link>http://www.dimuthu.org</link>
  <url>http://www.dimuthu.org/favicon.ico</url>
  <title>Dimuthu's Blog</title>
</image>
		<item>
		<title>Http Authentication for SOAP Messages in PHP &#8211; 2 Minutes Introduction</title>
		<link>http://www.dimuthu.org/blog/2008/09/24/http-authentication-for-sopa-messages-in-php-2-minutes-introduction/</link>
		<comments>http://www.dimuthu.org/blog/2008/09/24/http-authentication-for-sopa-messages-in-php-2-minutes-introduction/#comments</comments>
		<pubDate>Wed, 24 Sep 2008 17:29:28 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[2 minutes guide]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[2 minutes]]></category>
		<category><![CDATA[authentication]]></category>
		<category><![CDATA[basic]]></category>
		<category><![CDATA[HTTP]]></category>
		<category><![CDATA[messages]]></category>
		<category><![CDATA[SOAP]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=380</guid>
		<description><![CDATA[Yesterday&#8217;s blog on &#8220;Using Username token in Authentication&#8221; I explained a standard way of authenting SOAP messages in Application layer (Message level Authentication). Anyway you can authenticate SOAP messages in transport level itself. For an example with HTTP Transport we can use the HTTP Basic Authentication for this purpose. Setting up a client with Authentication [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday&#8217;s blog on <a href="http://www.dimuthu.org/blog/2008/09/23/authenticate-using-username-token-from-php-2-minutes-introduction/">&#8220;Using Username token in Authentication&#8221;</a> I explained a standard way of authenting SOAP messages in Application layer (Message level Authentication). Anyway you can authenticate SOAP messages in transport level itself. For an example with HTTP Transport we can use the HTTP Basic Authentication for this purpose.</p>
<p><strong>Setting up a client with Authentication Information</strong></p>
<p>With <a href="http://wso2.org/projects/wsf/php">WSF/PHP</a> you can give the username, password and the authentication type as options for WSClient constructor.</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;">"to"</span> =&gt; <span style="color: #ff0000;">"http://server/myendpoint"</span>,
		<span style="color: #ff0000;">"httpAuthUsername"</span> =&gt; <span style="color: #ff0000;">"user"</span>,
		<span style="color: #ff0000;">"httpAuthPassword"</span> =&gt; <span style="color: #ff0000;">"user_password"</span>,
		<span style="color: #ff0000;">"httpAuthType"</span> =&gt; <span style="color: #ff0000;">"basic"</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;</pre>
<p><strong>Setting up the Server to Handle the Authentication</strong></p>
<p>Since the Http authentication is handled by the transport level, you have to configure your authentication information in your web server itself. (e.g. Apache or IIS).</p>
<p>If you are using Apache, please use <a href="http://apache.active-venture.com/auth-basic.html">this guide</a> to configure your allowed list to access the server.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/09/24/http-authentication-for-sopa-messages-in-php-2-minutes-introduction/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Authenticate using Username Token from PHP &#8211; 2 Minutes Introduction</title>
		<link>http://www.dimuthu.org/blog/2008/09/23/authenticate-using-username-token-from-php-2-minutes-introduction/</link>
		<comments>http://www.dimuthu.org/blog/2008/09/23/authenticate-using-username-token-from-php-2-minutes-introduction/#comments</comments>
		<pubDate>Tue, 23 Sep 2008 14:58:59 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[2 minutes guide]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[2 minutes]]></category>
		<category><![CDATA[authentication]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[username token]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=372</guid>
		<description><![CDATA[Username token is a simple token sent inside SOAP message header element with username and password information.  It is used to authenticate SOAP messages in a standardized way. Sending Username Token To send username token with WSF/PHP you can use the generic API designed to implement WS-Security scenarios. First you need to declare the security [...]]]></description>
			<content:encoded><![CDATA[<p>Username token is a simple token sent inside SOAP message header element with username and password information.  It is used to authenticate SOAP messages in a standardized way.</p>
<p><strong>Sending Username Token</strong></p>
<p>To send username token with <a href="http://wso2.org/projects/wsf/php">WSF/PHP</a> you can use the generic API designed to implement WS-Security scenarios.</p>
<ul>
<li>First you need to declare the security policy saying you are using username token. You can do this either with a policy which is complaint with WS-Security Policy standards or using an associative array. Here we use the second approach which is more <em>PHP-Friendly</em>.
<pre class="php"><a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"useUsernameToken"</span> =&gt; <span style="font-weight: bold; color: #000000;">TRUE</span><span style="color: #66cc66;">)</span></pre>
</li>
<li> With a WSSecurityToken instance we are giving our user parameters. In this case it is username, password and the password type.
<pre class="php"><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="color: #ff0000;">"user"</span> =&gt; <span style="color: #ff0000;">"my_username"</span>,
                                                <span style="color: #ff0000;">"password"</span> =&gt; <span style="color: #ff0000;">"my_password"</span>,
                                                <span style="color: #ff0000;">"passwordType"</span> =&gt; <span style="color: #ff0000;">"Digest"</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;</pre>
</li>
<li> And create the WSClient object with policy and the security token object you just created + with &#8220;useWSA&#8221; on.  This is to enable the addressing headers in the request message which guide the server to identify the service and the operation.</li>
</ul>
<p>Here is the complete code for the client.</p>
<pre class="php">    <span style="font-style: italic; color: #808080;">// Set up security options</span>
    <span style="color: #0000ff;">$security_options</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"useUsernameToken"</span> =&gt; <span style="font-weight: bold; color: #000000;">TRUE</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;">$security_options</span><span style="color: #66cc66;">)</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="color: #ff0000;">"user"</span> =&gt; <span style="color: #ff0000;">"my_username"</span>,
                                                <span style="color: #ff0000;">"password"</span> =&gt; <span style="color: #ff0000;">"my_password"</span>,
                                                <span style="color: #ff0000;">"passwordType"</span> =&gt; <span style="color: #ff0000;">"Digest"</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;

    <span style="font-style: italic; color: #808080;">// Create client with options</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;">"policy"</span> =&gt; <span style="color: #0000ff;">$policy</span>,
                                 <span style="color: #ff0000;">"securityToken"</span> =&gt; <span style="color: #0000ff;">$security_token</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;

    <span style="font-style: italic; color: #808080;">// Send request and capture 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>;</pre>
<p><strong>Handling Username Token at Server Side</strong><br />
The same options (&#8220;policy&#8221; and &#8220;securityToken&#8221;) you gave to WSClient, can be given to WSService object as well. But hard coding values for &#8220;username&#8221; and &#8220;password&#8221; in SecurityToken is not much useful at the server side. Because it authenticate only one user. So in order to maintain multiple accounts, you have to have a callback function in php.</p>
<pre class="php"><span style="font-style: italic; color: #808080;">// callback function</span>
<span style="font-weight: bold; color: #000000;">function</span> my_passwd_callback_function<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$username</span><span style="color: #66cc66;">)</span>
<span style="color: #66cc66;">{</span>
    <span style="font-style: italic; color: #808080;">// logic to return the password for the username</span>
    <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$password</span>
<span style="color: #66cc66;">}</span>

<span style="font-style: italic; color: #808080;">// setting it to the security token</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;">"passwordCallback"</span> =&gt; <span style="color: #ff0000;">"my_passwd_callback_function"</span>,
                                       <span style="color: #ff0000;">"passwordType"</span> =&gt; <span style="color: #ff0000;">"Digest"</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;</pre>
<p>Here in the function you return the password for the username from a database and that information will be used to authenticate the request message.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/09/23/authenticate-using-username-token-from-php-2-minutes-introduction/feed/</wfw:commentRss>
		<slash:comments>3</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[web services]]></category>
		<category><![CDATA[WSDL]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[xml schema]]></category>
		<category><![CDATA[2 minutes]]></category>
		<category><![CDATA[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>3</slash:comments>
		</item>
		<item>
		<title>WSDL2PHP 2 Minutes Introduction</title>
		<link>http://www.dimuthu.org/blog/2008/09/21/wsdl2php-2-minutes-introduction/</link>
		<comments>http://www.dimuthu.org/blog/2008/09/21/wsdl2php-2-minutes-introduction/#comments</comments>
		<pubDate>Sun, 21 Sep 2008 17:54:43 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[2 minutes guide]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[WSDL]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[xml schema]]></category>
		<category><![CDATA[2 minutes]]></category>
		<category><![CDATA[client]]></category>
		<category><![CDATA[consumers]]></category>
		<category><![CDATA[guide]]></category>
		<category><![CDATA[WSClient]]></category>
		<category><![CDATA[wsdl2php]]></category>

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

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

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

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

    <span style="font-style: italic; color: #808080;">//--------my code-----</span>
    <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #0000ff;">$response</span>-&gt;<span style="color: #006600;">return</span>;
    <span style="font-style: italic; color: #808080;">//--------------------</span></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/09/21/wsdl2php-2-minutes-introduction/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>Developing WSF/PHP Webservices With Contract First Approach &#8211; 2 Minutes Introduction</title>
		<link>http://www.dimuthu.org/blog/2008/09/08/developing-wsfphp-webservices-with-contract-first-approach-2-minutes-introduction/</link>
		<comments>http://www.dimuthu.org/blog/2008/09/08/developing-wsfphp-webservices-with-contract-first-approach-2-minutes-introduction/#comments</comments>
		<pubDate>Mon, 08 Sep 2008 17:21:49 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[2 minutes guide]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[WSDL]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[xml schema]]></category>
		<category><![CDATA[2 minutes]]></category>
		<category><![CDATA[contract first]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[webservices]]></category>
		<category><![CDATA[wsdl2php]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=237</guid>
		<description><![CDATA[WSF/PHP allows you to develop web services with both Contract First (Starting from WSDL) and Code First Approaches. From these two, Contract First approach is the most famous and most recomended way of developing a Webservice. There you need to have a WSDL to start with. I will take the http://labs.wso2.org/wsf/php/example.xml as our WSDL. Generate [...]]]></description>
			<content:encoded><![CDATA[<p>WSF/PHP allows you to develop web services with both Contract First (Starting from WSDL) and Code First Approaches. From these two, Contract First approach is the most famous and most recomended way of developing a Webservice. There you need to have a WSDL to start with. I will take the <a href="http://labs.wso2.org/wsf/php/example.xml">http://labs.wso2.org/wsf/php/example.xml</a> as our WSDL.</p>
<p><strong>Generate The Service Code</strong></p>
<p>When you download the <a href="http://wso2.org/projects/wsf/php">WSF/PHP pack </a>there is a script called &#8216;wsdl2php.php&#8217; in the script directory. Open a command line and run it with the following options. Or you can use the <a href="http://labs.wso2.org/wsf/php/wsdl2phptool.php?wsdl_url=http%3A%2F%2Flabs.wso2.org%2Fwsf%2Fphp%2Fexample.xml&amp;generate_type=server">online wsdl2php tool</a></p>
<pre>php wsdl2php.php http://labs.wso2.org/wsf/php/example.xml -s</pre>
<p><strong>Complete The Business Logic</strong></p>
<p>Complete the TODO section of the generated file. Apparently what is left to do is filling the business logic for each function corresponding to the service operations in your WSDL. You are given the hint to the input and output parameters. Here is how I fill the logic for the simpleAdd function.</p>
<pre><span style="font-weight: bold; color: #000000;">function</span> simpleAdd<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$input</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>
    <span style="font-style: italic; color: #808080;">// TODO: fill in the business logic</span>
    <span style="font-style: italic; color: #808080;">// NOTE: $input is of type simpleAdd</span>
    <span style="font-style: italic; color: #808080;">// NOTE: should return an object of type simpleAddResponse</span>

    <span style="color: #0000ff;">$res</span> = <span style="font-weight: bold; color: #000000;">new</span> simpleAddResponse<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;

    <span style="color: #0000ff;">$res</span>-&gt;<span style="color: #006600;">return</span> = <span style="color: #0000ff;">$input</span>-&gt;<span style="color: #006600;">param0</span> + <span style="color: #0000ff;">$input</span>-&gt;<span style="color: #006600;">param1</span>;

    <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$res</span>;
<span style="color: #66cc66;">}</span></pre>
<p><strong>Advanced Types? &#8211; Read Generated Hints for Class variables</strong></p>
<p>So how about filling the matrix add logic. Can be it be really complex?. No, what you need to observe is there the class member variables contains not only simple types but also another Class type. There is a comment on each member variables to hint its type. So the logic for the matrix addition is simple as this,</p>
<pre><span style="font-weight: bold; color: #000000;">function</span> matrixAdd<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$input</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>
    <span style="font-style: italic; color: #808080;">// TODO: fill in the business logic</span>
    <span style="font-style: italic; color: #808080;">// NOTE: $input is of type matrixAdd</span>
    <span style="font-style: italic; color: #808080;">// NOTE: should return an object of type matrixAddResponse</span>

    <span style="color: #0000ff;">$matrix0</span> = <span style="color: #0000ff;">$input</span>-&gt;<span style="color: #006600;">param0</span>;
    <span style="color: #0000ff;">$matrix1</span> = <span style="color: #0000ff;">$input</span>-&gt;<span style="color: #006600;">param1</span>;

    <span style="color: #0000ff;">$matrix2</span> = <span style="font-weight: bold; color: #000000;">new</span> Matrix<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;
    <span style="color: #0000ff;">$matrix2</span>-&gt;<span style="color: #006600;">rows</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;

    <span style="color: #b1b100;">if</span><span style="color: #66cc66;">(</span><a href="http://www.php.net/count"><span style="color: #000066;">count</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$matrix0</span>-&gt;<span style="color: #006600;">rows</span><span style="color: #66cc66;">)</span> == <a href="http://www.php.net/count"><span style="color: #000066;">count</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$matrix1</span>-&gt;<span style="color: #006600;">rows</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span> <span style="font-style: italic; color: #808080;">// considering only happy path</span>

        <span style="color: #b1b100;">for</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$i</span> = <span style="color: #cc66cc;">0</span>; <span style="color: #0000ff;">$i</span> &lt; <a href="http://www.php.net/count"><span style="color: #000066;">count</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$matrix0</span>-&gt;<span style="color: #006600;">rows</span><span style="color: #66cc66;">)</span>; <span style="color: #0000ff;">$i</span> ++ <span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>

            <span style="color: #0000ff;">$row0</span> = <span style="color: #0000ff;">$matrix0</span>-&gt;<span style="color: #006600;">rows</span><span style="color: #66cc66;">[</span><span style="color: #0000ff;">$i</span><span style="color: #66cc66;">]</span>;
            <span style="color: #0000ff;">$row1</span> = <span style="color: #0000ff;">$matrix1</span>-&gt;<span style="color: #006600;">rows</span><span style="color: #66cc66;">[</span><span style="color: #0000ff;">$i</span><span style="color: #66cc66;">]</span>;

            <span style="color: #0000ff;">$row2</span> = <span style="font-weight: bold; color: #000000;">new</span> MatrixRow<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;
            <span style="color: #0000ff;">$matrix2</span>-&gt;<span style="color: #006600;">rows</span><span style="color: #66cc66;">[</span><span style="color: #66cc66;">]</span> = <span style="color: #0000ff;">$row2</span>;
            <span style="color: #0000ff;">$row2</span>-&gt;<span style="color: #006600;">columns</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;

            <span style="color: #b1b100;">if</span><span style="color: #66cc66;">(</span><a href="http://www.php.net/count"><span style="color: #000066;">count</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$row0</span>-&gt;<span style="color: #006600;">columns</span><span style="color: #66cc66;">)</span> == <a href="http://www.php.net/count"><span style="color: #000066;">count</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$row1</span>-&gt;<span style="color: #006600;">columns</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>

                <span style="color: #b1b100;">for</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$j</span> = <span style="color: #cc66cc;">0</span>; <span style="color: #0000ff;">$j</span>&lt; <a href="http://www.php.net/count"><span style="color: #000066;">count</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$row0</span>-&gt;<span style="color: #006600;">columns</span><span style="color: #66cc66;">)</span>; <span style="color: #0000ff;">$j</span> ++ <span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>

                    <span style="color: #0000ff;">$col0</span> = <span style="color: #0000ff;">$row0</span>-&gt;<span style="color: #006600;">columns</span><span style="color: #66cc66;">[</span><span style="color: #0000ff;">$j</span><span style="color: #66cc66;">]</span>;
                    <span style="color: #0000ff;">$col1</span> = <span style="color: #0000ff;">$row1</span>-&gt;<span style="color: #006600;">columns</span><span style="color: #66cc66;">[</span><span style="color: #0000ff;">$j</span><span style="color: #66cc66;">]</span>;

                    <span style="color: #0000ff;">$col2</span> = <span><span style="color: #0000ff;">$col0 </span></span>+ <span><span style="color: #0000ff;">$col1</span></span>;

                    <span style="color: #0000ff;">$row2</span>-&gt;<span style="color: #006600;">columns</span><span style="color: #66cc66;">[</span><span style="color: #66cc66;">]</span> = <span style="color: #0000ff;">$col2</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;">$res</span> = <span style="font-weight: bold; color: #000000;">new</span> matrixAddResponse<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;
    <span style="color: #0000ff;">$res</span>-&gt;<span style="color: #006600;">return</span> = <span style="color: #0000ff;">$matrix2</span>;
    <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$res</span>;
<span style="color: #66cc66;">}</span></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/09/08/developing-wsfphp-webservices-with-contract-first-approach-2-minutes-introduction/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP DataServices 2 Minutes Introduction</title>
		<link>http://www.dimuthu.org/blog/2008/09/06/php-dataservices-2-minutes-introduction/</link>
		<comments>http://www.dimuthu.org/blog/2008/09/06/php-dataservices-2-minutes-introduction/#comments</comments>
		<pubDate>Sat, 06 Sep 2008 16:52:12 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[2 minutes guide]]></category>
		<category><![CDATA[DataServices]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[2 minutes]]></category>
		<category><![CDATA[data services]]></category>
		<category><![CDATA[DataService]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=225</guid>
		<description><![CDATA[We use the term DataServices for exposing a Database as a WebService. PHP DataServices library make this task easy by providing a very simple API to the developers. The API is designed to let the service developer to provide the database configurations, input message format, output message format and the SQL query information. So reading [...]]]></description>
			<content:encoded><![CDATA[<p>We use the term DataServices for exposing a Database as a WebService. PHP DataServices library make this task easy by providing a very simple API to the developers.</p>
<p>The API is designed to let the service developer to provide the database configurations, input message format, output message format and the SQL query information. So reading and parsing the input SOAP message, building the response SOAP message from the queried data, serving the WSDL and providing the Database independent layer (with the help of PDO extensions) are done by the Dataserivce library.</p>
<p><strong>Configurations</strong></p>
<p>You give your database configurations in this format.</p>
<pre><span style="font-style: italic; color: #808080;">// database configuraitons</span>
<span style="color: #0000ff;">$config</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span>
      <span style="color: #ff0000;">"db"</span> =&gt; <span style="color: #ff0000;">"mysql"</span>, <span style="font-style: italic; color: #808080;">//your sql</span>
      <span style="color: #ff0000;">"username"</span> =&gt; DB_USERNAME, <span style="font-style: italic; color: #808080;">//your username</span>
      <span style="color: #ff0000;">"password"</span> =&gt; DB_PASSWORD, <span style="font-style: italic; color: #808080;">//your password</span>
      <span style="color: #ff0000;">"dbname"</span> =&gt; <span style="color: #ff0000;">"ds"</span>, <span style="font-style: italic; color: #808080;">//your database name</span>
      <span style="color: #ff0000;">"dbhost"</span> =&gt; <span style="color: #ff0000;">"localhost"</span><span style="color: #66cc66;">)</span>; <span style="font-style: italic; color: #808080;">//your database host</span></pre>
<p><strong>Input Format</strong></p>
<p>You have to declare the names and the types of the content of your input message. This is needed to generate the WSDL and invoke the database query with parameters.</p>
<pre><span style="font-style: italic; color: #808080;">// input format array(param_name =&gt; SQL_TYPE)</span>
<span style="color: #0000ff;">$inputFormat</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"customerNumber"</span> =&gt; <span style="color: #ff0000;">"INT"</span><span style="color: #66cc66;">)</span>;</pre>
<p><strong>Output Format</strong></p>
<p>You can customize your response SOAP message by providing the names of the wrapper elements  for both the message and the rows.</p>
<pre><span style="font-style: italic; color: #808080;">// output format, plese check the API from http://wso2.org/wiki/display/wsfphp/API+for+Data+Services+Revised</span>
<span style="color: #0000ff;">$outputFormat</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"resultElement"</span> =&gt; <span style="color: #ff0000;">"Orders"</span>, <span style="font-style: italic; color: #808080;">//the name of the wrapper element of the message</span>
                      <span style="color: #ff0000;">"rowElement"</span> =&gt; <span style="color: #ff0000;">"Order"</span>, <span style="font-style: italic; color: #808080;">//the name of the wrapper element of each row</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;">"order-number"</span> =&gt; <span style="color: #ff0000;">"OrderNumber"</span>,
                                           <span style="color: #ff0000;">"order-date"</span> =&gt; <span style="color: #ff0000;">"OrderDate"</span>,
                                           <span style="color: #ff0000;">"status"</span> =&gt; <span style="color: #ff0000;">"status"</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;</pre>
<p><strong>Create the Query</strong></p>
<p>The query in the PHP dataserivces term is not just the SQL query that you are familiar in accessing a database, It contains the input and output formats in addition to the actual SQL query to invoke.</p>
<pre><span style="font-style: italic; color: #808080;">// sql statment to execute</span>
<span style="color: #0000ff;">$sql</span>=<span style="color: #ff0000;">"select o.OrderNumber, o.OrderDate, o.status from Customers c, Orders o where c.customerNumber=o.customerNumber and c.customerNumber=?"</span>;

<span style="font-style: italic; color: #808080;">// operations are consist of inputFormat (optional), outputFormat(required), sql(sql), input_mapping(optional)</span>
<span style="color: #0000ff;">$operations</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"customerOrders"</span> =&gt;array<span style="color: #66cc66;">(</span><span style="color: #ff0000;">"inputFormat"</span> =&gt; <span style="color: #0000ff;">$inputFormat</span>, <span style="color: #ff0000;">"outputFormat"</span> =&gt; <span style="color: #0000ff;">$outputFormat</span>, <span style="color: #ff0000;">"sql"</span> =&gt; <span style="color: #0000ff;">$sql</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;</pre>
<p><strong>DataService object</strong></p>
<p>Finally you create the DataService object with the provided configurations and the query information.</p>
<pre><span style="color: #b1b100;">require_once</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"wso2/DataServices/DataService.php"</span><span style="color: #66cc66;">)</span>;

<span style="color: #0000ff;">$my_data_service</span> = <span style="font-weight: bold; color: #000000;">new</span> DataService<span style="color: #66cc66;">(</span><a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"config"</span> =&gt; <span style="color: #0000ff;">$config</span>,<span style="color: #ff0000;">"operations"</span> =&gt; <span style="color: #0000ff;">$operations</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;

<span style="color: #0000ff;">$my_data_service</span>-&gt;<span style="color: #006600;">reply</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/09/06/php-dataservices-2-minutes-introduction/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WSF/PHP WSDL Generation 2 Minutes Introduction</title>
		<link>http://www.dimuthu.org/blog/2008/09/05/wsfphp-wsdl-generation-2-minutes-introduction/</link>
		<comments>http://www.dimuthu.org/blog/2008/09/05/wsfphp-wsdl-generation-2-minutes-introduction/#comments</comments>
		<pubDate>Fri, 05 Sep 2008 12:33:46 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[2 minutes guide]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[WSDL]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[xml schema]]></category>
		<category><![CDATA[2 minutes]]></category>
		<category><![CDATA[annotations]]></category>
		<category><![CDATA[wsdl generation]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=217</guid>
		<description><![CDATA[Whenever you deploy a service script in WSF/PHP you can access its WSDL by adding &#8220;?wsdl&#8221; or &#8220;?wsdl2&#8243; (for WSDL version 2.0) to the service endpoint. Anyway you may have noticed that for some services it will just list the operations with xsd:anyType as the input and output message schemes. For an example for an [...]]]></description>
			<content:encoded><![CDATA[<p>Whenever you deploy a service script in WSF/PHP you can access its WSDL by adding &#8220;?wsdl&#8221; or &#8220;?wsdl2&#8243; (for WSDL version 2.0) to the service endpoint. Anyway you may have noticed that for some services it will just list the operations with xsd:anyType as the input and output message schemes.</p>
<p>For an example for an operation like this,</p>
<pre><span style="font-weight: bold; color: #000000;">&lt;?php</span>

<span style="font-weight: bold; color: #000000;">function</span> getInvoice<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$order_no</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>
   <span style="font-style: italic; color: #808080;">//something that return an invoice for this order </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;">"getInvoice"</span> =&gt; <span style="color: #ff0000;">"getInvoice"</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;">"operations"</span> =&gt; <span style="color: #0000ff;">$operations</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;

<span style="color: #0000ff;">$svr</span>-&gt;<span style="color: #006600;">reply</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;
<span style="font-weight: bold; color: #000000;">?&gt;</span></pre>
<p>This will generate you a nice WSDL but with a schema similar to this,</p>
<pre><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xsd:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"getInvoice"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xsd:complexType<span style="font-weight: bold; color: black;">&gt;</span></span></span>
       <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xsd:sequence<span style="font-weight: bold; color: black;">&gt;</span></span></span>
           <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xsd:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"order_no"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"xsd:anyType"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
       <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xsd:sequence<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xsd:complexType<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xsd:element<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>This schema is not enough for get an understanding about the request, response message formats, because it uses xsd:anyType to represent a general message. In order to get more specific schema, you need to provide more details to the WSDL generator. Here is how it is done using annotations.</p>
<pre><span style="font-weight: bold; color: #000000;">&lt;?php</span>
<span style="font-style: italic; color: #808080;">/**
 * @param int $orderNo Order Number
 * (maps to xsd:int)
 * @return string $invoice Invoice as a string
 * (maps to xsd:string)
 */</span>
<span style="font-weight: bold; color: #000000;">function</span> getInvoice<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$order_no</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>
   <span style="font-style: italic; color: #808080;">//something that return an invoice for this order </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;">"getInvoice"</span> =&gt; <span style="color: #ff0000;">"getInvoice"</span><span style="color: #66cc66;">)</span>;
<span style="color: #0000ff;">$opParams</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"getInvoice"</span> =&gt; <span style="color: #ff0000;">"MIXED"</span><span style="color: #66cc66;">)</span>; <span style="font-style: italic; color: #808080;">// Have to declare parameters as MIXED</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;">"operations"</span> =&gt; <span style="color: #0000ff;">$operations</span>, <span style="color: #ff0000;">"opParams"</span> =&gt; <span style="color: #0000ff;">$opParams</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;

<span style="color: #0000ff;">$svr</span>-&gt;<span style="color: #006600;">reply</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;
<span style="font-weight: bold; color: #000000;">?&gt;</span></pre>
<p>Now check the schema. It will gives you the information specific to your request, response messages.</p>
<pre><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xsd:schema</span> <span style="color: #000066;">elementFormDefault</span>=<span style="color: #ff0000;">"qualified"</span>
    <span style="color: #000066;">targetNamespace</span>=<span style="color: #ff0000;">"http://www.wso2.org/php/xsd"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xsd:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"getInvoice"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xsd:complexType<span style="font-weight: bold; color: black;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xsd:sequence<span style="font-weight: bold; color: black;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xsd:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"orderNo"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"xsd:int"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xsd:sequence<span style="font-weight: bold; color: black;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xsd:complexType<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xsd:element<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xsd:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"getInvoiceResponse"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xsd:complexType<span style="font-weight: bold; color: black;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xsd:sequence<span style="font-weight: bold; color: black;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xsd:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"invoice"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"xsd:string"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xsd:sequence<span style="font-weight: bold; color: black;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xsd:complexType<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xsd:element<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xsd:schema<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>So it is your chance to do more experiment with this feature. Check <a href="http://wso2.org/project/wsf/php/1.3.2/docs/wsdl_generation_api.html">WSDL generation API</a> for more snippets.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/09/05/wsfphp-wsdl-generation-2-minutes-introduction/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Axis2/C ADB 2 Minutes Introduction</title>
		<link>http://www.dimuthu.org/blog/2008/09/03/axis2c-adb-2-minitue-introduction/</link>
		<comments>http://www.dimuthu.org/blog/2008/09/03/axis2c-adb-2-minitue-introduction/#comments</comments>
		<pubDate>Wed, 03 Sep 2008 14:14:27 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[2 minutes guide]]></category>
		<category><![CDATA[adb]]></category>
		<category><![CDATA[axis2/c]]></category>
		<category><![CDATA[codegen]]></category>
		<category><![CDATA[tool]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[WSDL]]></category>
		<category><![CDATA[wsdl2c]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[xml schema]]></category>
		<category><![CDATA[2 minutes]]></category>
		<category><![CDATA[guide]]></category>
		<category><![CDATA[tutorial]]></category>

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

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

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

