<?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; SOAP</title>
	<atom:link href="http://www.dimuthu.org/tag/soap/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>Article Introducing PHP Data Services</title>
		<link>http://www.dimuthu.org/blog/2009/01/05/article-introducing-php-data-services/</link>
		<comments>http://www.dimuthu.org/blog/2009/01/05/article-introducing-php-data-services/#comments</comments>
		<pubDate>Mon, 05 Jan 2009 13:06:55 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[database]]></category>
		<category><![CDATA[DataServices]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[RESTful]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[SQL]]></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[introduction]]></category>
		<category><![CDATA[SOAP]]></category>
		<category><![CDATA[WS-*]]></category>
		<category><![CDATA[ws-security]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=900</guid>
		<description><![CDATA[Now you can view the article I wrote titling &#8220;Introduction to PHP Data Services&#8220;. There I explain how you can design and implement Data Services in PHP using WSF/PHP Data Services Library. This article covers, Designing your Data Service API. Writing the Data Service. Deploying and Testing Data Service. Make the Data Service available in [...]]]></description>
			<content:encoded><![CDATA[<p>Now you can view the article I wrote titling &#8220;<a href="http://wso2.org/library/articles/introduction-php-data-services">Introduction to PHP Data Services</a>&#8220;. There I explain how you can design and implement Data Services in PHP using <a href="http://wso2.org/projects/wsf/php">WSF/PHP</a> Data Services Library.</p>
<p>This article covers,</p>
<ol>
<li>Designing your Data Service API.</li>
<li>Writing the Data Service.</li>
<li>Deploying and Testing Data Service.</li>
<li>Make the Data Service available in both SOAP and RESTful form.</li>
<li>Use of WS-* features in your Data Service.</li>
</ol>
<p>If you are thinking of adapting SOA in to your database backed PHP applications, this article will be a good starting point.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2009/01/05/article-introducing-php-data-services/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Calling Simple Web Services From Javascript</title>
		<link>http://www.dimuthu.org/blog/2008/12/11/calling-simple-web-services-from-javascript/</link>
		<comments>http://www.dimuthu.org/blog/2008/12/11/calling-simple-web-services-from-javascript/#comments</comments>
		<pubDate>Thu, 11 Dec 2008 12:00:59 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[mashup server]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[mashup]]></category>
		<category><![CDATA[SOAP]]></category>
		<category><![CDATA[web applications]]></category>
		<category><![CDATA[WSRequest]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=785</guid>
		<description><![CDATA[If you are a web developer, you may have found many occasions you have to create simple mashups for your web site. There you call web services or data services to fill the content of the web page. Most of the time we call web services from a server side script, since there are many [...]]]></description>
			<content:encoded><![CDATA[<p>If you are a web developer, you may have found many occasions you have to create simple mashups for your web site. There you call web services or data services to fill the content of the web page. Most of the time we call web services from a server side script, since there are many server side technologies like Java, PHP, .NET support web services.</p>
<p>But sometime it is in vain that you call your server scripts for a simple web service request. In fact You can use the famous XMLHttpRequest object to do the same thing from the client side itself. But you may need to prepare the complete SOAP envelope (Yea with SOAP headers, if required) in your hand to send it through XMLHttpRequest.</p>
<p>Another option is to  use the WSRequest script (<a href="http://mooshup.com/js/wso2/WSRequest.js">http://mooshup.com/js/wso2/WSRequest.js</a>). We normally use this script in the <a href="http://wso2.org/projects/mashup">WSO2 Mashup Server</a> to call the mashups designed in the serverside using stub. (The server side mashup is also mostly written in Javascript). We can use this script stand alone to call remote web services as well.</p>
<p>It introduce you the WSRequest class. It is exactly similar to the famous XMLHttpRequest class we used in  AJAX. In stead of plain message over HTTP like in the case of XMLHttpRequest, WSRequest send and receive messages in SOAP form. Here is its API in brief.</p>
<pre class="javascript"><span style="font-weight: bold; color: #003366;">var</span> WSRequest = <span style="font-weight: bold; color: #003366;">function</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>
    <span style="font-style: italic; color: #009900;">//----------------------------------------------------</span>
    <span style="font-style: italic; color: #009900;">// the public properties - equivalent to XMLHTTPRequest</span>
    <span style="font-style: italic; color: #009900;">//-----------------------------------------------------</span>
    <span style="font-weight: bold; color: #000066;">this</span>.<span style="color: #006600;">readyState</span> = <span style="color: #cc0000;">0</span>;
    <span style="font-weight: bold; color: #000066;">this</span>.<span style="color: #006600;">responseText</span> = <span style="font-weight: bold; color: #003366;">null</span>;
    <span style="font-weight: bold; color: #000066;">this</span>.<span style="color: #006600;">responseXML</span> = <span style="font-weight: bold; color: #003366;">null</span>;
    <span style="font-weight: bold; color: #000066;">this</span>.<span style="color: #006600;">error</span> = <span style="font-weight: bold; color: #003366;">null</span>;  <span style="font-style: italic; color: #009900;">// equivalent to httpErrorCode</span>
    <span style="font-weight: bold; color: #000066;">this</span>.<span style="color: #006600;">onreadystatechange</span> = <span style="font-weight: bold; color: #003366;">null</span>;
    <span style="font-weight: bold; color: #000066;">this</span>.<span style="color: #006600;">proxyAddress</span> = <span style="font-weight: bold; color: #003366;">null</span>;
    <span style="font-weight: bold; color: #000066;">this</span>.<span style="color: #006600;">proxyEngagedCallback</span> = <span style="font-weight: bold; color: #003366;">null</span>
<span style="color: #66cc66;">}</span>

<span style="font-style: italic; color: #009900;">//----------------------------------------------------</span>
<span style="font-style: italic; color: #009900;">// the public operations - equivalent to XMLHTTPRequest</span>
<span style="font-style: italic; color: #009900;">//-----------------------------------------------------</span>

<span style="font-style: italic; color: #009900;">/**
 * @description Prepare a Web Service Request .
 * @method open
 * @param {hash} options,
 *   possible options: possible values for the option
 *            useSOAP : false/true/1.1/1.2
 *            useWSA : true/false/1.0/submission
 *            useWSS : true/false (only for usernametoken &amp; timestamp)
 *
 * @param {string} URL
 * @param {boolean} asyncFlag
 * @param {string} username
 * @param {string} password
 */</span>
WSRequest.<span style="color: #006600;">prototype</span>.<span style="color: #000066;">open</span> = <span style="font-weight: bold; color: #003366;">function</span><span style="color: #66cc66;">(</span>options, URL, asnycFlag, username, password<span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>.. <span style="color: #66cc66;">}</span>

<span style="font-style: italic; color: #009900;">/**
 * @description Send the payload to the Web Service.
 * @method send
 * @param {dom} response xml payload
 */</span>
WSRequest.<span style="color: #006600;">prototype</span>.<span style="color: #006600;">send</span> = <span style="font-weight: bold; color: #003366;">function</span><span style="color: #66cc66;">(</span>payload<span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>.. <span style="color: #66cc66;">}</span></pre>
<p>I wrote a simple javascript/html demo which calls the data service that I published for my blog. This service is written using <a href="http://wso2.org/projects/wsf/php">WSF/PHP</a> Data Services. Check the demo and client, service sources  from the following links.</p>
<table border="0">
<tbody>
<tr>
<td class="first">AJAX Tag Search</td>
<td class="second"><a href="http://ws.dimuthu.org/blog/WordpressTagSearchJSClientNoAuth.html">Demo</a> |  <a href="http://ws.dimuthu.org/blog/WordpressTagSearchServiceNoAuth.php?wsdl">WSDL</a><a> | </a><a href="http://ws.dimuthu.org/source.php?src=tag.search.NoAuthclient">Client</a> |  <a href="http://ws.dimuthu.org/source.php?src=tag.search.NoAuthservice">Service</a></td>
<td class="third">Demonstrates how you use SOAP Data Services using WSRequest object to retrieve the data asynchronously from javascript</td>
</tr>
</tbody>
</table>
<p>There You can see, how easy to write an AJAX like page for call web services using the WSRequest javascript class.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/12/11/calling-simple-web-services-from-javascript/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>DEMO on a SOAP and REST Client with PHP</title>
		<link>http://www.dimuthu.org/blog/2008/10/17/demo-on-a-soap-and-rest-client-with-php/</link>
		<comments>http://www.dimuthu.org/blog/2008/10/17/demo-on-a-soap-and-rest-client-with-php/#comments</comments>
		<pubDate>Fri, 17 Oct 2008 16:50:57 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[REST]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[amazon]]></category>
		<category><![CDATA[demo]]></category>
		<category><![CDATA[SOAP]]></category>
		<category><![CDATA[WSClient]]></category>

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

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

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

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

        <span style="color: #0000ff;">$res</span> = <span style="color: #0000ff;">$simplexml</span>;

        <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$res</span>;
    <span style="color: #66cc66;">}</span></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/10/17/demo-on-a-soap-and-rest-client-with-php/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Writing a Simple REST and SOAP Service With PHP</title>
		<link>http://www.dimuthu.org/blog/2008/10/10/writing-a-simple-rest-and-soap-service-with-php/</link>
		<comments>http://www.dimuthu.org/blog/2008/10/10/writing-a-simple-rest-and-soap-service-with-php/#comments</comments>
		<pubDate>Fri, 10 Oct 2008 14:23:25 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[REST]]></category>
		<category><![CDATA[RESTful]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[SOAP]]></category>
		<category><![CDATA[Weather]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=457</guid>
		<description><![CDATA[WSF/PHP enables you to write both REST and SOAP services in PHP from a single script. I have written about how you can expose your Database as a REST and SOAP services in few of my previous posts using the Data Service capability of WSF/PHP. But there can be situations where your service is not [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://wso2.org/projects/wsf/php">WSF/PHP</a> enables you to write both REST and SOAP services in PHP from a single script. I have written about how you can expose your Database as a REST and SOAP services in <a href="http://www.dimuthu.org/blog/2008/09/18/do-rest-in-php-php-restful-data-services/">few of my previous posts</a> using the Data Service capability of WSF/PHP. But there can be situations where your service is not based on a Database. For an example it can use results of some calculations, or a mashup calling other services. In that case you will prefer to write the service logic yourself. Here is how you can do it.</p>
<p>Lets think we have weather forecast data (may be from another service) and I want to make a web service using it and make it accessible via both REST and SOAP protocols.</p>
<p>In our demo service we give forecasts of temperature, humidity and some other parameters for a given date. So I expect</p>
<p>SOAP request payload as following.</p>
<pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;weatherReport<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;date<span style="font-weight: bold; color: black;">&gt;</span></span></span>{date}<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/date<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;parameter<span style="font-weight: bold; color: black;">&gt;</span></span></span>{parameter}<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/parameter<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/weatherReport<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>And REST Request will be like</p>
<pre>weatherReport/{date}/forecast/{parameter}</pre>
<p>Note that here parameter can hold values like temperature, humidity or sunset-time.</p>
<p>First we declare our operation and the REST Request Mapping like this,</p>
<pre class="php"><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;">"weatherReport"</span> =&gt; <span style="color: #ff0000;">"weather_report"</span><span style="color: #66cc66;">)</span>;
<span style="color: #0000ff;">$restmap</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"weatherReport"</span> =&gt;
				<a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"HTTPMethod"</span> =&gt;<span style="color: #ff0000;">"GET"</span>,
				      <span style="color: #ff0000;">"RESTLocation"</span> =&gt; <span style="color: #ff0000;">"weatherReport/{date}/forecast/{parameter}"</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;</pre>
<p>When you declare your rest mapping like above , in the service operation you will have the same request XML for both SOAP and REST form like this,</p>
<pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;weatherReport<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;date<span style="font-weight: bold; color: black;">&gt;</span></span></span>{date}<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/date<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;parameter<span style="font-weight: bold; color: black;">&gt;</span></span></span>{parameter}<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/parameter<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/weatherReport<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>So in your service logic you just handling the request in only above format. You can easily extract out the request parameters using SimpleXML functions and return the corresponding result. So you service operation would be something like this,</p>
<pre class="php"><span style="font-weight: bold; color: #000000;">function</span> weather_report<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$in_message</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>

	<span style="font-style: italic; color: #808080;">// create the simple xml element for the request xml</span>
	<span style="color: #0000ff;">$request_xml</span> = <span style="font-weight: bold; color: #000000;">new</span> SimpleXMLElement<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$in_message</span>-&gt;<span style="color: #006600;">str</span><span style="color: #66cc66;">)</span>;

	<span style="font-style: italic; color: #808080;">// extract out the parameter and the date</span>
	<span style="color: #0000ff;">$date</span> = <span style="color: #0000ff;">$request_xml</span>-&gt;<span style="color: #006600;">date</span>;
	<span style="color: #0000ff;">$parameter</span> = <span style="color: #0000ff;">$request_xml</span>-&gt;<span style="color: #006600;">parameter</span>;

	<span style="font-style: italic; color: #808080;">// It is up to you to retrun the weather data ($result) for the requested date and parameter</span>

	<span style="color: #b1b100;">return</span> <span style="color: #ff0000;">"&lt;response&gt;$result&lt;/response&gt;"</span>;
<span style="color: #66cc66;">}</span></pre>
<p>Finally you create the WSService object with the &#8220;operations&#8221; and &#8220;RESTMapping&#8221; and call its reply method which actually response to the requests.</p>
<pre class="php"><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;">"RESTMapping"</span> =&gt; <span style="color: #0000ff;">$restmap</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;
<span style="color: #0000ff;">$service</span>-&gt;<span style="color: #006600;">reply</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</pre>
<p>You just created a web service which will handle both SOAP and REST requests.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/10/10/writing-a-simple-rest-and-soap-service-with-php/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Http Authentication for SOAP Messages in PHP &#8211; 2 Minutes Introduction</title>
		<link>http://www.dimuthu.org/blog/2008/09/24/http-authentication-for-sopa-messages-in-php-2-minutes-introduction/</link>
		<comments>http://www.dimuthu.org/blog/2008/09/24/http-authentication-for-sopa-messages-in-php-2-minutes-introduction/#comments</comments>
		<pubDate>Wed, 24 Sep 2008 17:29:28 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[2 minutes guide]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[2 minutes]]></category>
		<category><![CDATA[authentication]]></category>
		<category><![CDATA[basic]]></category>
		<category><![CDATA[HTTP]]></category>
		<category><![CDATA[messages]]></category>
		<category><![CDATA[SOAP]]></category>

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

		<guid isPermaLink="false">http://www.dimuthu.org/?p=102</guid>
		<description><![CDATA[When you are developing a Web Service, you have to think about the security aspects of your service seriously. When it comes to security in web services you have two basic choices. Transport level security &#8211; Just SOAP over HTTPS Message level security &#8211; WS-Security See my previous blog comparing Transport level and Message level [...]]]></description>
			<content:encoded><![CDATA[<p>When you are developing a Web Service, you have to think about the security aspects of your service seriously. When it comes to security in web services you have two basic choices.</p>
<ol>
<li>Transport level security &#8211; Just SOAP over HTTPS</li>
<li>Message level security &#8211; <a href="http://www.oasis-open.org/specs/index.php#wssv1.1">WS-Security</a></li>
</ol>
<p>See my previous blog <a href="http://www.dimuthu.org/blog/2008/08/14/transport-level-security-vs-message-level-security/">comparing Transport level and Message level security</a>.</p>
<p>If you are satisfied with the security provided by using just &#8216;SOAP over HTTPS&#8217;, you can get the work done by configuring your server (Apache or IIS) to enable ssl. See <a href="http://www.onlamp.com/pub/a/onlamp/2008/03/04/step-by-step-configuring-ssl-under-apache.html">http://www.onlamp.com/pub/a/onlamp/2008/03/04/step-by-step-configuring-ssl-under-apache.html</a> for an step by step guide for configure SSL in your Apache server.</p>
<p>If you want message level security for your application, just use WS-Security. With <a href="http://wso2.org/projects/wsf/php">WSF/PHP</a> it is even easier to implement than SOAP over HTTPS method, because you can provide the certificates programatically in PHP and no need to do further configuration.</p>
<p>WSF/PHP provides you two classes in line with <a href="http://wso2.org/project/wsf/php/1.3.2/docs/api_content.html#service">WSService</a> to implement an API to provide WS-Security.</p>
<ol>
<li><a href="http://wso2.org/project/wsf/php/1.3.2/docs/security_api.html#wspolicy">WSPolicy</a> -Let you provide rules that the engine need to follow in securing the message. E.g.
<pre><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; <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="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;</pre>
<p>In fact you can load policies from an xml which adheres to the WS-SecurityPolicy specification.</li>
<li> <a href="http://wso2.org/project/wsf/php/1.3.2/docs/security_api.html#ws_security_token">WSSecurityToken</a> &#8211; Keeps the security tokens like certificates, keys, username, passwords which would be used when applying the rules specified in the policy. E.g.
<pre><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;">$pub_key</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;</pre>
</li>
</ol>
<p>You can see the WS-Security in action on live from <a href="http://labs.wso2.org/wsf/php/samples/security/">http://labs.wso2.org/wsf/php/samples/security/</a> and  <a href="http://labs.wso2.org/wsf/php/source_page_frame.php?src=samples/security">security demo ource codes.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/08/14/encrypt-your-soap-messages-in-php/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

