<?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; xml schema</title>
	<atom:link href="http://www.dimuthu.org/catagory/xml-schema/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>WSF/PHP Code First Approach: Returning an Array of String</title>
		<link>http://www.dimuthu.org/blog/2010/01/08/wsfphp-code-first-approach-returning-an-array-of-string/</link>
		<comments>http://www.dimuthu.org/blog/2010/01/08/wsfphp-code-first-approach-returning-an-array-of-string/#comments</comments>
		<pubDate>Fri, 08 Jan 2010 02:05:12 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[WSDL]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[xml schema]]></category>
		<category><![CDATA[code first]]></category>
		<category><![CDATA[wsdl generation]]></category>

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

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

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

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

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

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

 
    <span style="color: #808080; font-style: italic;">// call the operation</span>
    <span style="color: #0000ff;">$response</span> = <span style="color: #0000ff;">$proxy</span>-&gt;<span style="color: #006600;">splitMe</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$input</span><span style="color: #66cc66;">)</span>;
    <a href="http://www.php.net/print_r"><span style="color: #000066;">print_r</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$response</span><span style="color: #66cc66;">)</span>;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2010/01/08/wsfphp-code-first-approach-returning-an-array-of-string/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Code Generate Custom SOAP Faults For Axis2/C</title>
		<link>http://www.dimuthu.org/blog/2009/02/09/code-generate-custom-soap-faults-for-axis2c/</link>
		<comments>http://www.dimuthu.org/blog/2009/02/09/code-generate-custom-soap-faults-for-axis2c/#comments</comments>
		<pubDate>Mon, 09 Feb 2009 06:04:41 +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[SOA]]></category>
		<category><![CDATA[tool]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[WSDL]]></category>
		<category><![CDATA[wsdl2c]]></category>
		<category><![CDATA[xml schema]]></category>
		<category><![CDATA[custom]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[faults]]></category>
		<category><![CDATA[handling]]></category>
		<category><![CDATA[SOAP]]></category>
		<category><![CDATA[throwing]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=916</guid>
		<description><![CDATA[Web services use SOAP faults to report fault cases back to clients. The faults can be generated from the SOAP framework in a case of invalid SOAP messages, invalid security tokens or they can be generated from the service business logic itself. The fault messages may contain simply a string indicating the error, or it [...]]]></description>
			<content:encoded><![CDATA[<p>Web services use SOAP faults to report fault cases back to clients. The faults can be generated from the SOAP framework in a case of invalid SOAP messages, invalid security tokens or they can be generated from the service business logic itself. The fault messages may contain simply a string indicating the error, or it may contain lot of details which could be useful to the clients find the problem. In fact the format of the SOAP fault is a standard. But services can send custom details within the details element in a SOAP fault.</p>
<pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;soapenv:Envelope</span> <span style="color: #000066;">xmlns:soapenv</span>=<span style="color: #ff0000;">"http://schemas.xmlsoap.org/soap/envelope/"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
   <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;soapenv:Body<span style="font-weight: bold; color: black;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;soapenv:Fault<span style="font-weight: bold; color: black;">&gt;</span></span></span>
         <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;faultcode<span style="font-weight: bold; color: black;">&gt;</span></span></span>soapenv:Sender<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/faultcode<span style="font-weight: bold; color: black;">&gt;</span></span></span>
         <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;faultstring<span style="font-weight: bold; color: black;">&gt;</span></span></span>..<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/faultstring<span style="font-weight: bold; color: black;">&gt;</span></span></span>
         <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;detail<span style="font-weight: bold; color: black;">&gt;</span></span></span> You Custom Message <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/detail<span style="font-weight: bold; color: black;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/soapenv:Fault<span style="font-weight: bold; color: black;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/soapenv:Body<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/soapenv:Envelope<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>And you can define the schema of your custom fault message in a WSDL, so the clients can prepare to handle fault scenarios. In facts tools like <a href="http://ws.apache.org/axis2/">Apache Axis2</a> WSDL2C, WSDL2Java tool will help you to work with custom faults when they are defined in the WSDL.  Here is an example section of a WSDL with an operation which can throw two faults &#8220;MyFirstException&#8221;, &#8220;MySecondException&#8221;.</p>
<pre class="xml"><span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- fault schemas --&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;types<span style="font-weight: bold; color: black;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;schema</span> ..<span style="font-weight: bold; color: black;">&gt;</span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"MyFirstException"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
   <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;complexType<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;sequence<span style="font-weight: bold; color: black;">&gt;</span></span></span>
     <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"text"</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;/sequence<span style="font-weight: bold; color: black;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/complexType<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/element<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- fault element --&gt;</span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"MySecondException"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
   <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;complexType<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;sequence<span style="font-weight: bold; color: black;">&gt;</span></span></span>
     <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"number"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"xsd:int"</span><span style="color: #ff0000;"></span><span style="font-weight: bold; color: black;">/&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/sequence<span style="font-weight: bold; color: black;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/complexType<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/element<span style="font-weight: bold; color: black;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/schema<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/types<span style="font-weight: bold; color: black;">&gt;</span></span></span>

<span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- the fault messages --&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;message</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"MySecondExceptionFault"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
 <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;part</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"fault"</span> <span style="color: #000066;">element</span>=<span style="color: #ff0000;">"ns1:MySecondException"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/message<span style="font-weight: bold; color: black;">&gt;</span></span></span>

<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;message</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"MyFirstExceptionFault"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
 <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;part</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"fault"</span> <span style="color: #000066;">element</span>=<span style="color: #ff0000;">"ns1:MyFirstException"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/message<span style="font-weight: bold; color: black;">&gt;</span></span></span>

<span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- operation to throw fault --&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;portType</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"MyType"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
 <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;operation</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"myOperation"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;input</span> <span style="color: #000066;">message</span>=<span style="color: #ff0000;">"tns:myOperationRequest"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;output</span> <span style="color: #000066;">message</span>=<span style="color: #ff0000;">"tns:myOperationResponse"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;fault</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"MySecondException"</span> <span style="color: #000066;">message</span>=<span style="color: #ff0000;">"tns:MySecondExceptionFault"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;fault</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"MyFirstException"</span> <span style="color: #000066;">message</span>=<span style="color: #ff0000;">"tns:MyFirstExceptionFault"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
 <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/operation<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/portType<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>Note that the operation &#8220;myOperation&#8221; is throwing faults &#8220;MyFirstException&#8221;, &#8220;MySecondExcpetion&#8221;. If you generate the Java code for this operation, it would be simple as this,</p>
<pre class="java"><span style="color: #000000; font-weight: bold;">public</span> MyOperationRequest
MyOperation<span style="color: #66cc66;">(</span>MyOperationRequest<span style="color: #66cc66;">)</span> <span style="color: #000000; font-weight: bold;">throws</span>
          MyFirstExcpetion,
          MySecondExcpetion <span style="color: #66cc66;">{</span>
  <span style="color: #808080; font-style: italic;">// here is your business logic</span>
<span style="color: #66cc66;">}</span></pre>
<p>Anyway we are going to write codes in &#8216;C&#8217; language, which doesn&#8217;t have similar exception mechanism. Let see how we can do it, starting with writing the service and then writing a client.</p>
<p><strong>Writing Services With Custom SOAP Faults</strong></p>
<p>Once you generate the &#8216;C&#8217; codes for the WSDL using WSDL2C tool, you should first have a look at the skeleton header file.</p>
<pre class="c">    <span style="color: #808080; font-style: italic;">/**
     * the generated fault union for operation "myOperation|urn:myuri:1.0",
     * in a case you want to return a fault, put the appropriate adb object for
     * the union variable pointer comes as the last parameter of the method
     */</span>
    <span style="color: #993333;">typedef</span> <span style="color: #993333;">union</span>
    <span style="color: #66cc66;">{</span>
        adb_MyFirstException_t* MyFirstException;
        adb_MySecondException_t* MySecondException;

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

    <span style="color: #808080; font-style: italic;">/**
     * auto generated function declaration
     * for "myOperation|urn:myuri:1.0" operation.
     * @param env environment ( mandatory)
     * @param _myOperation of the adb_myOperation_t*
     *
     * @return adb_myOperationResponse_t*
     */</span>
    adb_myOperationResponse_t* axis2_skel_MyService_myOperation<span style="color: #66cc66;">(</span><span style="color: #993333;">const</span> axutil_env_t *env,
                                      adb_myOperation_t* _myOperation,
                                      axis2_skel_MyService_myOperation_fault *fault<span style="color: #66cc66;">)</span>;</pre>
<p>And at the very end of the header file, you will see an enumeration of constants corresponding to each fault is generated.</p>
<pre class="c">    <span style="color: #993333;">typedef</span> <span style="color: #000000; font-weight: bold;">enum</span>
    <span style="color: #66cc66;">{</span>
        AXIS2_SKEL_MYSERVICE_ERROR_NONE = AXIS2_SKEL_MYSERVICE_ERROR_CODES_START,

        AXIS2_SKEL_MYSERVICE_MYOPERATION_FAULT_MYFIRSTEXCEPTION,
        AXIS2_SKEL_MYSERVICE_MYOPERATION_FAULT_MYSECONDEXCEPTION,

        AXIS2_SKEL_MYSERVICE_ERROR_LAST

    <span style="color: #66cc66;">}</span> axis2_skel_MyService_error_codes;</pre>
<p>That&#8217;s all you need to aware of. The plan is whenever you need to report the fault, you have to do three things inside the business logic.</p>
<ol>
<li>Create the adb object for the fault, in this case either &#8220;adb_MyFirstException_t&#8221; or &#8220;adb_MySecondException_t&#8221; and set it to the fault pointer variable.</li>
<li>Set the constant corresponding to the fault using &#8220;AXIS2_ERROR_SET&#8221; function</li>
<li>return NULL</li>
</ol>
<p>Here is an example how you do it inside the actual business logic code.</p>
<pre class="c">    adb_myOperationResponse_t* axis2_skel_MyService_myOperation<span style="color: #66cc66;">(</span><span style="color: #993333;">const</span> axutil_env_t *env,
                                      adb_myOperation_t* myOperation,
                                      axis2_skel_MyService_myOperation_fault *fault <span style="color: #66cc66;">)</span>
    <span style="color: #66cc66;">{</span>
        <span style="color: #808080; font-style: italic;">/* the buisness logic */</span>

        ....

        <span style="color: #b1b100;">if</span><span style="color: #66cc66;">(</span><span style="color: #808080; font-style: italic;">/* checking some condition to throw the "MyFirstException" fault */</span><span style="color: #66cc66;">)</span>
        <span style="color: #66cc66;">{</span>
          <span style="color: #808080; font-style: italic;">/* 1. Creating the adb object and set it to the fault pointer variable */</span>
          adb_MyFirstException_t *exp = <span style="color: #000000; font-weight: bold;">NULL</span>;
          exp = adb_MyFirstException_create<span style="color: #66cc66;">(</span>env<span style="color: #66cc66;">)</span>;
          adb_MyFirstException_set_text<span style="color: #66cc66;">(</span>exp, env, <span style="color: #ff0000;">"this is the exception 1"</span><span style="color: #66cc66;">)</span>; <span style="color: #808080; font-style: italic;">/* custom value */</span>

          fault-&gt;MyFirstException = exp;

          <span style="color: #808080; font-style: italic;">/* 2. Setting the error constant corrosponding to the fault */</span>
          AXIS2_ERROR_SET<span style="color: #66cc66;">(</span>env-&gt;error,
                      AXIS2_SKEL_MYSERVICE_MYOPERATION_FAULT_MYFIRSTEXCEPTION,
                      AXIS2_FAILURE<span style="color: #66cc66;">)</span>;

          <span style="color: #808080; font-style: italic;">/* 3. Returning NULL */</span>
          <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">NULL</span>;
        <span style="color: #66cc66;">}</span>

        <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #66cc66;">(</span><span style="color: #808080; font-style: italic;">/* checking some condition to throw the "MySecondException" fault */</span><span style="color: #66cc66;">)</span>
        <span style="color: #66cc66;">{</span>
          <span style="color: #808080; font-style: italic;">/* 1. Creating the adb object and set it to the fault pointer variable */</span>
          adb_MySecondException_t *exp = <span style="color: #000000; font-weight: bold;">NULL</span>;
          exp = adb_MySecondException_create<span style="color: #66cc66;">(</span>env<span style="color: #66cc66;">)</span>;
          adb_MySecondException_set_number<span style="color: #66cc66;">(</span>exp, env, <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">)</span>;<span style="color: #808080; font-style: italic;">/* custom value */</span>

          fault-&gt;MySecondException = exp;

          <span style="color: #808080; font-style: italic;">/* 2. Setting the error constant corrosponding to the fault */</span>
          AXIS2_ERROR_SET<span style="color: #66cc66;">(</span>env-&gt;error,
                      AXIS2_SKEL_MYSERVICE_MYOPERATION_FAULT_MYSECONDEXCEPTION,
                      AXIS2_FAILURE<span style="color: #66cc66;">)</span>;
          <span style="color: #808080; font-style: italic;">/* 3. Returning NULL */</span>
          <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">NULL</span>;
        <span style="color: #66cc66;">}</span>

        <span style="color: #808080; font-style: italic;">/* return the response in no fault scenario */</span>
        <span style="color: #b1b100;">return</span> response;
    <span style="color: #66cc66;">}</span></pre>
<p>That&#8217;s all you have to do, Axis2/C will make sure to build the fault and put your custom message inside the details element.</p>
<p><strong>Writing Clients  to Handle custom SOAP Faults</strong></p>
<p>After generating the code for clients using WSDL2C tool, this time you should look at the generated stub header file first. It is just similar to the skeleton header files may be except all the &#8220;skel&#8221; prefixes are renamed to &#8220;stub&#8221; and additional parameter &#8220;stub&#8221; for the operation.</p>
<pre class="c">    <span style="color: #808080; font-style: italic;">/**
     * the generated fault union for operation "myOperation|urn:myuri:1.0",
     * in a case the server return a fault, the corresponding adb object will be loaded for
     * the union variable pointer comes as the last parameter of the method
     */</span>
    <span style="color: #993333;">typedef</span> <span style="color: #993333;">union</span>
    <span style="color: #66cc66;">{</span>
        adb_MyFirstException_t* MyFirstException;
        adb_MySecondException_t* MySecondException;

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

    <span style="color: #808080; font-style: italic;">/**
     * auto generated function declaration
     * for "myOperation|urn:myuri:1.0" operation.
     * @param env environment ( mandatory)
     * @param _myOperation of the adb_myOperation_t*
     *
     * @return adb_myOperationResponse_t*
     */</span>
    adb_myOperationResponse_t* axis2_stub_MyService_myOperation<span style="color: #66cc66;">(</span>axis2_stub_t* stub, <span style="color: #993333;">const</span> axutil_env_t *env,
                                      adb_myOperation_t* _myOperation,
                                      axis2_stub_MyService_myOperation_fault *fault<span style="color: #66cc66;">)</span>;

    <span style="color: #993333;">typedef</span> <span style="color: #000000; font-weight: bold;">enum</span>
    <span style="color: #66cc66;">{</span>
        AXIS2_STUB_MYSERVICE_ERROR_NONE = AXIS2_STUB_MYSERVICE_ERROR_CODES_START,

        AXIS2_STUB_MYSERVICE_MYOPERATION_FAULT_MYFIRSTEXCEPTION,
        AXIS2_STUB_MYSERVICE_MYOPERATION_FAULT_MYSECONDEXCEPTION,

        AXIS2_STUB_MYSERVICE_ERROR_LAST

    <span style="color: #66cc66;">}</span> axis2_stub_MyService_error_codes;</pre>
<p>Looking at this, you may have got the idea how to differentiate what fault is being thrown by the server and how to extract the parameters of the custom fault. Here is an example client code correctly handling exceptions.</p>
<pre class="c">    <span style="color: #808080; font-style: italic;">/* the structure to keep the fault */</span>
    axis2_stub_MyService_myOperation_fault fault;

    ..... <span style="color: #808080; font-style: italic;">/* the part preparing the request is ignored here */</span>

    <span style="color: #808080; font-style: italic;">/* invoking the "myOperation" operation */</span>
    response = axis2_stub_op_MyService_myOperation<span style="color: #66cc66;">(</span>stub, env, op, &amp;fault<span style="color: #66cc66;">)</span>;

    <span style="color: #808080; font-style: italic;">/* checking the response == NULL implies fault is sent  */</span>
    <span style="color: #b1b100;">if</span><span style="color: #66cc66;">(</span>response == <span style="color: #000000; font-weight: bold;">NULL</span><span style="color: #66cc66;">)</span>
    <span style="color: #66cc66;">{</span>
        <span style="color: #808080; font-style: italic;">/* getting the error number to distinguish the fault */</span>
        error_code = env-&gt;error-&gt;error_number;

        <span style="color: #808080; font-style: italic;">/* compare error code with constants of each faults */</span>
        <span style="color: #b1b100;">if</span><span style="color: #66cc66;">(</span>error_code == AXIS2_STUB_MYSERVICE_MYOPERATION_FAULT_MYFIRSTEXCEPTION<span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>

            <span style="color: #808080; font-style: italic;">/* extracting out the adb objects */</span>
            axis2_char_t *text = adb_MyFirstException_get_text<span style="color: #66cc66;">(</span>fault.<span style="color: #202020;">MyFirstException</span>, env<span style="color: #66cc66;">)</span>;

            <span style="color: #808080; font-style: italic;">/* do a printf of the message */</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 First Exception called: with param %s<span style="color: #000099; font-weight: bold;">\\</span>n"</span>, text<span style="color: #66cc66;">)</span>;

        <span style="color: #66cc66;">}</span>
        <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #66cc66;">(</span>error_code == AXIS2_STUB_MYSERVICE_MYOPERATION_FAULT_MYSECONDEXCEPTION<span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>
            <span style="color: #808080; font-style: italic;">/* extracting out the adb objects */</span>
            <span style="color: #993333;">int</span> number = adb_MySecondException_get_number<span style="color: #66cc66;">(</span>fault.<span style="color: #202020;">MySecondException</span>, env<span style="color: #66cc66;">)</span>;

            <span style="color: #808080; font-style: italic;">/* do a printf of the message */</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 Second Exception called: with param %d<span style="color: #000099; font-weight: bold;">\\</span>n"</span>, number<span style="color: #66cc66;">)</span>;

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

    <span style="color: #66cc66;">}</span></pre>
<p>Note that this feature is available only in the very latest WSDL2C tool. Try to get latest build from <a href="http://ws.apache.org/axis2">Axis2/Java</a> to use this up to date tool.</p>
<p>You can download the WSDL and codes used in this example from here, <a href="https://issues.apache.org/jira/secure/attachment/12399724/case45.zip">https://issues.apache.org/jira/secure/attachment/12399724/case45.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2009/02/09/code-generate-custom-soap-faults-for-axis2c/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Sending Binary with Apache Axis2/C ADB</title>
		<link>http://www.dimuthu.org/blog/2008/11/24/sending-binary-with-apache-axis2c-adb/</link>
		<comments>http://www.dimuthu.org/blog/2008/11/24/sending-binary-with-apache-axis2c-adb/#comments</comments>
		<pubDate>Mon, 24 Nov 2008 18:21:22 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[adb]]></category>
		<category><![CDATA[axis2/c]]></category>
		<category><![CDATA[codegen]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[tool]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[wsdl2c]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[xml schema]]></category>
		<category><![CDATA[base64 binary]]></category>
		<category><![CDATA[binary]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=716</guid>
		<description><![CDATA[Axis2/C ADB is a C language binding to the XML schema. ADB object model represents an XML specific to a given schema in a WSDL. You can use the Axis2 codegen tool to generate ADB codes for your WSDL and use that to build and parse your XMLs. The idea is, if you use ADB [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://ws.apache.org/axis2/c/">Axis2/C</a> ADB  is a C language binding to the XML schema. ADB object model represents an  XML specific to a given schema in a WSDL. You can use the Axis2 codegen tool to generate ADB codes for your WSDL and use that to build and parse your XMLs. The idea is, if you use ADB to build and parse your xmls, it will be really easy to do that  and you don&#8217;t need to know or understand anything about the schema or the wsdl.</p>
<p>Apache Axis2/C to can be used to send and receive binaries as MTOM, SWA or base64 encoded. But ADB generated code still support to send and receive base64 encoded binaries only. So if you use contract first approach  with Axis2/C (i.e start with the WSDL, then write the service based on that), you have to use base64-encoded (non-optimized) as the binary transferring method. Note that you can use the other methods like MTOM or SWA, if you write the code to build and parse the xmls from AXIOM which is a general model for XML like DOM.</p>
<p>Say you have an element with base64Binary type in your request XML. So the schema for that element would be,</p>
<pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:complexType</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"Person"</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:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"image"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"xs:base64Binary"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
        ... <span style="color: #009900;"><span style="font-style: italic; color: #808080;">&lt;!-- some more elements --&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></pre>
<p>After you code generated, you will get the adb_person.h and adb_person.c files with the following function prototypes and the implementations,</p>
<pre class="c">        <span style="font-style: italic; color: #808080;">/**
         * Constructor for creating adb_Person_t
         * @param env pointer to environment struct
         * @return newly created adb_Person_t object
         */</span>
        adb_Person_t* AXIS2_CALL
        adb_Person_create<span style="color: #66cc66;">(</span>
            <span style="color: #993333;">const</span> axutil_env_t *env <span style="color: #66cc66;">)</span>;

        <span style="font-style: italic; color: #808080;">/**
         * Free adb_Person_t object
         * @param  _Person adb_Person_t object to free
         * @param env pointer to environment struct
         * @return AXIS2_SUCCESS on success, else AXIS2_FAILURE
         */</span>
        axis2_status_t AXIS2_CALL
        adb_Person_free <span style="color: #66cc66;">(</span>
            adb_Person_t* _Person,
            <span style="color: #993333;">const</span> axutil_env_t *env<span style="color: #66cc66;">)</span>;

        <span style="font-style: italic; color: #808080;">/**
         * Getter for image.
         * @param  _Person adb_Person_t object
         * @param env pointer to environment struct
         * @return axutil_base64_binary_t*
         */</span>
        axutil_base64_binary_t* AXIS2_CALL
        adb_Person_get_image<span style="color: #66cc66;">(</span>
            adb_Person_t* _Person,
            <span style="color: #993333;">const</span> axutil_env_t *env<span style="color: #66cc66;">)</span>;

        <span style="font-style: italic; color: #808080;">/**
         * Setter for image.
         * @param  _Person adb_Person_t object
         * @param env pointer to environment struct
         * @param arg_image axutil_base64_binary_t*
         * @return AXIS2_SUCCESS on success, else AXIS2_FAILURE
         */</span>
        axis2_status_t AXIS2_CALL
        adb_Person_set_image<span style="color: #66cc66;">(</span>
            adb_Person_t* _Person,
            <span style="color: #993333;">const</span> axutil_env_t *env,
            axutil_base64_binary_t*  arg_image<span style="color: #66cc66;">)</span>;</pre>
<p>So you can manipulate the person element in c language using the create, get, set and free function.</p>
<pre class="c">    <span style="font-style: italic; color: #808080;">/* here the env is the axutil_env_t* instance - the axis2/c environment */</span>
    FILE *f = fopen<span style="color: #66cc66;">(</span><span style="color: #ff0000;">"./images/person.png"</span>, <span style="color: #ff0000;">"r+"</span><span style="color: #66cc66;">)</span>;
    <span style="color: #993333;">int</span> binary_count;
    <span style="font-style: italic; color: #808080;">/* binary read a function you may write to read the binary data to the
     variable binary and the count to the variable binary_count */</span>
    <span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> *binary = binary_read<span style="color: #66cc66;">(</span>f, env, &amp;binary_count<span style="color: #66cc66;">)</span>;
    axutil_base64_binary_t *base64 = axutil_base64_binary_create_with_plain_binary<span style="color: #66cc66;">(</span>
                                        env, binary, binary_count<span style="color: #66cc66;">)</span>;

    adb_Person_t *person = adb_Person_create<span style="color: #66cc66;">(</span>env<span style="color: #66cc66;">)</span>;
    adb_Person_set_image<span style="color: #66cc66;">(</span>person, env, base64<span style="color: #66cc66;">)</span>;</pre>
<p>You can set this adb person directly to your request or to a setter of another adb instance to complete the ADB tree. So this way you can send binaries (as base64 encoded) using the Axis2/C ADB generated code.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/11/24/sending-binary-with-apache-axis2c-adb/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WS-SecurityPolicy With PHP</title>
		<link>http://www.dimuthu.org/blog/2008/11/19/ws-securitypolicy-with-php/</link>
		<comments>http://www.dimuthu.org/blog/2008/11/19/ws-securitypolicy-with-php/#comments</comments>
		<pubDate>Wed, 19 Nov 2008 16:20:43 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[DataServices]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[WSDL]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[xml schema]]></category>
		<category><![CDATA[policy]]></category>
		<category><![CDATA[ws-policy]]></category>
		<category><![CDATA[ws-security]]></category>
		<category><![CDATA[ws-security policy]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=647</guid>
		<description><![CDATA[WS-SecurityPolicy specification defines standards for defining security policies for your web service. WSF/PHP allows you to declare your security policies according to these standards. You can take one of following approaches to associate policies to your web service or client. PHP Array to represent your policies Policy file compliant with WS-Security Policy. Declaring policies inline [...]]]></description>
			<content:encoded><![CDATA[<p>WS-SecurityPolicy specification defines standards for defining security policies for your web service.<a href="http://wso2.org/projects/wsf/php"> WSF/PHP</a> allows you to declare your security policies according to these standards.</p>
<p>You can take one of following approaches to associate policies to your web service or client.</p>
<ul>
<li>PHP Array to represent your policies</li>
<li>Policy file compliant with WS-Security Policy.</li>
<li>Declaring policies inline with the WSDL.</li>
</ul>
<p><strong>Declaring Policies with a PHP Array</strong></p>
<p>This is a WSF/PHP specific API to declare policies for a web service. You don&#8217;t need to learn WS-Security Policy to write policies with this approach. You can set whether you want to use encryption, signing or usernameToken in a PHP array and create a WSPolicy object using it.</p>
<pre class="php"><span style="font-style: italic; color: #808080;">// here is the security array to declare your policies in simple manner</span><span style="color: #0000ff;">
$sec_array</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"encrypt"</span> =&gt; <span style="font-weight: bold; color: #000000;">TRUE</span>,
 <span style="color: #ff0000;">"algorithmSuite"</span> =&gt; <span style="color: #ff0000;">"Basic256Rsa15"</span>,
 <span style="color: #ff0000;">"securityTokenReference"</span> =&gt; <span style="color: #ff0000;">"IssuerSerial"</span><span style="color: #66cc66;">)</span>;

<span style="font-style: italic; color: #808080;">// creating WSPolicy instance using the policy array</span><span style="color: #0000ff;">
$policy</span> = <span style="font-weight: bold; color: #000000;">new</span> WSPolicy<span style="color: #66cc66;">(</span><a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"security"</span>=&gt; <span style="color: #0000ff;">$sec_array</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;</pre>
<p>You can use this policy object to create a service along with a WSSecurityToken which contain the user parameters like the server private key and the client certificate.</p>
<pre class="php"><span style="color: #0000ff;">$sec_token</span> = <span style="font-weight: bold; color: #000000;">new</span> WSSecurityToken<span style="color: #66cc66;">(</span><a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span>
 <span style="color: #ff0000;">"privateKey"</span> =&gt; <span style="color: #0000ff;">$server_pvt_key</span>,
 <span style="color: #ff0000;">"receiverCertificate"</span> =&gt; <span style="color: #0000ff;">$client_pub_key</span><span style="color: #66cc66;">)</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;">"actions"</span> =&gt; <span style="color: #0000ff;">$actions</span>,
 <span style="color: #ff0000;">"operations"</span> =&gt; <span style="color: #0000ff;">$operations</span>,
 <span style="color: #ff0000;">"policy"</span> =&gt; <span style="color: #0000ff;">$policy</span>,
 <span style="color: #ff0000;">"securityToken"</span> =&gt; <span style="color: #0000ff;">$sec_token</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>; <span style="font-style: italic; color: #808080;">// here is the policy object you just created</span><span style="color: #0000ff;">

$svr</span>-&gt;<span style="color: #006600;">reply</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</pre>
<p>You can invoke this service just by writing a simple web service client. There also you need to provide the policies declared in the service, so the client can build his request to validate with server policies. You will be using a similar WSPolicy object to set these policies at the client side too, as show in the below code segment.</p>
<pre class="php"> <span style="color: #0000ff;">$sec_token</span> = <span style="font-weight: bold; color: #000000;">new</span> WSSecurityToken<span style="color: #66cc66;">(</span><a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span>
 <span style="color: #ff0000;">  "privateKey"</span> =&gt; <span style="color: #0000ff;">$pvt_key</span>,
 <span style="color: #ff0000;">  "receiverCertificate"</span> =&gt; <span style="color: #0000ff;">$rec_cert</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;

 <span style="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="font-style: italic; color: #808080;">/* the policy object */</span>
    <span style="color: #ff0000;">"securityToken"</span> =&gt; <span style="color: #0000ff;">$sec_token</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;

 <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>Declaring Policies with a Policy File</strong></p>
<p>You can set your policies in the server or client side using a policy file compliant with WS-Security Policy specification. You have to take this approach if your policy requirements are too complicated, like you want to sign only some parts of the message or you want to encrypt some soap headers.</p>
<p>Similar to the above method, here too you will use the WSPolicy object to set your policies. But unlike the above where you give the policies as a PHP array , here you can just give the policy file as an argument to the WSPolicy constructor.</p>
<pre class="php"><span style="font-style: italic; color: #808080;">// creating the WSPolicy instance from a policy file</span><span style="color: #0000ff;">
$policy_xml</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;">"policy.xml"</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><span style="color: #0000ff;">$policy_xml</span><span style="color: #66cc66;">)</span>;</pre>
<p><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2Fsecurity%2Fsigning%2Fpolicy_file_based%2Fpolicy.xml">Here </a>is an example of a complete policy file written according to the WS-Security Policy standards. And you can find a quick guide on WS-Security Policy from the article  <a href="http://wso2.org/library/3132">Understanding WS-Security Policy Language</a> written by <a href="http://nandana83.blogspot.com/">Nandana</a>, a key leader of Apache Rampart project.</p>
<p><strong>Declaring Policies inline in a WSDL</strong></p>
<p>We use WSDL to describe our web services. WSDL has the information about the service endpoint, the transport protocols (e.g. http), messaging protocols (e.g. SOAP) and the message schemas and many others about the service. You can attach your policies inside a WSDL.</p>
<p><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2FCalendar%2FCalendar.wsdl">Here</a> is an example of a WSDL with inline policies. The difference in this approach is you can set your policies separately for each messages or each operations or each endpoints of your service. The following segment of a WSDL shows how you refer to different policies which are declared in the early part of the WSDL.</p>
<pre class="xml">     <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;wsdl:binding</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"CalendarSOAP12Binding"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"ns1:CalendarPortType"</span><span style="font-weight: bold; color: black;">&gt;
</span></span>       <span style="color: #009900;"><span style="font-style: italic; color: #808080;">&lt;!-- Endpoint policies are declared here.
          these are common to all messages transferring
          through this protocols (i.e. SOAP12, http)--&gt;</span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;wsp:PolicyReference</span> <span style="color: #000066;">URI</span>=<span style="color: #ff0000;">"#transport_binding_policy"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">  &lt;soap12:binding</span> <span style="color: #000066;">transport</span>=<span style="color: #ff0000;">"http://schemas.xmlsoap.org/soap/http"</span> <span style="color: #000066;">style</span>=<span style="color: #ff0000;">"document"</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;">"login"</span><span style="font-weight: bold; color: black;">&gt;
          </span></span> <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;soap12:operation</span> <span style="color: #000066;">soapAction</span>=<span style="color: #ff0000;">"urn:login"</span> <span style="color: #000066;">style</span>=<span style="color: #ff0000;">"document"</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 style="font-weight: bold; color: black;">&gt;
             </span></span></span> <span style="color: #009900;"><span style="font-style: italic; color: #808080;">&lt;!-- policy specific to the 'login' operation --&gt;</span></span>
              <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;wsp:PolicyReference</span> <span style="color: #000066;">URI</span>=<span style="color: #ff0000;">"#username_token_policy"</span><span style="font-weight: bold; color: black;">/&gt;
             </span></span> <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;soap12:body</span> <span style="color: #000066;">use</span>=<span style="color: #ff0000;">"literal"</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 style="font-weight: bold; color: black;">&gt;</span></span></span>
           <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;wsdl:output<span style="font-weight: bold; color: black;">&gt;</span></span></span>
              <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;soap12:body</span> <span style="color: #000066;">use</span>=<span style="color: #ff0000;">"literal"</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 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 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;">"register"</span><span style="font-weight: bold; color: black;">&gt;
           </span></span> <span style="color: #009900;"><span style="font-style: italic; color: #808080;">&lt;!-- no specific policies are set for the 'register' operation</span></span><span style="color: #009900;"><span style="font-style: italic; color: #808080;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">
          </span></span> <span style="color: #009900;"><span style="font-weight: bold; color: black;"> &lt;soap12:operation</span> <span style="color: #000066;">soapAction</span>=<span style="color: #ff0000;">"urn:register"</span> <span style="color: #000066;">style</span>=<span style="color: #ff0000;">"document"</span><span style="font-weight: bold; color: black;">/&gt;
         </span></span> </span></span>  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;wsdl:input<span style="font-weight: bold; color: black;">&gt;</span></span></span>
              <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;soap12:body</span> <span style="color: #000066;">use</span>=<span style="color: #ff0000;">"literal"</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 style="font-weight: bold; color: black;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;wsdl:output<span style="font-weight: bold; color: black;">&gt;</span></span></span>
               <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;soap12:body</span> <span style="color: #000066;">use</span>=<span style="color: #ff0000;">"literal"</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 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 style="font-weight: bold; color: black;">&gt;</span></span></span>
           ....
       <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/wsdl:binding<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>This is the binding section of a WSDL where we bind messaging protocol and transport protocols with a service endpoint. Here we have &#8220;login&#8221; and &#8220;register&#8221; operations. Note that we are referring to &#8220;transport_binding_policy&#8221; from the parent level of each operation elements. That means these policies are common to all the operation in that binding. And inside the &#8220;login&#8221; operation we are referring to &#8220;username_token_policy&#8221;, so in order to invoke this operation, you have to send username token headers. And &#8220;register&#8221; doesn&#8217;t require any operation specific policies allowing users to register without any prior authentications.</p>
<p>You can select any of the above mentioned approach to define policies of your web service or to invoke a web service that support WS-Policy. If your policy requirements are simple, it will be easy to use the array based approach. If your policy requirements are complex or you have a good understanding of WS-Policy  and WS-Security Policy you can rely on the policy file based approach or defining policy inline with WSDL. And the former 2 methods will give you a nice separation of the logic code and security configurations. The selection is yours:)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/11/19/ws-securitypolicy-with-php/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>XML Schema Simple Types &amp; How WSDL2PHP Convert Them To PHP</title>
		<link>http://www.dimuthu.org/blog/2008/11/13/xml-schema-simple-types-how-wsdl2php-convert-them-to-php/</link>
		<comments>http://www.dimuthu.org/blog/2008/11/13/xml-schema-simple-types-how-wsdl2php-convert-them-to-php/#comments</comments>
		<pubDate>Thu, 13 Nov 2008 15:28:50 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[WSDL]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[xml schema]]></category>
		<category><![CDATA[built-in]]></category>
		<category><![CDATA[facets]]></category>
		<category><![CDATA[list]]></category>
		<category><![CDATA[primitive]]></category>
		<category><![CDATA[simple types]]></category>
		<category><![CDATA[union]]></category>
		<category><![CDATA[wsdl2php]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=598</guid>
		<description><![CDATA[As many of other languages, XML schema too have data types. Basically it can be categorized in to two groups. Simple Types Complex Types The different between these 2 types are so easy to identify. Say you have a schema element with a simple type like this. &#60;xs:element name="xx" type="someSimpleType"/&#62; Then a possible xml to [...]]]></description>
			<content:encoded><![CDATA[<p>As many of other languages, XML schema too have data types. Basically it can be categorized in to two groups.</p>
<ol>
<li>Simple Types</li>
<li>Complex Types</li>
</ol>
<p>The different between these 2 types are so easy to identify. Say you have a schema element with a simple type like this.</p>
<pre class="xml"><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;">"xx"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"someSimpleType"</span><span style="font-weight: bold; color: black;">/&gt;</span></span></pre>
<p>Then a possible xml to validate against this schema is</p>
<pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xx<span style="font-weight: bold; color: black;">&gt;</span></span></span>Bingo<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/x<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>Inside the &#8216;xxx&#8217; you can only find texts, But in a case of a  schema element with complex types,</p>
<pre class="xml"><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;">"xx"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"someComplexType"</span><span style="font-weight: bold; color: black;">/&gt;</span></span></pre>
<p>The XML will be set of nested elements.</p>
<pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xx<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;yy<span style="font-weight: bold; color: black;">&gt;</span></span></span>hi<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/yy<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;zz<span style="font-weight: bold; color: black;">&gt;</span></span></span>Nested elements<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/zz<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xx<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>Simply complex type contains elements with simple types or complex types similar to the class types in OOP languages which contain member variables with different types.</p>
<p>But unlike most of the other languages, in schema simple types are not always primitive types. There can be user derived simple types as well.</p>
<p>I will talk about each of these variations in schema types and their PHP representation of <a href="http://labs.wso2.org/wsf/php/wsdl2phptool.php">WSDL2PHP tool</a>.</p>
<ul>
<li>Primitive Types &amp; Built-in Types</li>
<li>List Types</li>
<li>Union Types</li>
<li>Faceted Types</li>
</ul>
<p><strong>Primitive Types &amp; Built-in Types<br />
</strong></p>
<p>The XML schema specification talks about <a href="http://www.w3.org/TR/xmlschema-2/#built-in-primitive-datatypes">19 primitive types</a>. Some of the common of these simple types and the corresponding PHP types generated by WSDL2PHP tool are,</p>
<table border="1">
<tbody>
<tr style="background:#dddddd">
<td>Schema Type</td>
<td>PHP Type</td>
</tr>
<tr>
<td><a href="http://www.w3.org/TR/xmlschema-2/#string">string</a></td>
<td>string</td>
</tr>
<tr>
<td><a href="http://www.w3.org/TR/xmlschema-2/#boolean">boolean</a></td>
<td>boolean</td>
</tr>
<tr>
<td><a href="http://www.w3.org/TR/xmlschema-2/#decimal">decimal</a></td>
<td>float</td>
</tr>
<tr>
<td><a href="http://www.w3.org/TR/xmlschema-2/#float">float</a></td>
<td>float</td>
</tr>
<tr>
<td><a href="http://www.w3.org/TR/xmlschema-2/#double">double</a></td>
<td>double</td>
</tr>
<tr>
<td><a href="http://www.w3.org/TR/xmlschema-2/#duration">duration</a></td>
<td>string</td>
</tr>
<tr>
<td><a href="http://www.w3.org/TR/xmlschema-2/#dateTime">dateTime</a></td>
<td>string (from above wsf/php 2.0 it is an integer &#8211; representing timestamp)</td>
</tr>
</tbody>
</table>
<p>You may have noticed the famous types like &#8216;integer&#8217;, &#8216;byte&#8217;, &#8216;short&#8217; are missing out of the above list. In fact these types exist, but they are not primitive types. They are derived from decimal (special cases when the fraction digits are 0 <img src='http://www.dimuthu.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . Anyway still these types are considered built-in types in xml schema. Here is the <a href="http://www.w3.org/TR/xmlschema-2/#built-in-primitive-datatypes">complete list of built-in types</a> (both primitive and non-primitive built-in types)</p>
<p>&#8216;integer&#8217;, &#8216;byte&#8217; and &#8216;short&#8217; are mapped to PHP integer types by the WSDL2PHP tool.</p>
<p>To show an example how WSDL2PHP tool generating code for simple types, I will take the following schema Element.</p>
<pre class="xml"><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;">"myName"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"xs:string"</span><span style="font-weight: bold; color: black;">/&gt;</span></span></pre>
<p>And WSDL2PHP will generate a simple public variable (Assuming this is generating inside some class) for that element with a comment to describing it.</p>
<pre class="php">    <span style="font-style: italic; color: #808080;">/**
     * @var string
     */</span>
     <span style="font-weight: bold; color: #000000;">public</span> <span style="color: #0000ff;">$myName</span>;</pre>
<p>So if I specified some value for the variable (Taking the variable name of the parent class is $parent),</p>
<pre class="php"><span style="color: #0000ff;">$parent</span>-&gt;<span style="color: #006600;">myName</span> = <span style="color: #ff0000;">"James"</span>;</pre>
<p>I will get the following nice XML.</p>
<pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;myName<span style="font-weight: bold; color: black;">&gt;</span></span></span>James<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/myName<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>This is the same approach for all the other built-in types as well.</p>
<p><strong>List Types</strong></p>
<p>The list types are derived from list of simple types. It still a simple type because it list all the element in the list as a white-space separated text inside the parent element.</p>
<p>Here is how you may declare a list type in an xml schema.</p>
<pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:simpleType</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"mylist"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:list</span> <span style="color: #000066;">itemType</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:simpleType<span style="font-weight: bold; color: black;">&gt;</span></span></span>

<span style="color: #009900;"><span style="font-style: italic; color: #808080;">&lt;!-- example element to have the above list value --&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;">"xCoordinates"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"tns:mylist"</span><span style="font-weight: bold; color: black;">/&gt;</span></span></pre>
<p>Then the WSDL2PHP generated PHP code would be something like,</p>
<pre class="php">    <span style="font-style: italic; color: #808080;">/**
     * @var array of int
     */</span>
    <span style="font-weight: bold; color: #000000;">public</span> <span style="color: #0000ff;">$xCoordinates</span>;</pre>
<p>As the comment implies, you have to feed the values in an php array.</p>
<pre class="xml"><span style="color: #0000ff;">$parent</span>-&gt;<span style="color: #006600;">xCoordinates</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">3</span>, <span style="color: #cc66cc;">8</span>, <span style="color: #cc66cc;">7</span>, <span style="color: #cc66cc;">9</span><span style="color: #66cc66;">)</span>;</pre>
<p>And Here is the XML you are getting,</p>
<pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xCoordinates<span style="font-weight: bold; color: black;">&gt;</span></span></span>1 3 8 7 9<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xCoordinates<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>Similarly you can have list of any simple types regardless whether it is built-in or derived.</p>
<p><strong>Union Types</strong></p>
<p>The union in schema is similar to the unions in &#8216;C&#8217;. In C variables of a union can have one (and not more than one) of the types declared inside the union type. Similarly in schema elements with union types can have one and only one simple type among the member types declared in the union. Here is an example of declaring union type,</p>
<pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:simpleType</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"myIntStringUnion"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:union</span> <span style="color: #000066;">memberTypes</span>=<span style="color: #ff0000;">"xs:int 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:simpleType<span style="font-weight: bold; color: black;">&gt;</span></span></span>

<span style="color: #009900;"><span style="font-style: italic; color: #808080;">&lt;!-- example element to have the above union value --&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;">"garbage"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"tns:myIntStringUnion"</span><span style="font-weight: bold; color: black;">/&gt;</span></span></pre>
<p>And the WSDl2PHP generated code,</p>
<pre class="php">    <span style="font-style: italic; color: #808080;">/**
     * @var int/string
     */</span>
    <span style="font-weight: bold; color: #000000;">public</span> <span style="color: #0000ff;">$garbage</span>;</pre>
<p>So if you read the comment you can have an idea that this variable accept either &#8216;in&#8217; or &#8216;string&#8217; type without digging in to the WSDL.</p>
<p><strong>Faceted Types</strong></p>
<p>You can apply facets and restrict the value space of a simple type.</p>
<ul>
<li>length</li>
<li>minLength</li>
<li>maxLength</li>
<li>pattern</li>
<li>enumeration</li>
<li>whiteSpace</li>
<li>maxInclusive</li>
<li>maxExclusive</li>
<li>minExclusive</li>
<li>minInclusive</li>
<li>totalDigits</li>
<li>fractionDigits</li>
</ul>
<p>Some facets are specific to some built-in data types or types derived from these built-in datatypes. <a href="http://www.w3.org/TR/xmlschema-2/#built-in-primitive-datatypes">Here is a table of valid facets</a> for each of the above mentioned catagory of types.</p>
<p>I have earlier blogged about how you work on faceted types in PHP in the post &#8220;<a href="http://www.dimuthu.org/blog/2008/10/21/coding-schema-inheritance-in-php/">Coding Schema Inheritance in PHP</a>&#8220;. So Here I will list out a similar example  to demonstrate the PHP generated code by WSDL2PHP tool for facets.</p>
<p>Here is a schema with the &#8216;enumeration&#8217; facet.</p>
<pre class="xml"><span style="color: #009900;"><span style="font-style: italic; color: #808080;">&lt;!-- applying enumeration facet to the xs:string --&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:simpleType</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"mySubject"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:restriction</span> <span style="color: #000066;">base</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:enumeration</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"Maths"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
         <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:enumeration</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"Physics"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
         <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:enumeration</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"Chemistry"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xs:restriction<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xs:simpleType<span style="font-weight: bold; color: black;">&gt;</span></span></span>

<span style="color: #009900;"><span style="font-style: italic; color: #808080;">&lt;!-- example element to have the above faceted value --&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;">"subject"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"tns:mySubject"</span><span style="font-weight: bold; color: black;">/&gt;</span></span></pre>
<p>And here is the WSDL2PHP generated code,</p>
<pre class="php">    <span style="font-style: italic; color: #808080;">/**
     * @var string
     *     NOTE: subject should follow the following restrictions
     *     You can have one of the following value
     *     Maths
     *     Physics
     *     Chemistry
     */</span>
    <span style="font-weight: bold; color: #000000;">public</span> <span style="color: #0000ff;">$subject</span>;</pre>
<p>It clearly says your variable &#8216;subject&#8217; is only allowed to have the list of values mentioned in the &#8216;enumeration&#8217;.</p>
<p>So I just wrote about some variations of simple schema types and how they are represented in the WSDL2PHP generated code. As you may have observed, you don&#8217;t need to know any thing about the WSDL or the schema to write a PHP code around that, since WSDL2PHP gives you a generated code mentioning all the guidelines, restrictions about using them.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/11/13/xml-schema-simple-types-how-wsdl2php-convert-them-to-php/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>WSF/PHP Test Cases Explained</title>
		<link>http://www.dimuthu.org/blog/2008/11/11/wsfphp-test-cases-explained/</link>
		<comments>http://www.dimuthu.org/blog/2008/11/11/wsfphp-test-cases-explained/#comments</comments>
		<pubDate>Tue, 11 Nov 2008 19:27:10 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[php]]></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[basic]]></category>
		<category><![CDATA[mtom]]></category>
		<category><![CDATA[phpt]]></category>
		<category><![CDATA[reliable messaging]]></category>
		<category><![CDATA[rm]]></category>
		<category><![CDATA[schema]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[test-suit]]></category>
		<category><![CDATA[tests]]></category>
		<category><![CDATA[wsdl generation]]></category>
		<category><![CDATA[wsdl mode]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=594</guid>
		<description><![CDATA[WSO2 WSF/PHP comes with a comprehensive set of test cases. It covers the most of the basic/concrete scenarios supported by WSF/PHP. You can find these test cases inside the &#8220;src/tests&#8221; directory of WSF/PHP source package. Or you can find the latest test-suite from the SVN location. Here are some aspects covered in the test-suit. Scenario [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://wso2.org/projects/wsf/php">WSO2 WSF/PHP</a> comes with a comprehensive set of test cases. It covers the most of the basic/concrete scenarios supported by WSF/PHP. You can find these test cases inside the &#8220;src/tests&#8221; directory of WSF/PHP source package. Or you can find the latest test-suite from <a href="https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/">the SVN location</a>.</p>
<p>Here are some aspects covered in the test-suit.</p>
<table border="1">
<tbody>
<tr style="background:#dddddd">
<td>Scenario</td>
<td>Test Cases For Client</td>
<td>Test Cases For Service</td>
</tr>
<tr>
<td>Basic Functionality</td>
<td><a href="https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/">echo_client*.phpt</a><a href="https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/">math_*.phpt</a></td>
<td><a href="https://wso2.org/repos/wso2/trunk/wsf/php/samples/">samples/echo_service*.php</a><br />
<a href="https://wso2.org/repos/wso2/trunk/wsf/php/samples/">samples/math_service.php</a></td>
</tr>
<tr>
<td>Basic Schema Types</td>
<td><a href="https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/BasicDataTypes/">BasicDataTypes/*.phpt</a></td>
<td><a href="https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/services/BasicTypesDoclitBSvc/">services/BasicTypesDoclitBSvc/*.php</a></td>
</tr>
<tr>
<td>Complex Schema Types</td>
<td><a href="https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/cmplxDataTypes/">cmplxDataTypes/*.phpt</a></td>
<td><a href="https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/services/ComplexDataTypesWSvc/">services/ComplexDataTypesWSvc/*.php</a><br />
<a href="https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/services/ComplexDataTypesBSvc/">services/ComplexDataTypesBSvc/*.php</a></td>
</tr>
<tr>
<td>WSDL/Schema Variations</td>
<td><a href="https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/wsdl_mode/">wsdl_mode/*.phpt</a></td>
<td><a href="https://wso2.org/repos/wso2/trunhttps://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/services/wsdl_mode/">services/wsdl_mode/*.php</a></td>
</tr>
<tr>
<td>WSDL Generation with Annotations</td>
<td><a href="https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/wsdl_generation/">wsdl_generation/*.phpt</a></td>
<td><a href="https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/services/wsdl_generation/">services/wsdl_generation/*.php</a></td>
</tr>
<tr>
<td>Reliable Messaging</td>
<td><a href="https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/">echo_rm*.phpt</a></td>
<td><a href="https://wso2.org/repos/wso2/trunk/wsf/php/samples/">samples/echo_service_rm*.php</a></td>
</tr>
<tr>
<td>Security</td>
<td><a href="https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/">echo_encrypt_client*.phpt</a><a href="https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/">echo_signing_client*.phpt</a></p>
<p><a href="https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/">echo_timestamp_client*.phpt</a></p>
<p><a href="https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/">echo_username_token_client*.phpt</a></td>
<td><a href="https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/services/">encrypt_service*.php</a><a href="https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/services/">signing_service*.php</a></p>
<p><a href="https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/services/">timestamp_service*.php</a></p>
<p><a href="https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/services/">username_token_service*.php</a></td>
</tr>
<tr>
<td>MTOM</td>
<td><a href="https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/">mtom_*.phpt</a></td>
<td><a href="https://wso2.org/repos/wso2/trunk/wsf/php/samples/mtom/">samples/mtom/*.php</a></td>
</tr>
</tbody>
</table>
<p>(Note that Here &#8216;*&#8217; is used as a wild card represent 0 or many characters)</p>
<p><strong>Steps to Run Tests</strong></p>
<ul>
<li>First you need to install WSF/PHP correctly. Please read the <a href="http://wso2.org/project/wsf/php/2.0.0/docs/manual_content.html#Installation">WSF/PHP installation manual</a> for that.</li>
<li>You have to have the &#8216;pear&#8217; utility tool comes with PHP. And add this to the PATH environment variable.</li>
<li>Copy the samples and src/tests/samples/services directory (paths are relative to the root directory of the wsf/php package) to the web root directory.</li>
<li>Then go to the src/tests directory and execute the following command.
<pre>pear run-tests -r</pre>
<p>This will execute all the test cases under the &#8216;tests&#8217; directory and finally give a summery of the test results.</li>
<li> You can run individual test cases separately by providing the relative path to the test case from the &#8216;test&#8217; directory. E.g. To run the echo_client.phpt test case, you may type
<pre>pear run-tests samples/echo_client.phpt</pre>
</li>
</ul>
<p>If you like to add test cases for the WSF/PHP scenarios, follow this comprehensive guideline titled <a href="http://wso2.org/library/3579">Writing Simple phpt Test Scripts For PHP Web Services</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/11/11/wsfphp-test-cases-explained/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sending Custom SOAP Headers in PHP Web Services</title>
		<link>http://www.dimuthu.org/blog/2008/11/03/sending-custom-soap-headers-in-php-web-services/</link>
		<comments>http://www.dimuthu.org/blog/2008/11/03/sending-custom-soap-headers-in-php-web-services/#comments</comments>
		<pubDate>Mon, 03 Nov 2008 17:24:12 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[php]]></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[custom headers]]></category>
		<category><![CDATA[Sending]]></category>
		<category><![CDATA[SOAP headers]]></category>
		<category><![CDATA[WSHeader]]></category>
		<category><![CDATA[WSMessage]]></category>

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

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

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

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

<span style="font-style: italic; color: #808080;">// create the WSClient with the endpoint</span>
<span style="color: #0000ff;">$client</span> = <span style="font-weight: bold; color: #000000;">new</span> WSClient<span style="color: #66cc66;">(</span><a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span> <span style="color: #ff0000;">"to"</span> =&gt; <span style="color: #ff0000;">"http://localhost/header_echo_service.php"</span> <span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;

<span style="font-style: italic; color: #808080;">// do the request with the WSMessage instance as the request argument</span>
<span style="color: #0000ff;">$responseMessage</span> = <span style="color: #0000ff;">$client</span>-&gt;<span style="color: #006600;">request</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$request_msg</span><span style="color: #66cc66;">)</span>;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

		<guid isPermaLink="false">http://www.dimuthu.org/?p=543</guid>
		<description><![CDATA[In XML Schema we declare an array or a multiple occurrence of a schema element by setting its maxOccurs attribute to a value greater than 1 or to the value &#8220;unbounded&#8221; in a case of no maximum boundary. &#60;xs:element maxOccurs="unbounded"  minOccurs="0"  name="params"  nillable="true"  type="xs:int"/&#62; If you generate PHP code to such a schema using wsdl2php [...]]]></description>
			<content:encoded><![CDATA[<p>In XML Schema we declare an array or a multiple occurrence of a schema element by setting its maxOccurs attribute to a value greater than 1 or to the value &#8220;unbounded&#8221; in a case of no maximum boundary.</p>
<pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:element</span> <span style="color: #000066;">maxOccurs</span>=<span style="color: #ff0000;">"unbounded"
           </span> <span style="color: #000066;">minOccurs</span>=<span style="color: #ff0000;">"0"</span>
            <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"params"</span>
            <span style="color: #000066;">nillable</span>=<span style="color: #ff0000;">"true"</span>
            <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"xs:int"</span><span style="font-weight: bold; color: black;">/&gt;</span></span></pre>
<p>If you generate PHP code to such a schema using <a title="online wsdl2php tool" href="http://labs.wso2.org/wsf/php/wsdl2phptool.php">wsdl2php tool</a>, you will get a code for the class variable named &#8220;params&#8221; similar to this.</p>
<pre class="php">    <span style="font-style: italic; color: #808080;">/**
     * @var array[0, unbounded] of int
     */</span>
    <span style="font-weight: bold; color: #000000;">public</span> <span style="color: #0000ff;">$params</span>;</pre>
<p>So if you have a variable (say $object) for the object of this class you can fill the &#8220;params&#8221; field like this,</p>
<pre class="php"><span style="color: #0000ff;">$object</span>-&gt;<span style="color: #006600;">params</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">5</span>, <span style="color: #cc66cc;">8</span><span style="color: #66cc66;">)</span>;</pre>
<p>This will create the xml with the expected array of elements.</p>
<pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;wrapper<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;params<span style="font-weight: bold; color: black;">&gt;</span></span></span>1<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/params<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;params<span style="font-weight: bold; color: black;">&gt;</span></span></span>5<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/params<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;params<span style="font-weight: bold; color: black;">&gt;</span></span></span>8<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/params<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/wrapper<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>Not only for simple types, you can have arrays of complex types too.</p>
<pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:element</span> <span style="color: #000066;">maxOccurs</span>=<span style="color: #ff0000;">"unbounded"</span>
            <span style="color: #000066;">minOccurs</span>=<span style="color: #ff0000;">"0"</span>
            <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"params"</span>
            <span style="color: #000066;">nillable</span>=<span style="color: #ff0000;">"true"</span>
            <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"tns:MyComplexType"</span><span style="font-weight: bold; color: black;">/&gt;
</span></span></pre>
<p>Instead of giving simple integers like earlier case, this time you will feed the &#8220;params&#8221; variable with an array of PHP objects of &#8216;MyComplexType&#8217; class.</p>
<pre class="php"><span style="color: #0000ff;">$obj1</span> = <span style="font-weight: bold; color: #000000;">new</span> MyComplexType<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;
<span style="font-style: italic; color: #808080;">/* feeding data to obj1 variables */</span>

<span style="color: #0000ff;">$obj2</span> = <span style="font-weight: bold; color: #000000;">new</span> MyComplexType<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;
<span style="font-style: italic; color: #808080;">/* feeding data to obj2 variables */</span>

<span style="color: #0000ff;">$obj3</span> = <span style="font-weight: bold; color: #000000;">new</span> MyComplexType<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;
<span style="font-style: italic; color: #808080;">/* feeding data to obj3 variables */</span>

<span style="color: #0000ff;">$object</span>-&gt;<span style="color: #006600;">params</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$obj1</span>, <span style="color: #0000ff;">$obj2</span>, <span style="color: #0000ff;">$obj3</span><span style="color: #66cc66;">)</span>;</pre>
<p>This will create a xml containing array of params similar to this,</p>
<pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;wrapper<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;params<span style="font-weight: bold; color: black;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;elementx</span><span style="font-weight: bold; color: black;">/&gt;</span></span> <span style="color: #009900;"><span style="font-style: italic; color: #808080;">&lt;!-- elements in the MyComplexType type --&gt;</span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;elementy</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/params<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;params<span style="font-weight: bold; color: black;">&gt;</span></span></span>
        ... <span style="color: #009900;"><span style="font-style: italic; color: #808080;">&lt;!-- elements in the MyComplexType type --&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/params<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;params<span style="font-weight: bold; color: black;">&gt;</span></span></span>
        ... <span style="color: #009900;"><span style="font-style: italic; color: #808080;">&lt;!-- elements in the MyComplexType type --&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/params<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/wrapper<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/10/25/wsfphp-wsdl-mode-handling-xml-schema-arrays/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WSDL Generation From PHP &#8211; Using Different Names in WSDL and PHP Code</title>
		<link>http://www.dimuthu.org/blog/2008/10/23/wsdl-generation-from-php-using-different-names-in-wsdl-and-php-code/</link>
		<comments>http://www.dimuthu.org/blog/2008/10/23/wsdl-generation-from-php-using-different-names-in-wsdl-and-php-code/#comments</comments>
		<pubDate>Thu, 23 Oct 2008 14:01:24 +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]]></category>
		<category><![CDATA[xml schema]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[classmap]]></category>
		<category><![CDATA[different]]></category>
		<category><![CDATA[names]]></category>
		<category><![CDATA[operation]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php2wsdl]]></category>
		<category><![CDATA[schema]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=535</guid>
		<description><![CDATA[PHP2WSDL feature of the WSF/PHP allows you to generate the WSDL for your service when you access the URL formed by adding &#8220;?wsdl&#8221; to the service URL ( or you can use service URL + &#8220;?wsdl2&#8243; to access the wsdl version 2.0). It will generate the schema types for the wsdl from the classes you [...]]]></description>
			<content:encoded><![CDATA[<p>PHP2WSDL feature of the <a href="http://wso2.org/projects/wsf/php">WSF/PHP</a> allows you to generate the WSDL for your service when you access the URL formed by adding &#8220;?wsdl&#8221; to the service URL ( or you can use service URL + &#8220;?wsdl2&#8243; to access the wsdl version 2.0). It will generate the schema types for the wsdl from the classes you use to build the request message + the annotations you provided describing the types of the variables.</p>
<p>Sometime you may need to generate schema types with different names to the corresponding PHP classes. May be you need to have a &#8216;-&#8217; in the schema type which is not valid in PHP class syntax or you like to have a different naming convention for PHP and wsdl.  Similarly you may need to have the operation names different in the WSDL and the PHP code.</p>
<p>Here is how you do it with WSF/PHP.</p>
<p><strong>Different Names for Operations<br />
</strong></p>
<pre class="php"><span style="font-style: italic; color: #808080;">/**
 * Service logic for the echo operation
 * @namespace http://ws.dimuthu.org/php/myecho/operations
 * @param object testObject $param
 * @return object testObject $return
 */</span>
<span style="font-weight: bold; color: #000000;">function</span> echoMe<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$param</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>
  <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$param</span>;
<span style="color: #66cc66;">}</span>

<span style="font-style: italic; color: #808080;">/* The Service operation name to PHP function name map */</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;">"echo"</span> =&gt; <span style="color: #ff0000;">"echoMe"</span><span style="color: #66cc66;">)</span>;</pre>
<p>There I want my actual operation name to be echo. But I can&#8217;t declare a function name echo since PHP already has a library function echo (Yea, the one you regularly use to echo output). So I don&#8217;t have option other than declaring a function with different name (here it is &#8220;echoMe&#8221;) and mapped it in to echo operation in the operation map. We are going to feed this $operation variable at the WSService creation as its constructor argument.</p>
<p>Lets see how different names are used in schema types and corresponding php class names.</p>
<p><strong>Different names for Types and Classes<br />
</strong></p>
<pre class="php"><span style="font-style: italic; color: #808080;">/**
 * @namespace http://ws.dimuthu.org/php/myecho/types
 */</span>
<span style="font-weight: bold; color: #000000;">class</span> testObject <span style="color: #66cc66;">{</span>

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

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

<span style="font-style: italic; color: #808080;">/* The mapping of schema types to PHP class */</span>
<span style="color: #0000ff;">$classmap</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"test-object"</span> =&gt; <span style="color: #ff0000;">"testObject"</span><span style="color: #66cc66;">)</span>;</pre>
<p>It is similar how we mapped operation in the previous section. Just use $classmap variable which map the schema type name to the php class name.</p>
<p>Here is the type section and the interface section of the WSDL 2.0 generated using above codes. Observe the operation names and the types names are formed the way we expected.</p>
<pre class="xml">  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;types<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> xmlns:ns0=<span style="color: #ff0000;">"http://ws.dimuthu.org/php/myecho/types"</span>
        xmlns:ns1=<span style="color: #ff0000;">"http://ws.dimuthu.org/php/myecho/types"</span>
        <span style="color: #000066;">elementFormDefault</span>=<span style="color: #ff0000;">"qualified"</span>
        <span style="color: #000066;">targetNamespace</span>=<span style="color: #ff0000;">"http://ws.dimuthu.org/php/myecho/operations/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:import</span> <span style="color: #000066;">namespace</span>=<span style="color: #ff0000;">"http://ws.dimuthu.org/php/myecho/types"</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;">"param"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"ns0:test-object"</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;">"return"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"ns1:test-object"</span><span style="font-weight: bold; color: black;">/&gt;</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>
    <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><span><span style="color: #009900;">
               </span></span><span style="color: #009900;"> <span style="color: #000066;">targetNamespace</span>=<span style="color: #ff0000;">"http://ws.dimuthu.org/php/myecho/types"</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> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"test-object"</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:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"aint"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"xsd:integer"</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;">"astring"</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:schema<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/types<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;interface</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"myEchoPortType"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;operation</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"echo"</span> <span style="color: #000066;">pattern</span>=<span style="color: #ff0000;">"http://www.w3.org/ns/wsdl/in-out"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;input</span> <span style="color: #000066;">element</span>=<span style="color: #ff0000;">"tnx:param"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;output</span> <span style="color: #000066;">element</span>=<span style="color: #ff0000;">"tnx:return"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/operation<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/interface<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>Here is the complete code (Combining all the previously mentioned code segments). You can check the complete wsdl generation (wsdl  1.1 or wsdl 2.0 as your preference) by copying and pasting this code to the <a href="http://labs.wso2.org/wsf/php/php2wsdltool.php">online php2wsdl generator</a> at the <a href="http://labs.wso2.org/wsf/php">WSF/PHP Demo Site</a>.</p>
<pre class="php"><span style="font-weight: bold; color: #000000;">&lt;?php</span>

<span style="font-style: italic; color: #808080;">/**
 * Service logic for the echo operation
 * @namespace http://ws.dimuthu.org/php/myecho/operations
 * @param object testObject $param
 * @return object testObject $return
 */</span>
<span style="font-weight: bold; color: #000000;">function</span> echoMe<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$param</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>
  <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$param</span>;
<span style="color: #66cc66;">}</span>

<span style="font-style: italic; color: #808080;">/**
 * @namespace http://ws.dimuthu.org/php/myecho/types
 */</span>
<span style="font-weight: bold; color: #000000;">class</span> testObject <span style="color: #66cc66;">{</span>

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

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

<span style="font-style: italic; color: #808080;">/* The Service operation name to PHP function name map */</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;">"echo"</span> =&gt; <span style="color: #ff0000;">"echoMe"</span><span style="color: #66cc66;">)</span>;

<span style="font-style: italic; color: #808080;">/* Telling that we input MIX types for the parameters */</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;">"echo"</span> =&gt; <span style="color: #ff0000;">"MIXED"</span><span style="color: #66cc66;">)</span>;

<span style="font-style: italic; color: #808080;">/* The mapping of schema types to PHP class */</span>
<span style="color: #0000ff;">$classmap</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"test-object"</span> =&gt; <span style="color: #ff0000;">"testObject"</span><span style="color: #66cc66;">)</span>;

<span style="font-style: italic; color: #808080;">/* Creating the WSService and serving the Request */</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;">"classmap"</span> =&gt; <span style="color: #0000ff;">$classmap</span>,
			<span style="color: #ff0000;">"opParams"</span> =&gt; <span style="color: #0000ff;">$opParams</span>,
			<span style="color: #ff0000;">"serviceName"</span> =&gt; <span style="color: #ff0000;">"myEcho"</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>;

<span style="font-weight: bold; color: #000000;">?&gt;</span></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/10/23/wsdl-generation-from-php-using-different-names-in-wsdl-and-php-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Coding Schema Inheritance in PHP</title>
		<link>http://www.dimuthu.org/blog/2008/10/21/coding-schema-inheritance-in-php/</link>
		<comments>http://www.dimuthu.org/blog/2008/10/21/coding-schema-inheritance-in-php/#comments</comments>
		<pubDate>Tue, 21 Oct 2008 13:07:08 +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]]></category>
		<category><![CDATA[xml schema]]></category>
		<category><![CDATA[complexContent]]></category>
		<category><![CDATA[complexType]]></category>
		<category><![CDATA[extension]]></category>
		<category><![CDATA[inheritance]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[restriction]]></category>
		<category><![CDATA[schema]]></category>
		<category><![CDATA[simpleContent]]></category>
		<category><![CDATA[simpleType]]></category>
		<category><![CDATA[wsdl2php]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=517</guid>
		<description><![CDATA[If you are thinking of writing a web service or a client based on a WSDL, you can easily generate the code for PHP or any other language using tools likes wsdl2php or other wsdl2xxx category tools. Then you don&#8217;t need to really worry about what is the schema of the WSDL or any other [...]]]></description>
			<content:encoded><![CDATA[<p>If you are thinking of writing a web service or a client based on a WSDL, you can easily generate the code for PHP or any other language using tools likes wsdl2php or other wsdl2xxx category tools. Then you don&#8217;t need to really worry about what is the schema of the WSDL or any other finer details. But sometime it may useful to know how different schema constructs are generated in PHP level so you can have a good idea when you are using them. This post describes How inheritance is used in XML Schema and how it is mapped to PHP code from <a href="http://labs.wso2.org/wsf/php/wsdl2phptool.php">wsdl2php tool</a> in <a href="http://wso2.org/projects/wsf/php">WSF/PHP</a>.</p>
<p>There are several ways that one schema type can inherit another type.  Here are some names use to refer them.</p>
<ul>
<li>SimpleType Restriction &#8211; Forming simple type by restricting another simple type</li>
<li>SimpleContent Extension &#8211; Forming complex type by extending a simple type</li>
<li>ComplexContent Extension &#8211; Forming complex type by extending another complex type</li>
</ul>
<p>Note that here the word &#8216;type&#8217; always refers to a schema type.</p>
<p>It is not straight forward to do a one to one map from these schema structures to a PHP or some other language. But wsdl2php tool does that keeping the simplicity and preserving the original meaning. Lets see how it is done for each of the above mentioned methods of inheriting.</p>
<p><strong>SimpleType Restriction</strong></p>
<p>You can create a simple type by restricting some values of another simple type. Here is an example.</p>
<pre class="xml">            <span style="color: #009900;"><span style="font-style: italic; color: #808080;">&lt;!-- derivedType from applying
              simple type restriction for xs:string --&gt;</span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:simpleType</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"derivedType"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
                <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:restriction</span> <span style="color: #000066;">base</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:enumeration</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"a"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
                    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:enumeration</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"ab"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
                    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:enumeration</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"abc"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
                    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:enumeration</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"abcd"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
                <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xs:restriction<span style="font-weight: bold; color: black;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xs:simpleType<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>Here the derivedType is a string, but it can only have values &#8220;a&#8221;, &#8220;ab&#8221;, &#8220;abc&#8221; and &#8220;abcd&#8221;. This restriction have used the &#8220;enumeration&#8221; (which we call a facet) to restrict the possible values. You can use other facets like length, minLength, MaxLength and so on. Here are the <a href="http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/datatypes.html#rf-facets">complete list of facets in the schema specification</a>.</p>
<p>So lets see hows this is mapped to a PHP code. Here we assume this type is used in an schema element called &#8216;input&#8217;.</p>
<pre class="php">    <span style="font-style: italic; color: #808080;">/**
     * @var string
     *     NOTE: $input should follow the following restrictions
     *     You can have one of the following value
     *     a
     *     ab
     *     abc
     *     abcd
     */</span>
     <span style="font-weight: bold; color: #000000;">public</span> <span style="color: #0000ff;">$input</span>;</pre>
<p>Note that here it does not say anything about the &#8216;derivedType&#8217;. Rather it says it is of type &#8220;String&#8221; which is a PHP type and in addition it has some restrictions, or rules when assigning values.</p>
<p>Although it could have been possible to use getters and setters to impose these rules, this uses just a comment about the rules because this way it is really easy the use the variable.</p>
<p>Say we have another type (say derievedType2) restricting the &#8216;derievedType&#8217;, that type will have the combination of restrictions of both types.</p>
<p>Here is the xml schema representation of the &#8216;derievedType2&#8242;.</p>
<pre class="xml">            <span style="color: #009900;"><span style="font-style: italic; color: #808080;">&lt;!-- derivedType2--&gt;</span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:simpleType</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"derivedType2"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
                <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:restriction</span> <span style="color: #000066;">base</span>=<span style="color: #ff0000;">"tns:derivedType"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
                    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:maxLength</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"3"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
                    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:minLength</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"2"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
                <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xs:restriction<span style="font-weight: bold; color: black;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xs:simpleType<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>And if input2 have that type, the php code will look like this, (Note that it has the combination of rules).</p>
<pre class="php">    <span style="font-style: italic; color: #808080;">/**
     * @var string
     *     NOTE: $input2 should follow the following restrictions
     *     You can have one of the following value
     *     a
     *     ab
     *     abc
     *     abcd
<strong>     *     Your length of the value should be
     *     Greater than 2
     *     Less than 3</strong>
     */</span>
     <span style="font-weight: bold; color: #000000;">public</span> <span style="color: #0000ff;">$input2</span>;</pre>
<p>I have highlighted the additional rules compared with $input, so you can see the difference.</p>
<p><strong>SimpleContent Extension</strong></p>
<p>Simple Content extension is extending a simple type to make a complex type. Say we have an element (say with the name &#8220;mystring&#8221;) and it has &#8220;xs:string&#8221; simple type.</p>
<pre class="xml"><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;">"mystring"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"xs:string"</span><span style="font-weight: bold; color: black;">/&gt;</span></span></pre>
<p>And here is a valid xml with this schema.</p>
<pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;mystring<span style="font-weight: bold; color: black;">&gt;</span></span></span>this can contain only string<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/mystring<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>So if I say I&#8217;m going to make a complex type extending this simple type you may think that I&#8217;m going to add element in to that. In fact I will create a complex type by adding an attribute.</p>
<pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;mystring</span> <span style="color: #000066;">myint</span>=<span style="color: #ff0000;">"3"</span><span style="font-weight: bold; color: black;">&gt;</span></span>this can contain only string<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/mystring<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>The schema to this xml will be something like this. (Note that I have assumed there is an schema element named &#8220;mystring&#8221; with the type &#8220;myStringType&#8221;)</p>
<pre class="xml">            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:complexType</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"myStringType"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
                <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:simpleContent<span style="font-weight: bold; color: black;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:extension</span> <span style="color: #000066;">base</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:attribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"myint"</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:extension<span style="font-weight: bold; color: black;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xs:simpleContent<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></pre>
<p>The PHP generated code for this schema is something like this,</p>
<pre class="php"><span style="font-weight: bold; color: #000000;">class</span> myStringType <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;">$myint</span>;

    <span style="font-style: italic; color: #808080;">// The "value" represents the element 'myStringType' value..</span>

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

<span style="color: #66cc66;">}</span></pre>
<p>So as you can see it creates a PHP class for that schema type with member variables for each attributes and finally for the value of the parent type. So in order to represent the above mentioned xml, you will use the following PHP code.</p>
<pre class="php"><span style="color: #0000ff;">$type</span> = <span style="font-weight: bold; color: #000000;">new</span> myStringType<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;

<span style="color: #0000ff;">$type</span>-&gt;<span style="color: #006600;">myint</span> = <span style="color: #cc66cc;">3</span>;
<span style="color: #0000ff;">$type</span>-&gt;<span style="color: #006600;">value</span> = <span style="color: #ff0000;">"this can contain only string"</span>;</pre>
<p>Next we will look at the inheritance with complexContent Extension.</p>
<p><strong>ComplexContent Extension</strong></p>
<p>This is to create a complex type by inheriting another complexType.</p>
<pre class="xml">            <span style="color: #009900;"><span style="font-style: italic; color: #808080;">&lt;!-- the parent type --&gt;</span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:complexType</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"parentType"</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:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"demo3"</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;">"demo4"</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-style: italic; color: #808080;">&lt;!-- the child type --&gt;</span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:complexType</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"childType"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
                <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:complexContent<span style="font-weight: bold; color: black;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:extension</span> <span style="color: #000066;">base</span>=<span style="color: #ff0000;">"tns:parentType"</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: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:extension<span style="font-weight: bold; color: black;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xs:complexContent<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></pre>
<p>So here the childType will inherit the &#8216;demo3&#8242; and &#8216;demo4&#8242; elements from the parent type. We will see how is the PHP generated code looks like.</p>
<pre class="php"><span style="font-weight: bold; color: #000000;">class</span> parentType <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;">$demo3</span>;

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

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

<span style="font-weight: bold; color: #000000;">class</span> childType <span style="font-weight: bold; color: #000000;">extends</span> parentType <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;">$demo1</span>;

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

<span style="color: #66cc66;">}</span></pre>
<p>It has uses the PHP inheritance to reprensent the schema inheritance. And the nice thing is you can use the childType for the places you have to use the parentType.  That is the theoy we learn at the inheritance class of other languages (Java, C++) too.</p>
<p>So say there is another complexType (say &#8220;anotherChildType&#8221;) inheriting from the type &#8220;parentType&#8221; and one another complexType (say &#8220;nextLevelChildType&#8221;) inheriting this time from &#8220;childType&#8221; (which in fact inheriting from the &#8220;parentType&#8221; as mentioned above).</p>
<p>So our types tree would be something like this.</p>
<pre>--- parentType
         |
         +-------- childType
         |              |
         |              +------------- nexLevelChildType
         |
         +-------- anotherChildType</pre>
<p>And lets say there is a schema element called &#8216;input3&#8242; with the type parentType. Then the generated variable for the input3 element will be like following code segment.</p>
<pre class="php">    <span style="font-style: italic; color: #808080;">/**
     * @var (object)parentType
     *    Or one of following derived class(es)
     *       childType
     *       nextLevelChildType
     *       anotherChildType
     */</span>
    <span style="font-weight: bold; color: #000000;">public</span> <span style="color: #0000ff;">$input3</span>;</pre>
<p>This comment tells you that you can actually use the inherited types in place of the parent type according to your preferences.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/10/21/coding-schema-inheritance-in-php/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

