<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Dimuthu's Blog &#187; xml</title>
	<atom:link href="http://www.dimuthu.org/catagory/xml/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dimuthu.org</link>
	<description>Waiting for your comments</description>
	<lastBuildDate>Wed, 21 Dec 2011 05:39:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<image>
  <link>http://www.dimuthu.org</link>
  <url>http://www.dimuthu.org/favicon.ico</url>
  <title>Dimuthu's Blog</title>
</image>
		<item>
		<title>WSF/PHP Code First Approach: Returning an Array of String</title>
		<link>http://www.dimuthu.org/blog/2010/01/08/wsfphp-code-first-approach-returning-an-array-of-string/</link>
		<comments>http://www.dimuthu.org/blog/2010/01/08/wsfphp-code-first-approach-returning-an-array-of-string/#comments</comments>
		<pubDate>Fri, 08 Jan 2010 02:05:12 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[WSDL]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[xml schema]]></category>
		<category><![CDATA[code first]]></category>
		<category><![CDATA[wsdl generation]]></category>

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

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

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

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

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

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

 
    <span style="color: #808080; font-style: italic;">// call the operation</span>
    <span style="color: #0000ff;">$response</span> = <span style="color: #0000ff;">$proxy</span>-&gt;<span style="color: #006600;">splitMe</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$input</span><span style="color: #66cc66;">)</span>;
    <a href="http://www.php.net/print_r"><span style="color: #000066;">print_r</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$response</span><span style="color: #66cc66;">)</span>;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2010/01/08/wsfphp-code-first-approach-returning-an-array-of-string/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Hello World To Web Services With C And C++</title>
		<link>http://www.dimuthu.org/blog/2009/01/22/hello-world-to-web-services-with-c-and-c/</link>
		<comments>http://www.dimuthu.org/blog/2009/01/22/hello-world-to-web-services-with-c-and-c/#comments</comments>
		<pubDate>Thu, 22 Jan 2009 04:39:27 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[axiom]]></category>
		<category><![CDATA[axis2/c]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[wsf/c++]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[hello world]]></category>
		<category><![CDATA[Web Service]]></category>
		<category><![CDATA[wsf/cpp]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=903</guid>
		<description><![CDATA[Once you have a web service, you can write clients to invoke that service from any language, mostly with the help of a framework written in to that particular language. When it comes to C, the most popular choice is Apache Axis2/C framework. When you are using Axis2/C to write web service clients, you need [...]]]></description>
			<content:encoded><![CDATA[<p>Once you have a web service, you can write clients to invoke that service from any language, mostly with the help of a framework written in to that particular language. When it comes to C, the most popular choice is <a href="http://ws.apache.org/axis2/c/">Apache Axis2/C</a> framework. When you are using Axis2/C to write web service clients, you need to learn about AXIOM which is a easy to use high performing XML model and the service client API which can be used to actually invoke the service. Lets look at the code.</p>
<pre class="c"><span style="color: #339933;">#include &lt;stdio.h&gt;</span>
<span style="color: #339933;">#include &lt;axiom.h&gt;</span>
<span style="color: #339933;">#include &lt;axis2_util.h&gt;</span>
<span style="color: #339933;">#include &lt;axiom_soap.h&gt;</span>
<span style="color: #339933;">#include &lt;axis2_client.h&gt;</span>

axiom_node_t *build_om_payload_for_helloworld_svc<span style="color: #66cc66;">(</span>
    <span style="color: #993333;">const</span> axutil_env_t * env<span style="color: #66cc66;">)</span>;

<span style="color: #993333;">int</span>
main<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>
<span style="color: #66cc66;">{</span>
    <span style="color: #993333;">const</span> axutil_env_t *env = <span style="color: #000000; font-weight: bold;">NULL</span>;
    <span style="color: #993333;">const</span> axis2_char_t *address = <span style="color: #000000; font-weight: bold;">NULL</span>;
    axis2_endpoint_ref_t *endpoint_ref = <span style="color: #000000; font-weight: bold;">NULL</span>;
    axis2_options_t *options = <span style="color: #000000; font-weight: bold;">NULL</span>;
    <span style="color: #993333;">const</span> axis2_char_t *client_home = <span style="color: #000000; font-weight: bold;">NULL</span>;
    axis2_svc_client_t *svc_client = <span style="color: #000000; font-weight: bold;">NULL</span>;
    axiom_node_t *payload = <span style="color: #000000; font-weight: bold;">NULL</span>;
    axiom_node_t *ret_node = <span style="color: #000000; font-weight: bold;">NULL</span>;

    <span style="color: #808080; font-style: italic;">/* Set up the environment */</span>
    env = axutil_env_create_all<span style="color: #66cc66;">(</span><span style="color: #ff0000;">"helloworld.log"</span>, AXIS2_LOG_LEVEL_TRACE<span style="color: #66cc66;">)</span>;

    <span style="color: #808080; font-style: italic;">/* Set end point reference of helloworld service */</span>
    address = <span style="color: #ff0000;">"http://localhost:9090/axis2/services/helloworld"</span>;

    <span style="color: #808080; font-style: italic;">/* Create EPR with given address */</span>
    endpoint_ref = axis2_endpoint_ref_create<span style="color: #66cc66;">(</span>env, address<span style="color: #66cc66;">)</span>;

    <span style="color: #808080; font-style: italic;">/* Setup options */</span>
    options = axis2_options_create<span style="color: #66cc66;">(</span>env<span style="color: #66cc66;">)</span>;
    axis2_options_set_to<span style="color: #66cc66;">(</span>options, env, endpoint_ref<span style="color: #66cc66;">)</span>;
    axis2_options_set_action<span style="color: #66cc66;">(</span>options, env,
                             <span style="color: #ff0000;">"http://ws.apache.org/axis2/c/samples/helloworldString"</span><span style="color: #66cc66;">)</span>;

    <span style="color: #808080; font-style: italic;">/* Set up deploy folder. It is from the deploy folder, the configuration is picked up
     * using the axis2.xml file. You need to set the AXIS2C_HOME variable to the axis2/c
     * installed dir.
     */</span>
    client_home = AXIS2_GETENV<span style="color: #66cc66;">(</span><span style="color: #ff0000;">"AXIS2C_HOME"</span><span style="color: #66cc66;">)</span>;
    <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span>!client_home || !strcmp<span style="color: #66cc66;">(</span>client_home, <span style="color: #ff0000;">""</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>
        client_home = <span style="color: #ff0000;">"../.."</span>;

    <span style="color: #808080; font-style: italic;">/* Create service client */</span>
    svc_client = axis2_svc_client_create<span style="color: #66cc66;">(</span>env, client_home<span style="color: #66cc66;">)</span>;
    <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span>!svc_client<span style="color: #66cc66;">)</span>
    <span style="color: #66cc66;">{</span>
        <span style="color: #808080; font-style: italic;">/* reporting the error */</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;">"Error creating service client, Please check AXIS2C_HOME again<span style="color: #000099; font-weight: bold;">\\</span>n"</span><span style="color: #66cc66;">)</span>;
        AXIS2_LOG_ERROR<span style="color: #66cc66;">(</span>env-&gt;log, AXIS2_LOG_SI,
                        <span style="color: #ff0000;">"Stub invoke FAILED: Error code:"</span> <span style="color: #ff0000;">" %d :: %s"</span>,
                        env-&gt;error-&gt;error_number,
                        AXIS2_ERROR_GET_MESSAGE<span style="color: #66cc66;">(</span>env-&gt;error<span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;
        <span style="color: #b1b100;">return</span> <span style="color: #cc66cc;">-1</span>;
    <span style="color: #66cc66;">}</span>

    <span style="color: #808080; font-style: italic;">/* Set service client options */</span>
    axis2_svc_client_set_options<span style="color: #66cc66;">(</span>svc_client, env, options<span style="color: #66cc66;">)</span>;

    <span style="color: #808080; font-style: italic;">/* Build the SOAP request message payload using OM API. */</span>
    payload = build_om_payload_for_helloworld_svc<span style="color: #66cc66;">(</span>env<span style="color: #66cc66;">)</span>;

    <span style="color: #808080; font-style: italic;">/* Send request */</span>
    ret_node = axis2_svc_client_send_receive<span style="color: #66cc66;">(</span>svc_client, env, payload<span style="color: #66cc66;">)</span>;

    <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span>ret_node<span style="color: #66cc66;">)</span>
    <span style="color: #66cc66;">{</span>
        <span style="color: #808080; font-style: italic;">/* extracting out the content from the response */</span>
        axis2_char_t *om_str = <span style="color: #000000; font-weight: bold;">NULL</span>;
        om_str = axiom_node_to_string<span style="color: #66cc66;">(</span>ret_node, env<span style="color: #66cc66;">)</span>;
        <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span>om_str<span style="color: #66cc66;">)</span>
            <a href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html"><span style="color: #000066;">printf</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"<span style="color: #000099; font-weight: bold;">\\</span>nReceived OM : %s<span style="color: #000099; font-weight: bold;">\\</span>n"</span>, om_str<span style="color: #66cc66;">)</span>;
        <a href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html"><span style="color: #000066;">printf</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"<span style="color: #000099; font-weight: bold;">\\</span>nhelloworld client invoke SUCCESSFUL!<span style="color: #000099; font-weight: bold;">\\</span>n"</span><span style="color: #66cc66;">)</span>;

        AXIS2_FREE<span style="color: #66cc66;">(</span>env-&gt;allocator, om_str<span style="color: #66cc66;">)</span>;
        ret_node = <span style="color: #000000; font-weight: bold;">NULL</span>;
    <span style="color: #66cc66;">}</span>
    <span style="color: #b1b100;">else</span>
    <span style="color: #66cc66;">{</span>
        AXIS2_LOG_ERROR<span style="color: #66cc66;">(</span>env-&gt;log, AXIS2_LOG_SI,
                        <span style="color: #ff0000;">"Stub invoke FAILED: Error code:"</span> <span style="color: #ff0000;">" %d :: %s"</span>,
                        env-&gt;error-&gt;error_number,
                        AXIS2_ERROR_GET_MESSAGE<span style="color: #66cc66;">(</span>env-&gt;error<span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;
        <a href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html"><span style="color: #000066;">printf</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"helloworld client invoke FAILED!<span style="color: #000099; font-weight: bold;">\\</span>n"</span><span style="color: #66cc66;">)</span>;
    <span style="color: #66cc66;">}</span>

    <span style="color: #808080; font-style: italic;">/* freeing the allocated memory */</span>
    <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span>svc_client<span style="color: #66cc66;">)</span>
    <span style="color: #66cc66;">{</span>
        axis2_svc_client_free<span style="color: #66cc66;">(</span>svc_client, env<span style="color: #66cc66;">)</span>;
        svc_client = <span style="color: #000000; font-weight: bold;">NULL</span>;
    <span style="color: #66cc66;">}</span>

    <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span>env<span style="color: #66cc66;">)</span>
    <span style="color: #66cc66;">{</span>
        axutil_env_free<span style="color: #66cc66;">(</span><span style="color: #66cc66;">(</span>axutil_env_t *<span style="color: #66cc66;">)</span> env<span style="color: #66cc66;">)</span>;
        env = <span style="color: #000000; font-weight: bold;">NULL</span>;
    <span style="color: #66cc66;">}</span>

    <span style="color: #b1b100;">return</span> <span style="color: #cc66cc;">0</span>;
<span style="color: #66cc66;">}</span></pre>
<p>Here is the implementation of the &#8220;build_om_payload_for_helloworld_svc&#8221; function that build the request SOAP message using Axiom/C. Note that axiom_element and axiom_node has one to one association. We use node to to navigate the XML, where as axiom_element to store the data.</p>
<pre class="c"><span style="color: #808080; font-style: italic;">/* build SOAP request message content using OM
           &lt;ns1:greet xmlns:ns1="http://ws.apache.org/axis2/services/helloworld"&gt;
                &lt;text&gt;Hello World&lt;/text&gt;
           &lt;/ns1:greet&gt;
*/</span>
axiom_node_t *
build_om_payload_for_helloworld_svc<span style="color: #66cc66;">(</span>
    <span style="color: #993333;">const</span> axutil_env_t * env<span style="color: #66cc66;">)</span>
<span style="color: #66cc66;">{</span>
    axiom_node_t *helloworld_om_node = <span style="color: #000000; font-weight: bold;">NULL</span>;
    axiom_element_t *helloworld_om_ele = <span style="color: #000000; font-weight: bold;">NULL</span>;
    axiom_node_t *text_om_node = <span style="color: #000000; font-weight: bold;">NULL</span>;
    axiom_element_t *text_om_ele = <span style="color: #000000; font-weight: bold;">NULL</span>;
    axiom_namespace_t *ns1 = <span style="color: #000000; font-weight: bold;">NULL</span>;
    axis2_char_t *om_str = <span style="color: #000000; font-weight: bold;">NULL</span>;

    ns1 =
       axiom_namespace_create<span style="color: #66cc66;">(</span>env, <span style="color: #ff0000;">"http://ws.apache.org/axis2/services/helloworld"</span>,
                               <span style="color: #ff0000;">"ns1"</span><span style="color: #66cc66;">)</span>;
    helloworld_om_ele =
        axiom_element_create<span style="color: #66cc66;">(</span>env, <span style="color: #000000; font-weight: bold;">NULL</span>, <span style="color: #ff0000;">"greet"</span>, ns1, &amp;helloworld_om_node<span style="color: #66cc66;">)</span>;
    text_om_ele =
        axiom_element_create<span style="color: #66cc66;">(</span>env, helloworld_om_node, <span style="color: #ff0000;">"text"</span>, <span style="color: #000000; font-weight: bold;">NULL</span>, &amp;text_om_node<span style="color: #66cc66;">)</span>;
    axiom_element_set_text<span style="color: #66cc66;">(</span>text_om_ele, env, <span style="color: #ff0000;">"Hello World!"</span>, text_om_node<span style="color: #66cc66;">)</span>;
    om_str = axiom_node_to_string<span style="color: #66cc66;">(</span>helloworld_om_node, env<span style="color: #66cc66;">)</span>;

    <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span>om_str<span style="color: #66cc66;">)</span>
    <span style="color: #66cc66;">{</span>
        <a href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html"><span style="color: #000066;">printf</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"<span style="color: #000099; font-weight: bold;">\\</span>nSending OM : %s<span style="color: #000099; font-weight: bold;">\\</span>n"</span>, om_str<span style="color: #66cc66;">)</span>;
        AXIS2_FREE<span style="color: #66cc66;">(</span>env-&gt;allocator, om_str<span style="color: #66cc66;">)</span>;
        om_str = <span style="color: #000000; font-weight: bold;">NULL</span>;
    <span style="color: #66cc66;">}</span>
    <span style="color: #b1b100;">return</span> helloworld_om_node;
<span style="color: #66cc66;">}</span></pre>
<p>So lets see how the same thing is done with C++. For C++ we use <a href="http://wso2.org/projects/wsf/cpp">WSO2 WSF/C++</a></p>
<pre class="cpp"><span style="color: #339900;">#include &lt;stdio.h&gt;</span>
<span style="color: #339900;">#include &lt;WSSOAPClient.h&gt;</span>
<span style="color: #339900;">#include &lt;OMElement.h&gt;</span>
<span style="color: #339900;">#include &lt;iostream&gt;</span>
<span style="color: #339900;">#include &lt;AxisFault.h&gt;</span>
<span style="color: #0000ff;">using</span> <span style="color: #0000ff;">namespace</span> std;
<span style="color: #0000ff;">using</span> <span style="color: #0000ff;">namespace</span> wso2wsf;

OMElement build_om_payload_for_helloworld_svc<span style="color: #000000;">(</span><span style="color: #000000;">)</span>;

<span style="color: #0000ff;">int</span> main<span style="color: #000000;">(</span><span style="color: #000000;">)</span>
<span style="color: #000000;">{</span>
    WSSOAPClient * sc = <span style="color: #0000dd;">new</span> WSSOAPClient<span style="color: #000000;">(</span><span style="color: #666666;">"http://localhost:9090/axis2/services/helloworld"</span><span style="color: #000000;">)</span>;
    sc-&gt;initializeClient<span style="color: #000000;">(</span><span style="color: #666666;">"helloworld_blocking.log"</span>, AXIS2_LOG_LEVEL_TRACE<span style="color: #000000;">)</span>;
    <span style="color: #000000;">{</span>
        <span style="color: #ff0000; font-style: italic;">/* generating the payload */</span>
        OMElement * payload = build_om_payload_for_helloworld_svc<span style="color: #000000;">(</span><span style="color: #000000;">)</span>;

        OMElement * response;
        <span style="color: #0000ff;">try</span>
        <span style="color: #000000;">{</span>
            <span style="color: #ff0000; font-style: italic;">/* invoking the web service */</span>
            response = sc-&gt;request<span style="color: #000000;">(</span>payload, <span style="color: #666666;">"http://ws.apache.org/axis2/c/samples/helloworldString"</span><span style="color: #000000;">)</span>;

            <span style="color: #ff0000; font-style: italic;">/* printing the response */</span>
            <span style="color: #0000ff;">if</span> <span style="color: #000000;">(</span>response<span style="color: #000000;">)</span>
            <span style="color: #000000;">{</span>
                <span style="color: #0000dd;">cout</span> &lt;&lt; endl &lt;&lt; <span style="color: #666666;">"Response: "</span> &lt;&lt; response &lt;&lt; endl;
            <span style="color: #000000;">}</span>
        <span style="color: #000000;">}</span>

        <span style="color: #ff0000; font-style: italic;">/* handling the fault */</span>
        <span style="color: #0000ff;">catch</span> <span style="color: #000000;">(</span>AxisFault &amp; e<span style="color: #000000;">)</span>
        <span style="color: #000000;">{</span>
            <span style="color: #0000ff;">if</span> <span style="color: #000000;">(</span>sc-&gt;getLastSOAPFault<span style="color: #000000;">(</span><span style="color: #000000;">)</span><span style="color: #000000;">)</span>
            <span style="color: #000000;">{</span>
                <span style="color: #0000dd;">cout</span> &lt;&lt; endl &lt;&lt; <span style="color: #666666;">"Response: "</span> &lt;&lt; sc-&gt;getLastSOAPFault<span style="color: #000000;">(</span><span style="color: #000000;">)</span> &lt;&lt; endl;
            <span style="color: #000000;">}</span>
            <span style="color: #0000ff;">else</span>
            <span style="color: #000000;">{</span>
                <span style="color: #0000dd;">cout</span> &lt;&lt; endl &lt;&lt; <span style="color: #666666;">"Response: "</span> &lt;&lt; e &lt;&lt; endl;
            <span style="color: #000000;">}</span>
        <span style="color: #000000;">}</span>
        <span style="color: #0000dd;">delete</span> payload;
    <span style="color: #000000;">}</span>
    <span style="color: #0000dd;">delete</span> sc;
<span style="color: #000000;">}</span></pre>
<p>You can see lines of code is reduced a lot. And you can see it from the code to build the request XML as well.</p>
<pre class="cpp"><span style="color: #ff0000; font-style: italic;">/* building the request soap message
   &lt;ns1:greet xmlns:ns1="http://ws.apache.org/axis2/services/helloworld"&gt;
        &lt;text&gt;Hello World&lt;/text&gt;
   &lt;/ns1:greet&gt;
 */</span>
OMElement build_om_payload_for_helloworld_svc<span style="color: #000000;">(</span><span style="color: #000000;">)</span>
<span style="color: #000000;">{</span>
    OMNamespace * ns = <span style="color: #0000dd;">new</span> OMNamespace<span style="color: #000000;">(</span><span style="color: #666666;">"http://ws.apache.org/axis2/services/helloworld"</span>, <span style="color: #666666;">"ns1"</span><span style="color: #000000;">)</span>;
    OMElement * payload = <span style="color: #0000dd;">new</span> OMElement<span style="color: #000000;">(</span><span style="color: #0000ff;">NULL</span>,<span style="color: #666666;">"greet"</span>, ns<span style="color: #000000;">)</span>;
    OMElement * child = <span style="color: #0000dd;">new</span> OMElement<span style="color: #000000;">(</span>payload,<span style="color: #666666;">"text"</span>, <span style="color: #0000ff;">NULL</span><span style="color: #000000;">)</span>;
    child-&gt;setText<span style="color: #000000;">(</span><span style="color: #666666;">"Hello World!"</span><span style="color: #000000;">)</span>;

    <span style="color: #0000ff;">return</span> payload;
<span style="color: #000000;">}</span></pre>
<p>WSF/C++ is build on top of Axis2/C. You can see the WSF/C++ API is designed very carefully to make it easy to use without breaking the flexibility provided in the C API. So C++ developers can straightaway use WSF/C++ to develop their web service consumers. Anyway Axis2/C API still has the power of embedding easily in to scripting languages  (Like it is done in WSF/PHP, WSF/Ruby) and probably deploy in legacy systems that doesn&#8217;t support C++ compiled binaries. So you have the options to select the most sutiable one for your application.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2009/01/22/hello-world-to-web-services-with-c-and-c/feed/</wfw:commentRss>
		<slash:comments>0</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>RESTful PHP Web Services &#8211; Book Review</title>
		<link>http://www.dimuthu.org/blog/2009/01/01/restful-php-web-services-book-review/</link>
		<comments>http://www.dimuthu.org/blog/2009/01/01/restful-php-web-services-book-review/#comments</comments>
		<pubDate>Thu, 01 Jan 2009 05:22:46 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[design]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[RESTful]]></category>
		<category><![CDATA[review]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[Book]]></category>
		<category><![CDATA[clients]]></category>
		<category><![CDATA[services]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=865</guid>
		<description><![CDATA[PHP is one of the famous choice, when it comes to develop a web site. As the web evolve with the emerge of web service, REST (REpresentational State Transfer) concepts, the PHP language is also adapted to the new requirements specially with the availability of new SOA (Service Oriented Architecture), REST frameworks and libraries. Anyway [...]]]></description>
			<content:encoded><![CDATA[<p>PHP is one of the famous choice, when it comes to develop a web site. As the web evolve with the emerge of web service, REST (REpresentational State Transfer) concepts, the PHP language is also adapted to the new requirements specially with the availability of new SOA (Service Oriented Architecture), REST frameworks and libraries. Anyway there were hardly any guides, references or samples that properly describe the methodologies of developing REST applications using PHP.</p>
<p>The book &#8220;<a href="http://www.packtpub.com/restful-php-web-services/book">RESTful PHP Web Services</a>&#8216; by <a href="http://samisa-abeysinghe.blogspot.com/">Samisa Abeysinghe</a> certainly fill this gap. It can be used as a step by step guideline for newbies to learn the concepts and write simple RESTful PHP applications and Mashups. And even experienced developers would find this a great reference to keep nearby while working with RESTful Web Services in PHP. And it has lot of code samples, utility functions that developers can use it in their applications.</p>
<p><a href="http://www.packtpub.com/restful-php-web-services/book"><img title="RESTful PHP Web Services - Samisa Abeysinghe" src="http://images.packtpub.com/images/full/1847195520.jpg" alt="RESTful PHP Web Services - Samisa Abeysinghe" width="200" /></a></p>
<p><strong>About the Author</strong></p>
<p><a href="http://samisa-abeysinghe.blogspot.com/">Samisa Abeysinghe</a> is a well recognized name in the web services world. He lead the development of <a href="http://ws.apache.org/axis2/c/">Apache Axis2/C</a> and <a href="http://wso2.org/projects/wsf/php">WSO2 WSF/PHP</a>, two famous open source web service frameworks for &#8216;C&#8217; and PHP. In addition to his deep knowledge in the subject, his experience in involving with the community and the enterprise for years and working as a lecturer in universities, should have influenced a lot in writing this book.</p>
<p><strong>The Arrangement and the Content</strong></p>
<p>The <a href="http://www.packtpub.com/article/restful-php-web-services-table-of-contents">arrangement of the book</a> is done really well to make sure the reader can go through it in the right sequence. All the content is bundled just within 200 pages. So you don&#8217;t need to allocate a lot of time to go through the whole book. It is organized into 7 chapters and two appendixes which are mostly independent from each other.</p>
<p>The first chapter is completely devoted to explain the concepts of RESTful web services. It basically explains what is RESTful web service and why it is needed. And it briefly mentions about the currently available REST Frameworks for PHP.</p>
<p>The second chapter introduce some PHP codes that do REST web service requests and handles the XML responses using both DOM and SimpleXML APIs. And in the third chapter it shows more code samples specially about consuming real world web services like BBC, Yahoo and an earthquakes information service. Theses codes are written as mashups mostly combining two services to produce more meaningful information.</p>
<p>The forth chapter is about  designing and writing web service providers. Its counterpart, writing web service consumers is described in the chapter five. There it demonstrate a library system that operate using RESTful webservices. You can map this example to any system that you may like to develop to run with RESTful web services.  The chapter five of the book is available as a free download, <a href="http://www.dimuthu.org/wp-content/uploads/2008/12/restful-php-webservices_sample-chapter.pdf">RESTful PHP Web Services &#8211; Chapter 5</a>.</p>
<p>The forth and fifth chapters are not using any framework to write the sample codes on consuming and providing web services. But in the sixth chapter it shows the use of <a href="http://framework.zend.com/">Zend framework</a> to do write them. There it rewrites the same example (The RESTful library system) in MVC (Model -View &#8211; Controller) approach using the functionalities of Zend framework. (In fact the View in the service is omitted).</p>
<p>The seventh chapter is about debugging web services. Debugging is a much needed step in any software development cycle. So if you are a newbie, you should read this chapter before start writing any of your own code. This introduces tools and methodologies to make your debugging easy and effective.</p>
<p>The book contains two appendixes. They are too really useful as the chapters of the book. In the first appendix it explains another REST web service framework, <a href="http://wso2.org/projects/wsf/php">WSO2 Web Services Framework for PHP (WSF/PHP)</a>. To demonstrate it uses, some selected functionalities of the example library system (that is mentioned in chapters 4, 5, 6) is re-implemented using WSF/PHP. And it shows you how you can convert this RESTful system to a SOAP system in a minute. The second appendix provides you a code of a class (RESTClient), that you can use in consuming web services very effectively.</p>
<p><strong>Recommended Readers<br />
</strong></p>
<p>This book assume you have some knowledge in PHP. But it doesn&#8217;t require you to know anything related to web services, REST or XML. As you read the first few chapters, you will have a good understanding on the concepts and the basic applications of REST and XML using PHP. And the later chapters will guide to get deeper knowledge in writing complex and real world applications.</p>
<p>If you are a professional developer, you can skip the introduction chapters and jump directly to where you need to refer. For an example, if you use this book as a reference in designing and developing RESTful web service providers, you can directly read the chapter4 &#8211; Resource Oriented Services, chapter6- Resource Oriented Clients and Services with Zend Framework and probably the chapter 7 &#8211; Debugging Web Services.</p>
<p>This book contains the same example system (the library system) written in three different approaches, first without using any framework support, second using the Zend Framework, third using WSF/PHP. Each of them has its own pros and cons. So if you want to determine the approach more suitable to your requirements, or thinking of migrating from one to another, this book will be an ideal resource for you.</p>
<p>As you may have already noticed, this book contains lot of code samples. All the concepts are followed by simple code samples that explain the concept. In appendix it gives you a complete code for RESTClient class that you can use to call any REST service. Apart from the code of the example library system written using different frameworks, it has lot of codes for calling public web service APIs. And the explanation of the code is also done really well.</p>
<p>So it is clear this book is more targetting readers who like to implement PHP RESTful Systems in practice. And it covers enough concepts that you needed to know in writing practicle applications. So this book can take you from the zero knowlege to a deeper knowlege of RESTful PHP Web Services.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2009/01/01/restful-php-web-services-book-review/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Sending Binary with Apache Axis2/C ADB</title>
		<link>http://www.dimuthu.org/blog/2008/11/24/sending-binary-with-apache-axis2c-adb/</link>
		<comments>http://www.dimuthu.org/blog/2008/11/24/sending-binary-with-apache-axis2c-adb/#comments</comments>
		<pubDate>Mon, 24 Nov 2008 18:21:22 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[adb]]></category>
		<category><![CDATA[axis2/c]]></category>
		<category><![CDATA[codegen]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[tool]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[wsdl2c]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[xml schema]]></category>
		<category><![CDATA[base64 binary]]></category>
		<category><![CDATA[binary]]></category>

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

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

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

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

    adb_Person_t *person = adb_Person_create<span style="color: #66cc66;">(</span>env<span style="color: #66cc66;">)</span>;
    adb_Person_set_image<span style="color: #66cc66;">(</span>person, env, base64<span style="color: #66cc66;">)</span>;</pre>
<p>You can set this adb person directly to your request or to a setter of another adb instance to complete the ADB tree. So this way you can send binaries (as base64 encoded) using the Axis2/C ADB generated code.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/11/24/sending-binary-with-apache-axis2c-adb/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Organic Chemistry &#8211; Reaction Simulator</title>
		<link>http://www.dimuthu.org/blog/2008/11/22/organic-chemistry-reaction-simulator/</link>
		<comments>http://www.dimuthu.org/blog/2008/11/22/organic-chemistry-reaction-simulator/#comments</comments>
		<pubDate>Sat, 22 Nov 2008 05:24:24 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[algorithm]]></category>
		<category><![CDATA[Organic Chemistry]]></category>
		<category><![CDATA[personal]]></category>
		<category><![CDATA[screenshots]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[G.C.E. A/L]]></category>
		<category><![CDATA[Reaction Simulator]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=683</guid>
		<description><![CDATA[Organic Reaction Simulator It is a tool that simulates the organic reactions and automatically generate the IUPAC names for the organic compounds drawn by you. This covers most of the syllabus of the Organic Chemistry for G.C.E. A/L examination. Features Nice Canvas to draw your Organic compounds. Generates IUPAC names for the drawn component as [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Organic Reaction Simulator</strong></p>
<p>It is a tool that simulates the organic reactions and automatically generate the IUPAC names for the organic compounds drawn by you. This covers most of the syllabus of the Organic Chemistry for G.C.E. A/L examination.</p>
<p><strong>Features</strong></p>
<ul>
<li> Nice Canvas to draw your Organic compounds.</li>
<li>Generates IUPAC names for the drawn component as possible. (It generates IUPAC names for almost all the compounds which G.C.E A/L examination expect students to know)</li>
<li>You can simulate reaction for organic compounds with preferred inorganic/organic compounds and the selected conditions. (Currently supporting 168 reactions)</li>
<li>Extensibility of adding IUPAC naming rules without the need of recompiling the code.</li>
<li>Extensibility of adding custom reactions, again without compiling a single line of code.</li>
</ul>
<p>Here is a screen shot of the main panel when &#8216;Aldole reaction&#8217; is simulated for some simple reactants.</p>
<div id="attachment_690" class="wp-caption aligncenter" style="width: 510px"><a href="http://www.dimuthu.org/wp-content/uploads/2008/11/aldole.jpg"><img class="size-full wp-image-690" title="Aldole Reaction - Reaction Simulator" src="http://www.dimuthu.org/wp-content/uploads/2008/11/aldole.jpg" alt="Aldole Reaction - Reaction Simulator" width="500" height="392" /></a><p class="wp-caption-text">Aldole Reaction - Reaction Simulator</p></div>
<p><strong>The Drawing Panel</strong></p>
<p>The &#8216;Reaction Simulator&#8217; app provides 2 views for the user. One is the main panel which shows and manages reactions which is shown in the above figure. The other view is the drawing panel. It will be not much different from your favorite drawing application.</p>
<div id="attachment_692" class="wp-caption aligncenter" style="width: 510px"><a href="http://www.dimuthu.org/wp-content/uploads/2008/11/drawing_panel.jpg"><img class="size-full wp-image-692" title="Drawing Panel - Reaction Simulator" src="http://www.dimuthu.org/wp-content/uploads/2008/11/drawing_panel.jpg" alt="Drawing Panel - Reaction Simulator" width="500" height="392" /></a><p class="wp-caption-text">Drawing Panel - Reaction Simulator</p></div>
<p>Here you can select elements and bond types to draw your organic compound. Additionally It has tools to move or delete selected parts of your drawing.</p>
<p>The other thing you may have already noticed, you don&#8217;t need to complete all the bonds for a particular element. Rather if you keep one side of a single bond unconnected, it will be automatically connected to a &#8216;H&#8217;(Hydrogen) at the rendering, similarly for double bond the default connecting element would be &#8216;O&#8217;(Oxygen), and for triple bond it is &#8216;N&#8217; (Nytrogen). And you don&#8217;t even need to bother about connecting bonds with an element, as if you connected only one bond to &#8216;C&#8217; all the other 3 possible bonds will be considered as connected with &#8216;H&#8217;s.</p>
<p>Just check the drawing panel on your own and find its user friendliness. Now after you finish designing your compound, just press &#8220;RETURN&#8221;.</p>
<div id="attachment_694" class="wp-caption aligncenter" style="width: 510px"><a href="http://www.dimuthu.org/wp-content/uploads/2008/11/iupac.jpg"><img class="size-full wp-image-694" title="IUPAC Name Generator - Reaction Simulator" src="http://www.dimuthu.org/wp-content/uploads/2008/11/iupac.jpg" alt="IUPAC Name Generator - Reaction Simulator" width="500" height="392" /></a><p class="wp-caption-text">IUPAC Name Generator - Reaction Simulator</p></div>
<p>Yea it will nicely render our compound, and look at the bottom, it has generated the IUPAC name for the compound.</p>
<p><strong>The Main Panel</strong></p>
<p>This contain a canvas that you can add, edit and delete organic compounds (so you will be directed to the &#8216;Drawing Panel&#8217;), some sidebar panels to select Inorganic compounds and additional conditions requires for the reactions and a set of buttons to start reactions and manage the result set. At the end of the sidebar there is a &#8216;help&#8217; button that directed you to the user guide.</p>
<p><strong>Extending IUPAC Naming Rules</strong></p>
<p>If you go to the &#8220;Data/IUPAC/&#8221; directory (you can view svn from here, <a href="http://svn.dimuthu.org/organic_chemistry/Organic_Reaction_Simulator/Data/IUPAC/">http://svn.dimuthu.org/organic_chemistry/Organic_Reaction_Simulator/Data/IUPAC/</a>) you can find there are set of .txt files (infact xmls) that defines the IUPAC rules.</p>
<p>If you open one of them (we will take al.txt), it would be something like this</p>
<pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;IUPAC</span> <span style="color: #000066;">basename</span>=<span style="color: #ff0000;">"al"</span> <span style="color: #000066;">subname</span>=<span style="color: #ff0000;">"oxo"</span> <span style="color: #000066;">level</span>=<span style="color: #ff0000;">"6"</span> <span style="color: #000066;">nonumber</span>=<span style="color: #ff0000;">"true"</span> <span style="color: #000066;">affectto</span>=<span style="color: #ff0000;">"1"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;bond</span> <span style="color: #000066;">type</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;element</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"7"</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 style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/bond<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;bond</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"1"</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;">type</span>=<span style="color: #ff0000;">"1"</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 style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/bond<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/IUPAC<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>It is the naming rules for aldehyde compounds. (H-C=O). First it identify the the aldehyde by checking double bond to &#8216;O&#8217; (which is the element type &#8217;7&#8242;), and a single bond to &#8216;H&#8217; (which is the element type &#8217;1&#8242;). If the element group found, it will give the name &#8216;al&#8217; or &#8216;oxo&#8217; depending on whether it defines the main group of elements of the compound or not.</p>
<p>If you take a look at all these rules, you can have a good idea what each of these syntax mean. And may be you can add your own rules, if you find something missing or incorrect there.</p>
<p><strong>Extending the Reactions</strong></p>
<p>The reaction rules are stored in the &#8220;Data/Reactions/&#8221; directory ( <a href="http://svn.dimuthu.org/organic_chemistry/Organic_Reaction_Simulator/Data/Reactions/">http://svn.dimuthu.org/organic_chemistry/Organic_Reaction_Simulator/Data/Reactions/</a>).</p>
<p>I will take the first reaction we studied in the &#8216;Organic Chemistry&#8217; Class.</p>
<p>CH4 + Cl2 + hv  (dim light) &#8212;&#8212;&#8212;&#8212;&#8212;-&gt; CCl4 + H2</p>
<p>Here is the rule defining that reaction. (cl2hv.txt)</p>
<pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;reaction</span> <span style="color: #000066;">inorganics</span>=<span style="color: #ff0000;">"Cl2"</span> <span style="color: #000066;">conditions</span>=<span style="color: #ff0000;">"hv"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;check<span style="font-weight: bold; color: black;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;bond</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"1"</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;">type</span>=<span style="color: #ff0000;">"H"</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 style="font-weight: bold; color: black;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/bond<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/check<span style="font-weight: bold; color: black;">&gt;</span></span></span>

	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;reordering</span> <span style="color: #000066;">activity</span>=<span style="color: #ff0000;">"remain"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
		<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;bond</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"1"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
			<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;check<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;">type</span>=<span style="color: #ff0000;">"H"</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 style="font-weight: bold; color: black;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/check<span style="font-weight: bold; color: black;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;reordering</span> <span style="color: #000066;">activity</span>=<span style="color: #ff0000;">"remain"</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;">type</span>=<span style="color: #ff0000;">"H"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
					<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;reordering</span> <span style="color: #000066;">activity</span>=<span style="color: #ff0000;">"replace"</span> <span style="color: #000066;">to</span>=<span style="color: #ff0000;">"Cl"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
					<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/reordering<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;/reordering<span style="font-weight: bold; color: black;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/bond<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/reordering<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/reaction<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>If you take a close look at, what it says is if there exist inorganic &#8216;Cl2&#8242; and condition &#8216;hv&#8217; (reactions inorganics=&#8221;Cl2&#8243; conditions=&#8221;hv&#8221;), check for a &#8216;H&#8217; (element type=&#8221;H&#8221;) elements that is connected to a &#8216;C&#8217; element (which is the root of the XML) through a single bond (bond type=&#8221;1&#8243;), then don&#8217;t replace the &#8216;C&#8217; (reordering activity=&#8221;remain&#8221;) and don&#8217;t replace the bond type (reordering activity=&#8221;remain&#8221;), just replace the &#8216;H&#8217; with &#8216;Cl&#8217; (reordering activity=&#8221;replace&#8221; to=&#8221;Cl&#8221;). It is so simple as that.</p>
<p>These rules are applied to all the C elements in reactants. Look at the following figure for this rule in application.</p>
<div id="attachment_698" class="wp-caption aligncenter" style="width: 510px"><a href="http://www.dimuthu.org/wp-content/uploads/2008/11/cl2hv.jpg"><img class="size-full wp-image-698" title="Alkane + Cl2 Reaction - Reaction Simulator" src="http://www.dimuthu.org/wp-content/uploads/2008/11/cl2hv.jpg" alt="Alkane + Cl2 Reaction - Reaction Simulator" width="500" height="392" /></a><p class="wp-caption-text">Alkane + Cl2 Reaction - Reaction Simulator</p></div>
<p>These reaction rules can be as complex as you want. Specially when two or more reactants are involved in a reaction, rules defining that reaction will be little complex. Look at how aldole reaction (which is applied in the first figure of this post) is written in <a href="http://svn.dimuthu.org/organic_chemistry/Organic_Reaction_Simulator/Data/Reactions/aldole.txt">aldole.txt</a>.</p>
<p>There are all together 168 reactions currently defined in this way. If you found some reaction is missing, feel free to add a another rule file defining that reaction. And if you want to share that with others, just let me know <img src='http://www.dimuthu.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> , so I can integrate it in to the distribution.</p>
<p><strong>Download</strong></p>
<p>This software application is not yet in a official release. I just thought use this post to do a pre release of the &#8216;Reaction Simulator&#8217;. You can download the windows binary of the pre release version (343KB) from <a href="http://downloads.dimuthu.org/bins/chemistry/reaction_simulator_pre_release/reaction_simulator_pre_release.zip">http://downloads.dimuthu.org/bins/chemistry/reaction_simulator_pre_release/reaction_simulator_pre_release.zip</a></p>
<p><strong>Source Code</strong></p>
<p>SVN location for the source code of &#8216;Reaction Simulator&#8217; is <a href="http://svn.dimuthu.org/organic_chemistry/Organic_Reaction_Simulator/">http://svn.dimuthu.org/organic_chemistry/Organic_Reaction_Simulator/</a></p>
<p><strong>Known Limitations &#8211; Possible Improvements<br />
</strong></p>
<ul>
<li>Generation of IUPAC names and simulations of reactions are not supported for compounds which involves Benzene ring.</li>
<li>IUPAC names generation is not supported for cyclic compounds which are anyway not part of the G.C.E. A/L syllabus.</li>
<li>The set of elements, available in drawing compounds, set of inorganic compounds and conditions, available in reactions are fixed and cannot be extended without changing the code and recompiling.</li>
<li>You can&#8217;t start with an IUPAC name and derive the compound. Currently you always have to start with drawing the compound and then generate the IUPAC.</li>
<li>Only for windows!</li>
</ul>
<p><strong>Little Background</strong></p>
<p>4 years ago, When I was a level 2 student in the <a href="http://www.mrt.ac.lk/">University of Moratuwa</a>, I participated to a competition for making educational software tools organized by <a href="http://www.cse.mrt.ac.lk/">C.S.E</a> and <a href="http://www.nie.lk/">N.I.E (National Institute of Education)</a>. I submitted a software that teaches Organic Chemistry. It consisted of interactive tutorials targeting local G.C.E A/L exams with exercises and revisions in both Sinhala(My Mother tongue) and English languages(not in Unicode though). I got the second price for that.</p>
<p>After the award I decided to improve my software application by adding an &#8216;Organic Reaction Simulator&#8217;. In fact in the vacation of 2 weeks for the New Year, I could complete it.</p>
<p>Although the N.I.E supposed to distribute the applications submitted to the competition throughout the country, it didn&#8217;t happened. So I decided to publish at least the &#8216;Reaction Simulator&#8217; application which I actually didn&#8217;t submitted to the competition.</p>
<p><strong>Technologies Used</strong></p>
<p>This is completely written in C++. It hasn&#8217;t use MFC, because I thought MFC is too heavy for such a small application. I used a lightweight, small image library code taken with some custom changes from some windows game programming book.</p>
<p>This is using XML to load data about reactions and IUPAC names which I have described in details in the early part of the blog. It uses a small inbuilt xml parser (just one recursive function) to parse these xmls.</p>
<p>So it has no depenedencies to third party libraries, You can just chekcout the <a href="http://svn.dimuthu.org/organic_chemistry/Organic_Reaction_Simulator/">souce code from the svn</a>, open the visual studio project and compile it (press &#8216;F7&#8242;).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/11/22/organic-chemistry-reaction-simulator/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>WS-SecurityPolicy With PHP</title>
		<link>http://www.dimuthu.org/blog/2008/11/19/ws-securitypolicy-with-php/</link>
		<comments>http://www.dimuthu.org/blog/2008/11/19/ws-securitypolicy-with-php/#comments</comments>
		<pubDate>Wed, 19 Nov 2008 16:20:43 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[DataServices]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[WSDL]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[xml schema]]></category>
		<category><![CDATA[policy]]></category>
		<category><![CDATA[ws-policy]]></category>
		<category><![CDATA[ws-security]]></category>
		<category><![CDATA[ws-security policy]]></category>

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

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

<span style="color: #0000ff;">$svr</span> = <span style="font-weight: bold; color: #000000;">new</span> WSService<span style="color: #66cc66;">(</span><a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"actions"</span> =&gt; <span style="color: #0000ff;">$actions</span>,
 <span style="color: #ff0000;">"operations"</span> =&gt; <span style="color: #0000ff;">$operations</span>,
 <span style="color: #ff0000;">"policy"</span> =&gt; <span style="color: #0000ff;">$policy</span>,
 <span style="color: #ff0000;">"securityToken"</span> =&gt; <span style="color: #0000ff;">$sec_token</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>; <span style="font-style: italic; color: #808080;">// here is the policy object you just created</span><span style="color: #0000ff;">

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

 <span style="color: #0000ff;">$client</span> = <span style="font-weight: bold; color: #000000;">new</span> WSClient<span style="color: #66cc66;">(</span><a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"useWSA"</span> =&gt; <span style="font-weight: bold; color: #000000;">TRUE</span>,
    <span style="color: #ff0000;">"policy"</span> =&gt; <span style="color: #0000ff;">$policy</span>, <span style="font-style: italic; color: #808080;">/* the policy object */</span>
    <span style="color: #ff0000;">"securityToken"</span> =&gt; <span style="color: #0000ff;">$sec_token</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;

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

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

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

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

<span style="color: #009900;"><span style="font-style: italic; color: #808080;">&lt;!-- example element to have the above faceted value --&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"subject"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"tns:mySubject"</span><span style="font-weight: bold; color: black;">/&gt;</span></span></pre>
<p>And here is the WSDL2PHP generated code,</p>
<pre class="php">    <span style="font-style: italic; color: #808080;">/**
     * @var string
     *     NOTE: subject should follow the following restrictions
     *     You can have one of the following value
     *     Maths
     *     Physics
     *     Chemistry
     */</span>
    <span style="font-weight: bold; color: #000000;">public</span> <span style="color: #0000ff;">$subject</span>;</pre>
<p>It clearly says your variable &#8216;subject&#8217; is only allowed to have the list of values mentioned in the &#8216;enumeration&#8217;.</p>
<p>So I just wrote about some variations of simple schema types and how they are represented in the WSDL2PHP generated code. As you may have observed, you don&#8217;t need to know any thing about the WSDL or the schema to write a PHP code around that, since WSDL2PHP gives you a generated code mentioning all the guidelines, restrictions about using them.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/11/13/xml-schema-simple-types-how-wsdl2php-convert-them-to-php/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>WSF/PHP WSDL Mode &#8211; Handling XML Schema Arrays</title>
		<link>http://www.dimuthu.org/blog/2008/10/25/wsfphp-wsdl-mode-handling-xml-schema-arrays/</link>
		<comments>http://www.dimuthu.org/blog/2008/10/25/wsfphp-wsdl-mode-handling-xml-schema-arrays/#comments</comments>
		<pubDate>Sat, 25 Oct 2008 15:20:40 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[WSDL]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[xml schema]]></category>
		<category><![CDATA[arrays]]></category>
		<category><![CDATA[maxOccurs]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[wsdl mode]]></category>
		<category><![CDATA[wsdl2php]]></category>

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

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

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

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

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

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

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

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

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

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

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

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

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

<span style="font-style: italic; color: #808080;">/* The Service operation name to PHP function name map */</span>
<span style="color: #0000ff;">$operations</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"echo"</span> =&gt; <span style="color: #ff0000;">"echoMe"</span><span style="color: #66cc66;">)</span>;

<span style="font-style: italic; color: #808080;">/* Telling that we input MIX types for the parameters */</span>
<span style="color: #0000ff;">$opParams</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"echo"</span> =&gt; <span style="color: #ff0000;">"MIXED"</span><span style="color: #66cc66;">)</span>;

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

<span style="font-style: italic; color: #808080;">/* Creating the WSService and serving the Request */</span>
<span style="color: #0000ff;">$service</span> = <span style="font-weight: bold; color: #000000;">new</span> WSService<span style="color: #66cc66;">(</span><a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span>
			<span style="color: #ff0000;">"operations"</span> =&gt; <span style="color: #0000ff;">$operations</span>,
			<span style="color: #ff0000;">"classmap"</span> =&gt; <span style="color: #0000ff;">$classmap</span>,
			<span style="color: #ff0000;">"opParams"</span> =&gt; <span style="color: #0000ff;">$opParams</span>,
			<span style="color: #ff0000;">"serviceName"</span> =&gt; <span style="color: #ff0000;">"myEcho"</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;

<span style="color: #0000ff;">$service</span>-&gt;<span style="color: #006600;">reply</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;

<span style="font-weight: bold; color: #000000;">?&gt;</span></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/10/23/wsdl-generation-from-php-using-different-names-in-wsdl-and-php-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

