<?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; WSDL</title>
	<atom:link href="http://www.dimuthu.org/tag/wsdl/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>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>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>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>WSF/PHP Samples Explained</title>
		<link>http://www.dimuthu.org/blog/2008/11/07/wsfphp-samples-explained/</link>
		<comments>http://www.dimuthu.org/blog/2008/11/07/wsfphp-samples-explained/#comments</comments>
		<pubDate>Fri, 07 Nov 2008 12:20:02 +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[beginners]]></category>
		<category><![CDATA[code first]]></category>
		<category><![CDATA[contract first]]></category>
		<category><![CDATA[data services]]></category>
		<category><![CDATA[mtom]]></category>
		<category><![CDATA[reliable messaging]]></category>
		<category><![CDATA[samples]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=589</guid>
		<description><![CDATA[Here is a simple categorization of the WSF/PHP samples. You can access all the wsf/php samples from http://labs.wso2.org/wsf/php/solutions/samples/index.html. Sample Category Example Client Source Code Example Service Source Code Online Demo Beginners echo_client.php echo_service.php Demo REST echo_client_rest.php echo_service_with_rest.php Demo WSDL Mode (Contract First) wsdl_11_client.php wsdl_11_service.php Demo WSDL Generation (Code First) doclit_client.php doclit_service.php Demo MTOM Attachments mtom_download_client.php [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a simple categorization of the <a href="http://wso2.org/projects/wsf/php">WSF/PHP </a>samples. You can access all the wsf/php samples from <a href="http://labs.wso2.org/wsf/php/solutions/samples/index.html">http://labs.wso2.org/wsf/php/solutions/samples/index.html</a>.</p>
<table border="1">
<tbody>
<tr style="background:#dddddd">
<td>Sample Category</td>
<td>Example Client Source Code</td>
<td>Example Service Source Code</td>
<td>Online Demo</td>
</tr>
<tr>
<td>Beginners</td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2Fecho_client.php">echo_client.php</a></td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2Fecho_service.php">echo_service.php</a></td>
<td><a href="http://labs.wso2.org/wsf/php/solutions/samples/echo_client.php">Demo</a></td>
</tr>
<tr>
<td>REST</td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2Fecho_client_rest.php">echo_client_rest.php</a></td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2Fecho_service_with_rest.php">echo_service_with_rest.php</a></td>
<td><a href="http://labs.wso2.org/wsf/php/solutions/samples/echo_client_rest.php">Demo</a></td>
</tr>
<tr>
<td>WSDL Mode (Contract First)</td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2Fwsdl_mode%2Fwsdl_11_client.php">wsdl_11_client.php</a></td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2Fwsdl_mode%2Fwsdl_11_service.php">wsdl_11_service.php</a></td>
<td><a href="http://labs.wso2.org/wsf/php/solutions/samples/wsdl_mode/wsdl_11_client.php">Demo</a></td>
</tr>
<tr>
<td>WSDL Generation (Code First)</td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2Fwsdl_generation%2Fdoclit_client.php">doclit_client.php</a></td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2Fwsdl_generation%2Fdoclit_service.php">doclit_service.php</a></td>
<td><a href="http://labs.wso2.org/wsf/php/solutions/samples/wsdl_generation/doclit_client.php">Demo</a></td>
</tr>
<tr>
<td>MTOM Attachments</td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2Fmtom%2Fmtom_download_client.php">mtom_download_client.php</a></td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2Fmtom%2Fmtom_download_service.php">mtom_download_service.php</a></td>
<td><a href="http://labs.wso2.org/wsf/php/solutions/samples/mtom/mtom_download_client.php">Demo</a></td>
</tr>
<tr>
<td>Security</td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2Fsecurity%2Fencryption%2Fclient.php">encryption_client.php</a></td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2Fsecurity%2Fencryption%2Fservice.php">encryption_service.php</a></td>
<td><a href="http://labs.wso2.org/wsf/php/solutions/samples/security/encryption/client.php">Demo</a></td>
</tr>
<tr>
<td>Reliable Messaging</td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2Freliable%2Fecho_client_rm.php">echo_client_rm.php</a></td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2Freliable%2Fecho_service_rm.php">echo_service_rm.php</a></td>
<td><a href="http://labs.wso2.org/wsf/php/solutions/samples/reliable/echo_client_rm.php">Demo</a></td>
</tr>
<tr>
<td>Data Services</td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2FDataServices%2FCustomerDetailsClient.php">CustomerDetailsClient.php</a><a></a></td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2FDataServices%2FCustomerDetailsService.php">CustomerDetailsService.php</a><a></a></td>
<td><a href="http://labs.wso2.org/wsf/php/solutions/samples/DataServices/CustomerDetailsClient.php">Demo</a></td>
</tr>
</tbody>
</table>
<p>If you have downloaded the  <a href="http://wso2.org/projects/wsf/php">WSF/PHP binaries or souce code</a> package you can find all these samples, inside the &#8216;samples&#8217; directory</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/11/07/wsfphp-samples-explained/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>
		<item>
		<title>Demo on Providing PHP Web Service with Username Token</title>
		<link>http://www.dimuthu.org/blog/2008/10/16/demo-on-providing-php-web-service-with-username-token/</link>
		<comments>http://www.dimuthu.org/blog/2008/10/16/demo-on-providing-php-web-service-with-username-token/#comments</comments>
		<pubDate>Thu, 16 Oct 2008 17:43:45 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[security]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[WSDL]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[Calendar]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[policies]]></category>
		<category><![CDATA[wsdl mode]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=468</guid>
		<description><![CDATA[WSF/PHP Demo Site contains number of applications that demonstrate the different features of WSO2 WSF/PHP in practice. Calendar Service is one of such application. It demonstrate the use of WSDL Mode for a service with different policies for different operations + the use of Username tokens. You can view the source code of the Calendar [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://labs.wso2.org/wsf/php">WSF/PHP Demo Site</a> contains number of applications that demonstrate the different features of <a href="http://wso2.org/projects/wsf/php">WSO2 WSF/PHP</a> in practice. <a href="http://labs.wso2.org/wsf/php/resource_view.php?url=Calendar">Calendar Service</a> is one of such application. It demonstrate the use of WSDL Mode for a service with different policies for different operations + the use of Username tokens.</p>
<p>You can view the source code of the Calendar Service from <a href="http://labs.wso2.org/wsf/php/source_page_frame.php?src=Calendar">here</a>.</p>
<p>The username token is provided as an arguments to the WSService constructor at the end of <a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2FCalendar%2FCalendarService.php&amp;aschild=1">the service script</a>.</p>
<pre class="php"><span style="font-style: italic; color: #808080;">// our security token</span>
<span style="color: #0000ff;">$security_token</span> = <span style="font-weight: bold; color: #000000;">new</span> WSSecurityToken<span style="color: #66cc66;">(</span><a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"passwordCallback"</span> =&gt; <span style="color: #ff0000;">"get_password"</span>,
                                      <span style="color: #ff0000;">"passwordType"</span> =&gt; <span style="color: #ff0000;">"plain"</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;
<span style="font-style: italic; color: #808080;">// create service in WSDL mode</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;">"wsdl"</span> =&gt;<span style="color: #ff0000;">"Calendar.wsdl"</span>,
        <span style="color: #ff0000;">"actions"</span> =&gt; <span style="color: #0000ff;">$actions</span>,
        <span style="color: #ff0000;">"classmap"</span> =&gt; <span style="color: #0000ff;">$class_map</span>,
        <span style="color: #ff0000;">"securityToken"</span> =&gt; <span style="color: #0000ff;">$security_token</span>,
        <span style="color: #ff0000;">"operations"</span> =&gt; <span style="color: #0000ff;">$operations</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;

<span style="font-style: italic; color: #808080;">// process client requests and reply </span>
<span style="color: #0000ff;">$service</span>-&gt;<span style="color: #006600;">reply</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</pre>
<p>We use a callback function (&#8220;get_password&#8221;) to validate the user and give that function name to the securityToken object constructor. Inside that callback function, we retrieve the password for the user from a database call. Here is the code inside the callback function that is again extracted out from the <a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2FCalendar%2FCalendarService.php">calendar service</a>.</p>
<pre class="php"><span style="font-style: italic; color: #808080;">/**
 * call back function.
 * verify the validity of user enterd password with
 * the actual password which is kept in the database.
 */</span>
<span style="color: #0000ff;">$current_username</span> = <span style="color: #ff0000;">""</span>;
<span style="font-weight: bold; color: #000000;">function</span> get_password<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$username</span><span style="color: #66cc66;">)</span>
<span style="color: #66cc66;">{</span>

    <span style="color: #0000ff;">$dbhost</span> = DB_HOST;
    <span style="color: #0000ff;">$dbname</span> = DB_NAME;
    <span style="color: #0000ff;">$dbuname</span> = DB_USERNAME;
    <span style="color: #0000ff;">$dbpass</span> = DB_PASSWORD;
    <span style="color: #0000ff;">$link</span>=<a href="http://www.php.net/mysql_connect"><span style="color: #000066;">mysql_connect</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$dbhost</span>,  <span style="color: #0000ff;">$dbuname</span>,  <span style="color: #0000ff;">$dbpass</span><span style="color: #66cc66;">)</span>;
    <a href="http://www.php.net/mysql_select_db"><span style="color: #000066;">mysql_select_db</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$dbname</span>, <span style="color: #0000ff;">$link</span><span style="color: #66cc66;">)</span>;

    <span style="color: #0000ff;">$sql</span>=<span style="color: #ff0000;">"SELECT password FROM `customer_details` WHERE `user_name` = '"</span>.<span style="color: #0000ff;">$username</span>.<span style="color: #ff0000;">"'"</span>;
    <span style="color: #0000ff;">$result</span>=<a href="http://www.php.net/mysql_query"><span style="color: #000066;">mysql_query</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$sql</span>,<span style="color: #0000ff;">$link</span><span style="color: #66cc66;">)</span>;
    <span style="color: #0000ff;">$password</span>=<a href="http://www.php.net/mysql_fetch_array"><span style="color: #000066;">mysql_fetch_array</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$result</span>, MYSQL_NUM<span style="color: #66cc66;">)</span>;

    <a href="http://www.php.net/global"><span style="color: #000066;">global</span></a> <span style="color: #0000ff;">$current_username</span>;
    <span style="color: #b1b100;">if</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$password</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>
         <span style="color: #0000ff;">$current_username</span> = <span style="color: #0000ff;">$username</span>;
         <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$password</span><span style="color: #66cc66;">[</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">]</span>;
    <span style="color: #66cc66;">}</span>
    <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">{</span>
         <span style="color: #0000ff;">$current_username</span> = <span style="color: #ff0000;">""</span>;
         <span style="color: #b1b100;">return</span> <span style="font-weight: bold; color: #000000;">NULL</span>;
    <span style="color: #66cc66;">}</span>
<span style="color: #66cc66;">}</span></pre>
<p>So for all the operations which require authentication like login, getEvents, deleteEvents and addEvent, the WSF/PHP engine validate the user before invoking the operation. If the authentication fails, the engine will send a SOAP fault with the fault details. But in this service there is a operation which doesn&#8217;t require authentication. That is the &#8216;register&#8217; operation. Because until the registration complete you can&#8217;t have a username password, so we should not authenticate that &#8216;register&#8217; operation. So we need to provide a different policy for the &#8216;register&#8217; operation.</p>
<p>The policies for each of the operation is declared in the <a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2FCalendar%2FCalendar.wsdl&amp;aschild=1">Calender.wsdl</a> itself.  If you look at the WSDL you can see each of the policies required by the operations are declared inside the policy elements as mentioned in WS-Policy Specification. And each of the operation refers the corresponding policy element from the binding section of the WSDL.</p>
<p>You can see how it is done for login (which requires authentication) and the register (which doesn&#8217;t requires authentication) from the code below.</p>
<pre class="xml">        <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-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-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 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></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/10/16/demo-on-providing-php-web-service-with-username-token/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WSDL2PHP 2 Minutes Introduction</title>
		<link>http://www.dimuthu.org/blog/2008/09/21/wsdl2php-2-minutes-introduction/</link>
		<comments>http://www.dimuthu.org/blog/2008/09/21/wsdl2php-2-minutes-introduction/#comments</comments>
		<pubDate>Sun, 21 Sep 2008 17:54:43 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[2 minutes guide]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[WSDL]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[xml schema]]></category>
		<category><![CDATA[2 minutes]]></category>
		<category><![CDATA[client]]></category>
		<category><![CDATA[consumers]]></category>
		<category><![CDATA[guide]]></category>
		<category><![CDATA[WSClient]]></category>
		<category><![CDATA[wsdl2php]]></category>

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

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

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

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

    <span style="font-style: italic; color: #808080;">//--------my code-----</span>
    <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #0000ff;">$response</span>-&gt;<span style="color: #006600;">return</span>;
    <span style="font-style: italic; color: #808080;">//--------------------</span></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/09/21/wsdl2php-2-minutes-introduction/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>WSF/PHP WSDL Generation 2 Minutes Introduction</title>
		<link>http://www.dimuthu.org/blog/2008/09/05/wsfphp-wsdl-generation-2-minutes-introduction/</link>
		<comments>http://www.dimuthu.org/blog/2008/09/05/wsfphp-wsdl-generation-2-minutes-introduction/#comments</comments>
		<pubDate>Fri, 05 Sep 2008 12:33:46 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[2 minutes guide]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[WSDL]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[xml schema]]></category>
		<category><![CDATA[2 minutes]]></category>
		<category><![CDATA[annotations]]></category>
		<category><![CDATA[wsdl generation]]></category>

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

<span style="font-weight: bold; color: #000000;">function</span> getInvoice<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$order_no</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>
   <span style="font-style: italic; color: #808080;">//something that return an invoice for this order </span>
<span style="color: #66cc66;">}</span>

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

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

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

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

<span style="color: #0000ff;">$operations</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"getInvoice"</span> =&gt; <span style="color: #ff0000;">"getInvoice"</span><span style="color: #66cc66;">)</span>;
<span style="color: #0000ff;">$opParams</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"getInvoice"</span> =&gt; <span style="color: #ff0000;">"MIXED"</span><span style="color: #66cc66;">)</span>; <span style="font-style: italic; color: #808080;">// Have to declare parameters as MIXED</span>

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

<span style="color: #0000ff;">$svr</span>-&gt;<span style="color: #006600;">reply</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;
<span style="font-weight: bold; color: #000000;">?&gt;</span></pre>
<p>Now check the schema. It will gives you the information specific to your request, response messages.</p>
<pre><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xsd:schema</span> <span style="color: #000066;">elementFormDefault</span>=<span style="color: #ff0000;">"qualified"</span>
    <span style="color: #000066;">targetNamespace</span>=<span style="color: #ff0000;">"http://www.wso2.org/php/xsd"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xsd:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"getInvoice"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xsd:complexType<span style="font-weight: bold; color: black;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xsd:sequence<span style="font-weight: bold; color: black;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xsd:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"orderNo"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"xsd:int"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xsd:sequence<span style="font-weight: bold; color: black;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xsd:complexType<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xsd:element<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xsd:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"getInvoiceResponse"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xsd:complexType<span style="font-weight: bold; color: black;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xsd:sequence<span style="font-weight: bold; color: black;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xsd:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"invoice"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"xsd:string"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xsd:sequence<span style="font-weight: bold; color: black;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xsd:complexType<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xsd:element<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xsd:schema<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>So it is your chance to do more experiment with this feature. Check <a href="http://wso2.org/project/wsf/php/1.3.2/docs/wsdl_generation_api.html">WSDL generation API</a> for more snippets.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/09/05/wsfphp-wsdl-generation-2-minutes-introduction/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>How to Build Custom SOAP Headers in WSDL Using Axis2/C and WSF/PHP</title>
		<link>http://www.dimuthu.org/blog/2008/08/21/how-to-build-custom-soap-headers-in-wsdl-using-axis2c-and-wsfphp/</link>
		<comments>http://www.dimuthu.org/blog/2008/08/21/how-to-build-custom-soap-headers-in-wsdl-using-axis2c-and-wsfphp/#comments</comments>
		<pubDate>Thu, 21 Aug 2008 01:29:47 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[adb]]></category>
		<category><![CDATA[axis2/c]]></category>
		<category><![CDATA[codegen]]></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[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[Headers]]></category>
		<category><![CDATA[SOAP]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=200</guid>
		<description><![CDATA[SOAP Headers are used in many WS-* standards (for an example WS-Security) to transmit information related to the QOS aspects of the service. So only the SOAP engines which process these QOS parameters are supposed to see these headers. Web Service Developer or Consumer need to care only what is in the SOAP payload (which [...]]]></description>
			<content:encoded><![CDATA[<p>SOAP Headers are used in many WS-* standards (for an example WS-Security) to transmit information related to the QOS aspects of the service. So only the SOAP engines which process these QOS parameters are supposed to see these headers. Web Service Developer or Consumer need to care only what is in the SOAP payload (which is what inside the SOAP body element) and not SOAP headers.</p>
<p>But that is theory, In practice we see many places where people uses SOAP headers to transmit what they should have easily sent through SOAP Body. And many SOAP stacks also provide APIs to allow people to send/receive custom headers and standards like WSDL too provide ways to describe services which accept custom headers. So I thought it might worth to discuss how you describe custom headers in a service from a WSDL and how you can consume and serve in real world with SOAP stacks like <a href="http://ws.apache.org/axis2">Axis2/C</a> and <a href="http://wso2.org/projects/wsf/php">WSF/PHP</a>.</p>
<p>In a WSDL 1.1 you first declare your headers in the binding section itself which is the section that is used to provide the messaging and transport protocol information.</p>
<pre>  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;binding</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"RetHeaderBinding"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"tns:RetHeaderPortType"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;soap: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;operation</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"echoString"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;soap:operation</span> <span style="color: #000066;">soapAction</span>=<span style="color: #ff0000;">"http://soapinterop.org/"</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;input<span style="font-weight: bold; color: black;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;soap: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;soap:header</span> <span style="color: #000066;">message</span>=<span style="color: #ff0000;">"tns:Header1"</span> <span style="color: #000066;">part</span>=<span style="color: #ff0000;">"Header1"</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;soap:header</span> <span style="color: #000066;">message</span>=<span style="color: #ff0000;">"tns:Header2"</span> <span style="color: #000066;">part</span>=<span style="color: #ff0000;">"Header2"</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;/input<span style="font-weight: bold; color: black;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;output<span style="font-weight: bold; color: black;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;soap: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;soap:header</span> <span style="color: #000066;">message</span>=<span style="color: #ff0000;">"tns:Header1"</span> <span style="color: #000066;">part</span>=<span style="color: #ff0000;">"Header1"</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;soap:header</span> <span style="color: #000066;">message</span>=<span style="color: #ff0000;">"tns:Header2"</span> <span style="color: #000066;">part</span>=<span style="color: #ff0000;">"Header2"</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;/output<span style="font-weight: bold; color: black;">&gt;</span></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;/binding<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>There you can see we have Header1 and Header2 in both in input and output of the operation. It refers to the message section with the specific part name that represent the header. Here is how message section will look like.</p>
<pre>  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;message</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"Header1"</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;">"Header1"</span> <span style="color: #000066;">element</span>=<span style="color: #ff0000;">"types:Header1"</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;">"Header2"</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;">"Header2"</span> <span style="color: #000066;">element</span>=<span style="color: #ff0000;">"types:Header2"</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></pre>
<p>In this section it refers to the schema element that actually describe the element structure/schema. Here I put a string and an int in each header.</p>
<pre>  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;s:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"Header1"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;s:complexType<span style="font-weight: bold; color: black;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;s:sequence<span style="font-weight: bold; color: black;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;s:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"string"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"s:string"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
          <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;s:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"int"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"s:int"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/s:sequence<span style="font-weight: bold; color: black;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/s:complexType<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/s:element<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;s:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"Header2"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;s:complexType<span style="font-weight: bold; color: black;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;s:sequence<span style="font-weight: bold; color: black;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;s:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"int"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"s:int"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
          <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;s:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"string"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"s:string"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/s:sequence<span style="font-weight: bold; color: black;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/s:complexType<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/s:element<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>Here is a valid SOAP message for the WSDL description.</p>
<pre><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 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;ns1:Header1</span> xmlns:ns1=<span style="color: #ff0000;">"http://soapinterop.org/xsd"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
         <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ns1: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;/ns1:string<span style="font-weight: bold; color: black;">&gt;</span></span></span>
         <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ns1: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;/ns1:int<span style="font-weight: bold; color: black;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/ns1:Header1<span style="font-weight: bold; color: black;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ns1:Header2</span> xmlns:ns1=<span style="color: #ff0000;">"http://soapinterop.org/xsd"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
         <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ns1:int<span style="font-weight: bold; color: black;">&gt;</span></span></span>8<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/ns1:int<span style="font-weight: bold; color: black;">&gt;</span></span></span>
         <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ns1: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;/ns1:string<span style="font-weight: bold; color: black;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/ns1: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>
      My payload
   <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>If you are using <a href="http://ws.apache.org/axis2">Apache Axis2/C WSDL2C Codegen tool (which is shipped with Axis2/Java)</a> you will be able to directly use the API provided with the generated code to deal with custom headers. Here is how the client API is generated for the above WSDL.</p>
<pre>         <span style="font-style: italic; color: #808080;">/**
          * auto generated method signature
          * for "echoString|http://ws.dimuthu.org/blog/headers" operation.
          *
          * @param _echoStringParam
          * @param _header1
          * @param _header2
          *
          * @param dp_header10 - output header
          * @param dp_header21 - output header
          * @return adb_echoStringReturn_t*
          */</span>
         adb_echoStringReturn_t*
         axis2_stub_op_RetHeaderService_echoString<span style="color: #66cc66;">(</span> axis2_stub_t *stub, <span style="color: #993333;">const</span> axutil_env_t *env,
                                              adb_echoStringParam_t* _echoStringParam,
                                              adb_Header1E0_t* _header1,
                                              adb_Header2E1_t* _header2,
                                              adb_Header1E0_t** dp_header10 <span style="font-style: italic; color: #808080;">/* output header double ptr*/</span>,
                                              adb_Header2E1_t** dp_header21 <span style="font-style: italic; color: #808080;">/* output header double ptr*/</span><span style="color: #66cc66;">)</span></pre>
<p>Note that the first parameter is the environment variable passed in every function in Axis2/c. The second parameters is the payload. Input headers (input headers for server side) are in 3rd and 4th parameters, you can build them similar to how you build payload object. 5th and 6th are for the output headers which you only need to provide some pointers and the generated code will build you the objects from the response data.</p>
<p>You service will also have a similar API. There you have to create adb objects for output headers (like you build output payload) and assign the pointer to these output header double pointers.</p>
<pre>             adb_Header2_t* arg_Header1 = adb_Header1_create<span style="color: #66cc66;">(</span>env<span style="color: #66cc66;">)</span>;
             adb_Header1_set_string<span style="color: #66cc66;">(</span>arg_Header1, env, <span style="color: #ff0000;">"I m response Header 1"</span><span style="color: #66cc66;">)</span>;
             adb_Header1_set_int<span style="color: #66cc66;">(</span>arg_Header1, env, <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">)</span>;
             adb_Header10_t* _header1 = adb_Header10_create<span style="color: #66cc66;">(</span>env<span style="color: #66cc66;">)</span>;
             adb_Header10_set_Header1<span style="color: #66cc66;">(</span>_header1, env, arg_Header1<span style="color: #66cc66;">)</span>;
             *dp_header10 = _header1;</pre>
<p>Now how about PHP, can you provide the same API form the PHP as well. Yes, PHP has references similar to C pointers. WSF/PHP already have the custom headers support in the SVN and to be released with the 2.0.<br />
Here is the generated API for the service business logic for the above WSDL.</p>
<pre><span style="font-style: italic; color: #808080;">/**
 * Service function echoString
 * @param string $input
 * @param object of Header1 $header_in0 input header
 * @param object of Header2 $header_in1 input header
 * @param reference object of Header1 $header_out0 output header
 * @param reference object of Header2 $header_out1 output header
 * @return string
 */</span>
<span style="font-weight: bold; color: #000000;">function</span> echoString<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="color: #66cc66;">{</span>

...
<span style="color: #66cc66;">}</span></pre>
<p>These tool provides APIs to consume and provide data through custom headers in same easiness you send the data in the payload. Anyway it is really recommended to not to use custom SOAP headers in your Service and try to avoid them as much as possible. Whenever you think there is valid reason to put a custom header (it is relevant to QOS aspects), just try to integrate the header processing logic to the SOAP engine. In Axis2 C or Java you can write Axis2 modules for that. That will really speed up the processing of your service and give consumers a well-designed API.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/08/21/how-to-build-custom-soap-headers-in-wsdl-using-axis2c-and-wsfphp/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

