<?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; WSClient</title>
	<atom:link href="http://www.dimuthu.org/tag/wsclient/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>5 Facts About WS-Addressing Action in WSF/PHP</title>
		<link>http://www.dimuthu.org/blog/2008/11/26/5-facts-about-ws-addressing-action-in-wsfphp/</link>
		<comments>http://www.dimuthu.org/blog/2008/11/26/5-facts-about-ws-addressing-action-in-wsfphp/#comments</comments>
		<pubDate>Wed, 26 Nov 2008 17:55:29 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[WSDL]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[action]]></category>
		<category><![CDATA[dispatching]]></category>
		<category><![CDATA[SOAP action]]></category>
		<category><![CDATA[ws-addressing]]></category>
		<category><![CDATA[WSClient]]></category>
		<category><![CDATA[WSMessage]]></category>
		<category><![CDATA[WSService]]></category>

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

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

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

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

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

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

<span style="font-style: italic; color: #808080;">// we will take echoString and echoInt as tow operations</span>
<span style="color: #0000ff;">$operations</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"echoString"</span> =&gt; <span style="color: #ff0000;">"echoStringFunction"</span>,
                    <span style="color: #ff0000;">"echoInt"</span> =&gt; <span style="color: #ff0000;">"echoIntFunction"</span><span style="color: #66cc66;">)</span>;

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

<span style="font-style: italic; color: #808080;">// creating the service with the operations and actions set</span>
<span style="color: #0000ff;">$service</span> = <span style="font-weight: bold; color: #000000;">new</span> WSService<span style="color: #66cc66;">(</span><a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"operations"</span> =&gt; <span style="color: #0000ff;">$operations</span>,
                               <span style="color: #ff0000;">"actions"</span> =&gt; <span style="color: #0000ff;">$actions</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;

<span style="color: #0000ff;">$service</span>-&gt;<span style="color: #006600;">reply</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</pre>
<p>Note that this code is same as the code I post in a previous blog &#8220;<a href="http://www.dimuthu.org/blog/2008/11/25/the-use-of-soap-action-with-wsfphp/">The Use of SOAP Action with WSF/PHP</a>&#8221; which uses SOAP action to dispatch the operation. In fact WSService will adjust to dispatch SOAP messages, so if there is a SOAP action in the message, it will be dispatched using that, and if it contains WS-Addressing action, it will used to do dispatching without the need of writing a single additional line of code. Note that this same code for both &#8220;submission&#8221; and &#8220;1.0&#8243; WS-Addressing versions.</li>
<li>In a WSDL 1.1, WS-Addressing action can be declared in the message element in the portType section.
<pre class="xml">    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;wsdl:portType</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"echoPortType"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;wsdl:operation</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"echoString"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;wsdl:input</span> <span style="color: #000066;">message</span>=<span style="color: #ff0000;">"ns0:echoStringRequest"</span> <span style="color: #000066;">wsaw:Action</span>=<span style="color: #ff0000;">"http://localhost/samples/echo_service/echoString"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;wsdl:output</span> <span style="color: #000066;">message</span>=<span style="color: #ff0000;">"ns0:echoStringResponse"</span> <span style="color: #000066;">wsaw:Action</span>=<span style="color: #ff0000;">"http://localhost/samples/echo_service/echoStringResponse"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/wsdl:operation<span style="font-weight: bold; color: black;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;wsdl:operation</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"echoInt"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;wsdl:input</span> <span style="color: #000066;">message</span>=<span style="color: #ff0000;">"ns0:echoIntRequest"</span> <span style="color: #000066;">wsaw:Action</span>=<span style="color: #ff0000;">"http://localhost/samples/echo_service/echoInt"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;wsdl:output</span> <span style="color: #000066;">message</span>=<span style="color: #ff0000;">"ns0:echoIntResponse"</span> <span style="color: #000066;">wsaw:Action</span>=<span style="color: #ff0000;">"http://localhost/samples/echo_service/echoIntResponse"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/wsdl:operation<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/wsdl:portType<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>When you use WSF/PHP in wsdl mode, it will pick the action declared in the WSDL and set it in the SOAP message, if you have enabled the addressing for the WSClient by setting non-null value for &#8220;useWSA&#8221; option.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/11/26/5-facts-about-ws-addressing-action-in-wsfphp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ScreenCast &#8211; How to Consume a Web Service Using WSF/PHP</title>
		<link>http://www.dimuthu.org/blog/2008/10/29/screencast-how-to-consume-a-web-service-using-wsfphp/</link>
		<comments>http://www.dimuthu.org/blog/2008/10/29/screencast-how-to-consume-a-web-service-using-wsfphp/#comments</comments>
		<pubDate>Wed, 29 Oct 2008 17:35:47 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[screencast]]></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[client]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[WSClient]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=557</guid>
		<description><![CDATA[You can watch a Screencast on How to Consume a Web Service Using WSF/PHP from WSO2 Oxygent Tank developer portal. There I have presented the steps you need to follow to consume a web service. I choose US National Digital Forecasting database Web Service as my example service to write the demo client. This screencast [...]]]></description>
			<content:encoded><![CDATA[<p>You can watch a <a href="http://wso2.org/library/presentations/wso2-wsf-php-screencast-consume-service-using-wsf-php">Screencast on How to Consume a Web Service Using WSF/PHP</a> from WSO2 Oxygent Tank developer portal.</p>
<p>There I have presented the steps you need to follow to consume a web service. I choose <a href="http://www.nws.noaa.gov/forecasts/xml/">US National Digital Forecasting database Web Service </a>as my example service to write the demo client.</p>
<p>This screencast contains,</p>
<ol>
<li>Where to find the Service documentation + WSDL and what are the information available in there.</li>
<li>How to generate the PHP client from the WSDL using wsdlphp tool.</li>
<li>What is in the php file generated from the wsdl2php tool and how you select the required operations to invoke.</li>
<li>How to fill the input parameter for the web service operation</li>
<li>How to handle the response returned from the service.</li>
<li>Finally It shows some different ways the data that you are extracting from the service, can be presented to your user.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/10/29/screencast-how-to-consume-a-web-service-using-wsfphp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DEMO on a SOAP and REST Client with PHP</title>
		<link>http://www.dimuthu.org/blog/2008/10/17/demo-on-a-soap-and-rest-client-with-php/</link>
		<comments>http://www.dimuthu.org/blog/2008/10/17/demo-on-a-soap-and-rest-client-with-php/#comments</comments>
		<pubDate>Fri, 17 Oct 2008 16:50:57 +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[demo]]></category>
		<category><![CDATA[SOAP]]></category>
		<category><![CDATA[WSClient]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=478</guid>
		<description><![CDATA[Last week I wrote a how to on Writing a SOAP and REST Service with PHP. It shows how to write a single script that enables the SOAP and REST web services interfaces using WSF/PHP. Today I&#8217;m going to show you how you can use WSF/PHP to write clients in both SOAP and REST form. [...]]]></description>
			<content:encoded><![CDATA[<p>Last week I wrote a <a href="http://www.dimuthu.org/blog/2008/10/10/writing-a-simple-rest-and-soap-service-with-php/">how to on Writing a SOAP and REST Service with PHP</a>. It shows how to write a single script that enables the SOAP and REST web services interfaces using <a href="http://wso2.org/projects/wsf/php">WSF/PHP</a>. Today I&#8217;m going to show you how you can use WSF/PHP to write clients in both SOAP and REST form.</p>
<p>For that I use the <a href="http://labs.wso2.org/wsf/php/resource_view.php?url=AmazonClient">Amazon Client Demo</a> hosted in the <a href="http://labs.wso2.org/wsf/php">PHP Web Services Demo Site</a>. With this demo you can do shopping with Amazon using their web services API. It uses <a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2FAmazon%2FAmazonClient.php">a php library (AmazonClient.php) </a>that allows us to connect Amazon using SOAP or REST libraries.</p>
<p>You can see in <a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2FAmazon%2FAmazonClient.php">the library code</a> It is using different values for &#8220;useSOAP&#8221; argument depending on what form of messaging we like to use. Amazon SOAP service uses the SOAP 1.1 and the REST service uses the &#8220;GET&#8221; HTTP method for messaging. We can configure these details as mentioned in the following table.</p>
<table border="1px" style="width:500px">
<tbody>
<tr style="background: #666666">
<td>REST</td>
<td>SOAP</td>
</tr>
<tr>
<td>
<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;">"to"</span>=&gt;self::<span style="color: #006600;">AMAZON_REST_ENDPOINT</span>,
      <span style="color: #ff0000;">"HTTPMethod"</span>=&gt;<span style="color: #ff0000;">"GET"</span>,
      <span style="color: #ff0000;">"useSOAP"</span> =&gt; <span style="font-weight: bold; color: #000000;">FALSE</span><span style="color: #66cc66;">)</span></pre>
</td>
<td>
<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;">"to"</span>=&gt;self::<span style="color: #006600;">AMAZON_SOAP_ENDPOINT</span>,
      <span style="color: #ff0000;">"useSOAP"</span> =&gt; <span style="color: #ff0000;">"1.1"</span>,
      <span style="color: #ff0000;">"action"</span> =&gt; <span style="color: #ff0000;">"http://soap.amazon.com"</span><span style="color: #66cc66;">)</span></pre>
</td>
</tr>
</tbody>
</table>
<p>Since Amazon requires different request messages for SOAP and REST services, we have to create them separately depending on the request type. But the response returns by the service is same in both cases so we can handle it using the same code.</p>
<p>Here is how ItemLookup operation of the Amazon service is written within the above mentioned constrains.</p>
<pre class="php">    <span style="font-style: italic; color: #808080;">/**
     * ItemLookup
     * @param $ASIN Amaxon Item Id
     * @return associate array consist of the response parameters
     */</span>
    <span style="font-weight: bold; color: #000000;">public</span> <span style="font-weight: bold; color: #000000;">function</span> ItemLookup<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$ASIN</span><span style="color: #66cc66;">)</span>
    <span style="color: #66cc66;">{</span>

        <span style="color: #b1b100;">if</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">is_soap</span><span style="color: #66cc66;">)</span>
        <span style="color: #66cc66;">{</span>
             <span style="color: #0000ff;">$req_payload</span> = &lt;&lt;&lt;XML
                &lt;ItemLookup xmlns=<span style="color: #ff0000;">"http://webservices.amazon.com/AWSECommerceService/2007-10-29"</span>&gt;
                    &lt;SubscriptionId&gt;<span style="color: #66cc66;">{</span><span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">amazon_key</span><span style="color: #66cc66;">}</span>&lt;/SubscriptionId&gt;
                    &lt;ResponseGroup&gt;Medium&lt;/ResponseGroup&gt;
                    &lt;Request&gt;
                        &lt;ItemId&gt;<span style="color: #66cc66;">{</span><span style="color: #0000ff;">$ASIN</span><span style="color: #66cc66;">}</span>&lt;/ItemId&gt;
                        &lt;ReviewPage&gt;<span style="color: #cc66cc;">1</span>&lt;/ReviewPage&gt;
                    &lt;/Request&gt;
                &lt;/ItemLookup&gt;
XML;
        <span style="color: #66cc66;">}</span>
        <span style="color: #b1b100;">else</span>
        <span style="color: #66cc66;">{</span>
             <span style="color: #0000ff;">$req_payload</span> = &lt;&lt;&lt;XML
                &lt;ItemLookup xmlns=<span style="color: #ff0000;">"http://webservices.amazon.com/AWSECommerceService/2007-10-29"</span>&gt;
                    &lt;SubscriptionId&gt;<span style="color: #66cc66;">{</span><span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">amazon_key</span><span style="color: #66cc66;">}</span>&lt;/SubscriptionId&gt;
                    &lt;Service&gt;AWSECommerceService&lt;/Service&gt;
                    &lt;ResponseGroup&gt;Large&lt;/ResponseGroup&gt;
                    &lt;Operation&gt;ItemLookup&lt;/Operation&gt;
                    &lt;ItemId&gt;<span style="color: #66cc66;">{</span><span style="color: #0000ff;">$ASIN</span><span style="color: #66cc66;">}</span>&lt;/ItemId&gt;
                    &lt;ReviewPage&gt;<span style="color: #cc66cc;">1</span>&lt;/ReviewPage&gt;
                &lt;/ItemLookup&gt;
XML;
        <span style="color: #66cc66;">}</span>

        <span style="color: #0000ff;">$ret_message</span> = <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">request</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$req_payload</span><span style="color: #66cc66;">)</span>;

        <span style="color: #0000ff;">$simplexml</span> = <span style="font-weight: bold; color: #000000;">new</span> SimpleXMLElement<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$ret_message</span>-&gt;<span style="color: #006600;">str</span><span style="color: #66cc66;">)</span>;

        <span style="color: #0000ff;">$res</span> = <span style="color: #0000ff;">$simplexml</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/10/17/demo-on-a-soap-and-rest-client-with-php/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>WSClient WSDL Mode With Array Based API</title>
		<link>http://www.dimuthu.org/blog/2008/10/08/wsclient-wsdl-mode-with-array-based-api/</link>
		<comments>http://www.dimuthu.org/blog/2008/10/08/wsclient-wsdl-mode-with-array-based-api/#comments</comments>
		<pubDate>Wed, 08 Oct 2008 14:53:55 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<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[array based]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[WSClient]]></category>
		<category><![CDATA[wsdl mode]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=454</guid>
		<description><![CDATA[In WSF/PHP WDL Mode we have two APIs, first one is the class based API which we give a class object as the input parameter for the operation and expect to retrieve a class object as the response as well. The other API is the array based API. which we give an array (in fact [...]]]></description>
			<content:encoded><![CDATA[<p>In WSF/PHP WDL Mode we have two APIs, first one is the class based API which we give a class object as the input parameter for the operation and expect to retrieve a class object as the response as well. The other API is the array based API. which we give an array (in fact an associated map) containing all the necessary information and returns an array filled with response information.</p>
<p>If you are using WSDL2PHP script you are always using the class based API. But there are situations where you can easily use array based API instead of the class based API. Here is an example.</p>
<p>Take the simple add operation of the following WSDL, <a href="http://labs.wso2.org/wsf/php/example.xml">http://labs.wso2.org/wsf/php/example.xml</a>.</p>
<p>If you generated the code using <a href="http://labs.wso2.org/wsf/php/wsdl2phptool.php">wsdlphp tool</a> (<a href="http://labs.wso2.org/wsf/php/wsdl2phptool.php?wsdl_url=http%3A%2F%2Flabs.wso2.org%2Fwsf%2Fphp%2Fexample.xml">Here</a> is the complete generated code for the above wsdl using online wsdlphp tool) You can see two classes are generated for the above operation, one for the input object and the other for the output object.</p>
<pre class="php"><span style="font-weight: bold; color: #000000;">class</span> simpleAdd <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;">$param0</span>;

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

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

<span style="font-weight: bold; color: #000000;">class</span> simpleAddResponse <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;">$return</span>;

<span style="color: #66cc66;">}</span></pre>
<p>So in order to invoke the service you need to create an object of the simpleAdd and set your input parameters and return the value from the simpleAddResponse object.</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="color: #0000ff;">$input</span>-&gt;<span style="color: #006600;">param0</span> = <span style="color: #cc66cc;">3</span>;
  <span style="color: #0000ff;">$input</span>-&gt;<span style="color: #006600;">parma1</span> = <span style="color: #cc66cc;">4</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;">  // extract the return value</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>;</pre>
<p>But if you are using array mode for the same operation it will be something like this.</p>
<pre class="php">  <span style="font-style: italic; color: #808080;">// input as an array</span>
  <span style="color: #0000ff;">$input</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"param0"</span> =&gt; <span style="color: #cc66cc;">3</span>, <span style="color: #ff0000;">"param1"</span> =&gt; <span style="color: #cc66cc;">4</span><span style="color: #66cc66;">)</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;">// extract out the return value from the array</span>
  <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #0000ff;">$response</span><span style="color: #66cc66;">[</span><span style="color: #ff0000;">"return"</span><span style="color: #66cc66;">]</span>;</pre>
<p>In this approach you don&#8217;t need to declare classes at the start. So you can write the code without the support of WSDL2PHP tool. Anyway for complex scenarios it is not easy to find the keys needed to be in the input array, so it is better depend on the generated code. But you can use array based approach more productively for simple scenarios like this.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/10/08/wsclient-wsdl-mode-with-array-based-api/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Invoking WSF/PHP Web Services Through Proxy</title>
		<link>http://www.dimuthu.org/blog/2008/10/06/invoking-wsfphp-web-services-through-proxy/</link>
		<comments>http://www.dimuthu.org/blog/2008/10/06/invoking-wsfphp-web-services-through-proxy/#comments</comments>
		<pubDate>Mon, 06 Oct 2008 16:28:40 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[axis2/c]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[axis2.xml]]></category>
		<category><![CDATA[proxy]]></category>
		<category><![CDATA[proxyHost]]></category>
		<category><![CDATA[proxyPort]]></category>
		<category><![CDATA[WSClient]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=446</guid>
		<description><![CDATA[If you are behind a proxy server you need to configure your client to send the request through proxy. With WSF/PHP you can do it in two ways. 1. Setting proxy configuration in WSClient itself You can use the &#8216;proxyHost&#8217; and &#8216;proxyPort&#8217; options to provide the proxy information through WSClient. $client = new WSClient(array("to" =&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>If you are behind a proxy server you need to configure your client to send the request through proxy. With <a href="http://wso2.org/projects/wsf/php">WSF/PHP</a> you can do it in two ways.</p>
<p><strong>1. Setting proxy configuration in WSClient itself</strong></p>
<p>You can use the &#8216;proxyHost&#8217; and &#8216;proxyPort&#8217; options to provide the proxy information through <a href="http://wso2.org/project/wsf/php/2.0.0/docs/api_content.html#client">WSClient</a>.</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://my.external.host/service_url"</span>,
                  <span style="color: #ff0000;">"proxyHost"</span> =&gt; PROXY_HOST,
                  <span style="color: #ff0000;">"proxyPort"</span> =&gt; PROXY_PORT<span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;</pre>
<p><strong>2. Use the axis2.xml</strong></p>
<p>Change the <a href="http://ws.apache.org/axis2/c/docs/axis2c_manual.html#appA">axis2.xml</a> to the following. (axis2.xml is in the wsf_c directory which is by default installed inside the php extension directory unless you specified it explicitly in your php.ini &#8216;wsf.home&#8217; entry)</p>
<pre class="xml">    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;transportSender</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"http"</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"axis2_http_sender"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;parameter</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"PROTOCOL"</span> <span style="color: #000066;">locked</span>=<span style="color: #ff0000;">"false"</span><span style="font-weight: bold; color: black;">&gt;</span></span>HTTP/1.1<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/parameter<span style="font-weight: bold; color: black;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;parameter</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"xml-declaration"</span> <span style="color: #000066;">insert</span>=<span style="color: #ff0000;">"false"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
      <span style="color: #009900;"><span style="font-style: italic; color: #808080;">&lt;!--Here is where you set the proxy host and the port--&gt;</span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;parameter</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"PROXY"</span> <span style="color: #000066;">proxy_host</span>=<span style="color: #ff0000;">"MY_PROXY_HOST"</span> <span style="color: #000066;">proxy_port</span>=<span style="color: #ff0000;">"MY_PROXY_IP"</span> <span style="color: #000066;">locked</span>=<span style="color: #ff0000;">"true"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/transportSender<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>So if you want only to use the proxy for particular clients, you can use the former approach. But if you want to use the proxy for all the clients in your system just use the later approach so you don&#8217;t need to edit each client.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/10/06/invoking-wsfphp-web-services-through-proxy/feed/</wfw:commentRss>
		<slash:comments>5</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>
	</channel>
</rss>

