<?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; mtom</title>
	<atom:link href="http://www.dimuthu.org/tag/mtom/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>Sending Encrypted Binary Messages With PHP Web Services</title>
		<link>http://www.dimuthu.org/blog/2008/12/14/sending-encrypted-binary-messages-with-php-web-services/</link>
		<comments>http://www.dimuthu.org/blog/2008/12/14/sending-encrypted-binary-messages-with-php-web-services/#comments</comments>
		<pubDate>Sun, 14 Dec 2008 17:51:04 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[Attachment]]></category>
		<category><![CDATA[base64]]></category>
		<category><![CDATA[encryption]]></category>
		<category><![CDATA[MIME]]></category>
		<category><![CDATA[mtom]]></category>
		<category><![CDATA[policy]]></category>
		<category><![CDATA[secuirty token]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=797</guid>
		<description><![CDATA[Web services has made the communication between heterogeneous environments (say PHP with .NET  or Java) a reality. It has defines standards for communicate not only with texts but also with binaries. And more importantly you can keep these communication confidential using encrypted messages according to your requirement. In this post, we will look at how [...]]]></description>
			<content:encoded><![CDATA[<p>Web services has made the communication between heterogeneous environments (say PHP with .NET  or Java) a reality. It has defines standards for communicate not only with texts but also with binaries. And more importantly you can keep these communication confidential using encrypted messages according to your requirement. In this post, we will look at how we can implement such a system with PHP in one side.</p>
<p>In web services we can send/receive binary messages in two basic forms.</p>
<ol>
<li>Setting the binary inside the SOAP message. &#8211; Binary should be converted to base64 to make sure the SOAP body contains only texts. Since base64 converted data span longer than the binary data, we call this form as non-optimized way of sending binaries.</li>
<li>Setting the binary outside the SOAP message &#8211; Binary would be sent as a MIME part in the message. And some element inside SOAP body keeps a reference to the binary using the MIME id. MTOM is a standard for referencing the MIME from inside the SOAP body. Since the binary is encoded, this will keep the message optimum with the binaries.</li>
</ol>
<p>In <a href="http://wso2.org/projects/wsf/php">WSF/PHP</a> you can use any of these methods as you prefer. Lets forget about the encryption for now. We will check how we can send binaries in both of the above mentioned forms.</p>
<pre class="php"><span style="font-style: italic; color: #808080;">// first the request xml. Note tht xop:Include element that is referring the attachment with the id "myid1".</span>
<span style="color: #0000ff;">$reqPayloadString</span> = &lt;&lt;&lt;XML
&lt;ns1:upload xmlns:ns1=<span style="color: #ff0000;">"http://wso2.org/wsfphp/samples/mtom"</span>&gt;
               &lt;ns1:fileName&gt;test.jpg&lt;/ns1:fileName&gt;
               &lt;ns1:image xmlmime:contentType=<span style="color: #ff0000;">"image/jpeg"</span> xmlns:xmlmime=<span style="color: #ff0000;">"http://www.w3.org/2004/06/xmlmime"</span>&gt;
                  &lt;xop:<span style="color: #b1b100;">Include</span> xmlns:xop=<span style="color: #ff0000;">"http://www.w3.org/2004/08/xop/include"</span> href=<span style="color: #ff0000;">"cid:myid1"</span>&gt;&lt;/xop:Include&gt;
               &lt;/ns1:image&gt;
&lt;/ns1:upload&gt;
XML;

try <span style="color: #66cc66;">{</span>
    <span style="color: #0000ff;">$f</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;">"my_binary_file.jpg"</span><span style="color: #66cc66;">)</span>;

    <span style="font-style: italic; color: #808080;">// here in the attachments option we define the binaries</span>
    <span style="font-style: italic; color: #808080;">// corresponding to the id defined in the above XML</span>
    <span style="color: #0000ff;">$reqMessage</span> = <span style="font-weight: bold; color: #000000;">new</span> WSMessage<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$reqPayloadString</span>,
                                <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"to"</span> =&gt; <span style="color: #ff0000;">"http://localhost/simple_upload_service.php"</span>,
                                      <span style="color: #ff0000;">"action"</span> =&gt; <span style="color: #ff0000;">"http://wso2.org/upload"</span>,
                                      <span style="color: #ff0000;">"attachments"</span> =&gt; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"myid1"</span> =&gt; <span style="color: #0000ff;">$f</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;

    <span style="font-style: italic; color: #808080;">// creating the WSClient</span>
    <span style="font-style: italic; color: #808080;">// here the option useMTOM will decide whether the</span>
    <span style="font-style: italic; color: #808080;">// attachment is set MTOM or base64</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;">"useMTOM"</span> =&gt; <span style="font-weight: bold; color: #000000;">TRUE</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;

    <span style="font-style: italic; color: #808080;">// sending the message and retrieving the response</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>;

    <a href="http://www.php.net/printf"><span style="color: #000066;">printf</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"Response = %s <span style="font-weight: bold; color: #000099;">\\</span>n"</span>, <span style="color: #0000ff;">$resMessage</span>-&gt;<span style="color: #006600;">str</span><span style="color: #66cc66;">)</span>;

<span style="color: #66cc66;">}</span> catch <span style="color: #66cc66;">(</span>Exception <span style="color: #0000ff;">$e</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>

    <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span><span style="color: #0000ff;">$e</span> instanceof WSFault<span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>
        <a href="http://www.php.net/printf"><span style="color: #000066;">printf</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"Soap Fault: %s<span style="font-weight: bold; color: #000099;">\\</span>n"</span>, <span style="color: #0000ff;">$e</span>-&gt;<span style="color: #006600;">Reason</span><span style="color: #66cc66;">)</span>;
    <span style="color: #66cc66;">}</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">{</span>
        <a href="http://www.php.net/printf"><span style="color: #000066;">printf</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"Message = %s<span style="font-weight: bold; color: #000099;">\\</span>n"</span>,<span style="color: #0000ff;">$e</span>-&gt;<span style="color: #006600;">getMessage</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;
    <span style="color: #66cc66;">}</span>
<span style="color: #66cc66;">}</span></pre>
<p>As mentioned in the inline comment we can choose the preferred form of sending binary using the &#8220;useMTOM&#8221; option. if it is true, the binary is set as a MTOM, (referencing from the body) or if it is set false, the binary will be set as a base64 binary within the SOAP body.<br />
To encrypt the message you only need to write few additional lines. First you define your policy that you need to encrypt this message using a WSPolicy object. Then the security token including the service public key and your private key. You need to give these two option as a constructor argument in WSClient. Here is that little additional code you need to write to add the encryption.</p>
<pre class="php">    <span style="font-style: italic; color: #808080;">// loading the keys</span>
    <span style="color: #0000ff;">$rec_cert</span> = ws_get_cert_from_file<span style="color: #66cc66;">(</span><span style="color: #ff0000;">"receiving_server.cert"</span><span style="color: #66cc66;">)</span>;
    <span style="color: #0000ff;">$pvt_key</span> = ws_get_key_from_file<span style="color: #66cc66;">(</span><span style="color: #ff0000;">"my_private_key.pem"</span><span style="color: #66cc66;">)</span>;

    <span style="font-style: italic; color: #808080;">// here we defines the policies and create WSPolicy object</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="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>;

    <span style="font-style: italic; color: #808080;">// defining Security Tokens</span>
    <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="font-style: italic; color: #808080;">// modifing WSClient with adding WSPolicy and WSSecurityToken object</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;">"useMTOM"</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="color: #ff0000;">"securityToken"</span> =&gt; <span style="color: #0000ff;">$sec_token</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;</pre>
<p>You can implement the receiving side of the message similar to the sending side that we just described above. The most important thing is it doesn&#8217;t need to be written in PHP. It can be a Java code or .NET code.If you already have web services that use encrypted binary messaging, the above php code can be use out of the box to communicate with it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/12/14/sending-encrypted-binary-messages-with-php-web-services/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>WSF/PHP Test Cases Explained</title>
		<link>http://www.dimuthu.org/blog/2008/11/11/wsfphp-test-cases-explained/</link>
		<comments>http://www.dimuthu.org/blog/2008/11/11/wsfphp-test-cases-explained/#comments</comments>
		<pubDate>Tue, 11 Nov 2008 19:27:10 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[WSDL]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[xml schema]]></category>
		<category><![CDATA[basic]]></category>
		<category><![CDATA[mtom]]></category>
		<category><![CDATA[phpt]]></category>
		<category><![CDATA[reliable messaging]]></category>
		<category><![CDATA[rm]]></category>
		<category><![CDATA[schema]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[test-suit]]></category>
		<category><![CDATA[tests]]></category>
		<category><![CDATA[wsdl generation]]></category>
		<category><![CDATA[wsdl mode]]></category>

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

		<guid isPermaLink="false">http://www.dimuthu.org/?p=589</guid>
		<description><![CDATA[Here is a simple categorization of the WSF/PHP samples. You can access all the wsf/php samples from http://labs.wso2.org/wsf/php/solutions/samples/index.html. Sample Category Example Client Source Code Example Service Source Code Online Demo Beginners echo_client.php echo_service.php Demo REST echo_client_rest.php echo_service_with_rest.php Demo WSDL Mode (Contract First) wsdl_11_client.php wsdl_11_service.php Demo WSDL Generation (Code First) doclit_client.php doclit_service.php Demo MTOM Attachments mtom_download_client.php [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a simple categorization of the <a href="http://wso2.org/projects/wsf/php">WSF/PHP </a>samples. You can access all the wsf/php samples from <a href="http://labs.wso2.org/wsf/php/solutions/samples/index.html">http://labs.wso2.org/wsf/php/solutions/samples/index.html</a>.</p>
<table border="1">
<tbody>
<tr style="background:#dddddd">
<td>Sample Category</td>
<td>Example Client Source Code</td>
<td>Example Service Source Code</td>
<td>Online Demo</td>
</tr>
<tr>
<td>Beginners</td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2Fecho_client.php">echo_client.php</a></td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2Fecho_service.php">echo_service.php</a></td>
<td><a href="http://labs.wso2.org/wsf/php/solutions/samples/echo_client.php">Demo</a></td>
</tr>
<tr>
<td>REST</td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2Fecho_client_rest.php">echo_client_rest.php</a></td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2Fecho_service_with_rest.php">echo_service_with_rest.php</a></td>
<td><a href="http://labs.wso2.org/wsf/php/solutions/samples/echo_client_rest.php">Demo</a></td>
</tr>
<tr>
<td>WSDL Mode (Contract First)</td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2Fwsdl_mode%2Fwsdl_11_client.php">wsdl_11_client.php</a></td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2Fwsdl_mode%2Fwsdl_11_service.php">wsdl_11_service.php</a></td>
<td><a href="http://labs.wso2.org/wsf/php/solutions/samples/wsdl_mode/wsdl_11_client.php">Demo</a></td>
</tr>
<tr>
<td>WSDL Generation (Code First)</td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2Fwsdl_generation%2Fdoclit_client.php">doclit_client.php</a></td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2Fwsdl_generation%2Fdoclit_service.php">doclit_service.php</a></td>
<td><a href="http://labs.wso2.org/wsf/php/solutions/samples/wsdl_generation/doclit_client.php">Demo</a></td>
</tr>
<tr>
<td>MTOM Attachments</td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2Fmtom%2Fmtom_download_client.php">mtom_download_client.php</a></td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2Fmtom%2Fmtom_download_service.php">mtom_download_service.php</a></td>
<td><a href="http://labs.wso2.org/wsf/php/solutions/samples/mtom/mtom_download_client.php">Demo</a></td>
</tr>
<tr>
<td>Security</td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2Fsecurity%2Fencryption%2Fclient.php">encryption_client.php</a></td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2Fsecurity%2Fencryption%2Fservice.php">encryption_service.php</a></td>
<td><a href="http://labs.wso2.org/wsf/php/solutions/samples/security/encryption/client.php">Demo</a></td>
</tr>
<tr>
<td>Reliable Messaging</td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2Freliable%2Fecho_client_rm.php">echo_client_rm.php</a></td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2Freliable%2Fecho_service_rm.php">echo_service_rm.php</a></td>
<td><a href="http://labs.wso2.org/wsf/php/solutions/samples/reliable/echo_client_rm.php">Demo</a></td>
</tr>
<tr>
<td>Data Services</td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2FDataServices%2FCustomerDetailsClient.php">CustomerDetailsClient.php</a><a></a></td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2FDataServices%2FCustomerDetailsService.php">CustomerDetailsService.php</a><a></a></td>
<td><a href="http://labs.wso2.org/wsf/php/solutions/samples/DataServices/CustomerDetailsClient.php">Demo</a></td>
</tr>
</tbody>
</table>
<p>If you have downloaded the  <a href="http://wso2.org/projects/wsf/php">WSF/PHP binaries or souce code</a> package you can find all these samples, inside the &#8216;samples&#8217; directory</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/11/07/wsfphp-samples-explained/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Send Binary With Web Services in PHP &#8211; 2 Minutes Introduction</title>
		<link>http://www.dimuthu.org/blog/2008/09/22/send-binary-with-web-services-in-php-2-minutes-introduction/</link>
		<comments>http://www.dimuthu.org/blog/2008/09/22/send-binary-with-web-services-in-php-2-minutes-introduction/#comments</comments>
		<pubDate>Mon, 22 Sep 2008 17:14:53 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[2 minutes guide]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[WSDL]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[xml schema]]></category>
		<category><![CDATA[2 minutes]]></category>
		<category><![CDATA[base64]]></category>
		<category><![CDATA[binary]]></category>
		<category><![CDATA[mtom]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[SWA]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=358</guid>
		<description><![CDATA[In PHP you have several ways of sending binary data. It can be primarily categorized in to non-optimized method (send as base64 binary) and optimized method (send as MTOM or SWA). Here I m talking about how to send binaries in above mentioned methods starting from a WSDL. WSDL Think you have a WSDL with [...]]]></description>
			<content:encoded><![CDATA[<p>In PHP you have several ways of sending binary data. It can be primarily categorized in to non-optimized method (send as base64 binary) and optimized method (send as MTOM or SWA). Here I m talking about how to send binaries in above mentioned methods starting from a WSDL.</p>
<p><strong>WSDL</strong></p>
<p>Think you have a WSDL with the following XML Schema.</p>
<pre class="xml">            <span style="color: #009900;"><span style="font-style: italic; color: #808080;">&lt;!-- Here is my submitPerson method-&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;">"submitPerson"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
                <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:complexType<span style="font-weight: bold; color: black;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="font-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;">"name"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"xs:string"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
                        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"age"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"xs:int"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
                        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"photo"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"xs:base64Binary"</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">/&gt;</span></span>
<span style="color: #009900;">                    <span style="font-weight: bold; color: black;">&lt;/xs:sequence<span style="font-weight: bold; color: black;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xs:complexType<span style="font-weight: bold; color: black;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xs:element<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>The submit Person method submit the name,age and a photo which is a type of base64Binary.</p>
<p><strong>Generated Class</strong></p>
<p>After generating php class for this piece of code using <a href="http://labs.wso2.org/wsf/php/wsdl2phptool.php">wsdl2php</a> you will have  the following class.</p>
<pre class="php"><span style="font-weight: bold; color: #000000;">class</span> submitPerson <span style="color: #66cc66;">{</span>

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

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

    <span style="font-style: italic; color: #808080;">// You need to set only one from the following two vars</span>

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

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

<span style="color: #66cc66;">}</span></pre>
<p>So it is very easy to fill the class with your own data. Note that you only need to fill one of the &#8216;photo&#8217; or &#8216;photo_encoded&#8217; fields. If you have binary already converted to base64 then you can use the &#8216;photo_encoded&#8217; field where as if you only have the row binary just use the &#8216;photo&#8217; field. Here are my values for this particular example.</p>
<pre class="php"><span style="color: #0000ff;">$person</span> = <span style="font-weight: bold; color: #000000;">new</span> submitPerson<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;
<span style="color: #0000ff;">$person</span>-&gt;<span style="color: #006600;">name</span> = <span style="color: #ff0000;">"xxxx yyy"</span>;
<span style="color: #0000ff;">$person</span>-&gt;<span style="color: #006600;">age</span> = <span style="color: #cc66cc;">35</span>;
<span style="color: #0000ff;">$person</span>-&gt;<span style="color: #006600;">photo</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;">"/photo/xxxyyy"</span><span style="color: #66cc66;">)</span>;</pre>
<p><strong>Sending Binary as MTOM</strong></p>
<p>Here is the code you need to send the above structure as a MTOM message.</p>
<pre class="php"><span style="color: #0000ff;">$client</span> = <span style="font-weight: bold; color: #000000;">new</span> WSClient<span style="color: #66cc66;">(</span><a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"useMTOM"</span> =&gt; <span style="font-weight: bold; color: #000000;">TRUE</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>; <span style="font-style: italic; color: #808080;">// anyway useMTOM is default to TRUE for WSClient</span>
<span style="color: #0000ff;">$proxy</span> = <span style="color: #0000ff;">$client</span>-&gt;<span style="color: #006600;">getProxy</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;

<span style="color: #0000ff;">$response</span> = <span style="color: #0000ff;">$proxy</span>-&gt;<span style="color: #006600;">submitPerson</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$person</span><span style="color: #66cc66;">)</span>;</pre>
<p><strong>Sending Binary as Base64 Encoded string<br />
</strong></p>
<p>You only need to change one option. That is setting &#8220;useMTOM&#8221; to FALSE will send the binary as Base64.</p>
<pre class="php"><span style="color: #0000ff;">$client</span> = <span style="font-weight: bold; color: #000000;">new</span> WSClient<span style="color: #66cc66;">(</span><a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"useMTOM"</span> =&gt; <span style="font-weight: bold; color: #000000;">FALSE</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;
<span style="color: #0000ff;">$proxy</span> = <span style="color: #0000ff;">$client</span>-&gt;<span style="color: #006600;">getProxy</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;

<span style="color: #0000ff;">$response</span> = <span style="color: #0000ff;">$proxy</span>-&gt;<span style="color: #006600;">submitPerson</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$person</span><span style="color: #66cc66;">)</span>;</pre>
<p><strong>SWA (SOAP With Attachments) </strong><br />
You can send the binary data as SWA by setting the &#8220;useMTOM&#8221; option to &#8220;SWA&#8221;. SWA is also a binary optimized method of sending attachments, but unlike with MTOM you can&#8217;t integrate security or reliability with this approach.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/09/22/send-binary-with-web-services-in-php-2-minutes-introduction/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Send Binary in SOAP with WSF/PHP 1.3.2</title>
		<link>http://www.dimuthu.org/blog/2008/08/19/send-binary-in-soap-with-wsfphp-132/</link>
		<comments>http://www.dimuthu.org/blog/2008/08/19/send-binary-in-soap-with-wsfphp-132/#comments</comments>
		<pubDate>Tue, 19 Aug 2008 02:57:17 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[web services]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[base64]]></category>
		<category><![CDATA[binary]]></category>
		<category><![CDATA[mtom]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=195</guid>
		<description><![CDATA[In a valid XML you can only have text and you can not have binary characters. SOAP which in fact an XML is also having this issue. So it is not staright forward to send binary data in SOAP. But with WSO2 WSF/PHP 1.3.2 It is really easy to send binaries. Check the online WSF/PHP [...]]]></description>
			<content:encoded><![CDATA[<p>In a valid XML you can only have text and you can not have binary characters. SOAP which in fact an XML is also having this issue. So it is not staright forward to send binary data in SOAP. But with <a title="WSO2, WSF/PHP" href="http://wso2.org/projects/wsf/php">WSO2 WSF/PHP 1.3.2 </a>It is really easy to send binaries. Check the <a href="http://labs.wso2.org/wsf/php/source_page_frame.php?src=samples/mtom">online WSF/PHP Mtom Sample sources</a> to understand the few lines that needed to send and serve binaries.</p>
<p>To understand what is happening inside WSF/PHP to send your message we will first take a simple demo. To understand the messages I will be sending text data rather than binary so you can clearly see how your data goes through the wire.</p>
<p>Here is my code to send the binary. (in fact a test in this percular case)</p>
<pre><span style="font-weight: bold; color: #000000;">&lt;?php</span>
<span style="color: #0000ff;">$requestPayloadString</span> = &lt;&lt;&lt;XML
&lt;ns1:upload xmlns:ns1=<span style="color: #ff0000;">"http://php.axis2.org/samples/mtom"</span>&gt;
  &lt;ns1:fileName&gt;test.txt&lt;/ns1:fileName&gt;
  &lt;ns1:image xmlmime:contentType=<span style="color: #ff0000;">"text/txt"</span> xmlns:xmlmime=<span style="color: #ff0000;">"http://www.w3.org/2004/06/xmlmime"</span>&gt;

    &lt;xop:<span style="color: #b1b100;">Include</span> xmlns:xop=<span style="color: #ff0000;">"http://www.w3.org/2004/08/xop/include"</span> href=<span style="color: #ff0000;">"cid:myid1"</span>&gt;&lt;/xop:Include&gt;
  &lt;/ns1:image&gt;
&lt;/ns1:upload&gt;
XML;

try <span style="color: #66cc66;">{</span>
    <span style="color: #0000ff;">$f</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;">"test.txt"</span><span style="color: #66cc66;">)</span>;

    <span style="color: #0000ff;">$requestMessage</span> = <span style="font-weight: bold; color: #000000;">new</span> WSMessage<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$requestPayloadString</span>,
        <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"to"</span> =&gt; <span style="color: #ff0000;">"http://localhost/my_mtom_service.php"</span>,
        <span style="color: #ff0000;">"attachments"</span> =&gt; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"myid1"</span> =&gt; <span style="color: #0000ff;">$f</span><span style="color: #66cc66;">)</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;">"useMTOM"</span> =&gt; <span style="color: #ff0000;">"FALSE"</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;

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

    <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #0000ff;">$responseMessage</span>-&gt;<span style="color: #006600;">str</span>;

<span style="color: #66cc66;">}</span> catch <span style="color: #66cc66;">(</span>Exception <span style="color: #0000ff;">$e</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>
    <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span><span style="color: #0000ff;">$e</span> instanceof WSFault<span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>

        <a href="http://www.php.net/printf"><span style="color: #000066;">printf</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"Soap Fault: %s<span style="font-weight: bold; color: #000099;">\\</span>n"</span>, <span style="color: #0000ff;">$e</span>-&gt;<span style="color: #006600;">Reason</span><span style="color: #66cc66;">)</span>;
    <span style="color: #66cc66;">}</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">{</span>

        <a href="http://www.php.net/printf"><span style="color: #000066;">printf</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"Message = %s<span style="font-weight: bold; color: #000099;">\\</span>n"</span>,<span style="color: #0000ff;">$e</span>-&gt;<span style="color: #006600;">getMessage</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;
    <span style="color: #66cc66;">}</span>
<span style="color: #66cc66;">}</span>

<span style="font-weight: bold; color: #000000;">?&gt;</span></pre>
<p>And test.txt has the following text</p>
<pre>TEXT as BINARY</pre>
<p>In here the &#8216;xop:include&#8217; element is where you going to send either the binary data or some reference to binary data.<br />
<strong>&#8220;useMTOM&#8221; =&gt; FALSE</strong><br />
Note that in there in the &#8220;useMTOM&#8221; option for the WSClient I have given the value FALSE. That mean don&#8217;t use the MTOM(<span>Message Transmission Optimization Mechanism) to serialize the message.There the generated soap message (over HTTP) will look like this,</span></p>
<pre>POST /samples/mtom/mtom_upload_service.php HTTP/1.1
User-Agent: Axis2C/1.5.0
Content-Length: 404
Content-Type: application/soap+xml;charset=UTF-8
Host: 127.0.0.1:8080

<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;soapenv:Envelope</span> <span style="color: #000066;">xmlns:soapenv</span>=<span style="color: #ff0000;">"http://www.w3.org/2003/05/soap-envelope"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
   <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;soapenv:Header</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
   <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;soapenv:Body<span style="font-weight: bold; color: black;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ns1:upload</span> xmlns:ns1=<span style="color: #ff0000;">"http://php.axis2.org/samples/mtom"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
         <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ns1:fileName<span style="font-weight: bold; color: black;">&gt;</span></span></span>test.jpg<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/ns1:fileName<span style="font-weight: bold; color: black;">&gt;</span></span></span>
         <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ns1:image</span> <span style="color: #000066;">xmlmime:contentType</span>=<span style="color: #ff0000;">"text/txt"</span> <span style="color: #000066;">xmlns:xmlmime</span>=<span style="color: #ff0000;">"http://www.w3.org/2004/06/xmlmime"</span><span style="font-weight: bold; color: black;">&gt;</span></span>VEVYVCBhcyBCSU5BUlkK<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/ns1:image<span style="font-weight: bold; color: black;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/ns1:upload<span style="font-weight: bold; color: black;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/soapenv:Body<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/soapenv:Envelope<span style="font-weight: bold; color: black;">&gt;</span>
</span></span></pre>
<p>The value &#8220;<strong>VEVYVCBhcyBCSU5BUlkK</strong>&#8221; is base64 encoded value for the &#8220;TEXT as BINARY&#8221; text.</p>
<pre><span style="font-weight: bold; color: #000000;">&lt;?php</span>
<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <a href="http://www.php.net/base64_encode"><span style="color: #000066;">base64_encode</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"TEXT as BINARY"</span><span style="color: #66cc66;">)</span>;
<span style="font-weight: bold; color: #000000;">?&gt;</span></pre>
<p>In fact it is a standard that map each 6 bit of your binary file to an 8 bit (valid character to send through XML), so you can send the encoded value in the soap message. But no doubt you see the drawback. The encoded value is 4/3rd of the original data size. So this is not the most optimized way to send binary over SOAP.<br />
<strong>&#8220;useMTOM&#8221; =&gt; TRUE</strong><br />
Setting this option TRUE will generate the following soap message over http.</p>
<pre>POST /samples/mtom/mtom_upload_service.php HTTP/1.1
User-Agent: Axis2C/1.5.0
Transfer-Encoding: chunked
Content-Type: multipart/related; boundary=MIMEBoundary594038a6-6d95-1dd1-2b72-00197e732d4d; type="application/xop+xml"; start="<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;<span style="color: #cc66cc;">0</span></span>.594038e2-6d95-1dd1-2b73-00197e732d4d@apache.org<span style="font-weight: bold; color: black;">&gt;</span></span>"; start-info="application/soap+xml"; charset="UTF-8"
Host: 127.0.0.1:8080

32
--MIMEBoundary594038a6-6d95-1dd1-2b72-00197e732d4d
2

b2
content-transfer-encoding: binary
content-id: <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;<span style="color: #cc66cc;">0</span></span>.594038e2-6d95-1dd1-2b73-00197e732d4d@apache.org<span style="font-weight: bold; color: black;">&gt;</span></span>content-type: application/xop+xml;charset=UTF-8;type="application/soap+xml";21ff
   <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;soapenv:Envelope</span> <span style="color: #000066;">xmlns:soapenv</span>=<span style="color: #ff0000;">"http://www.w3.org/2003/05/soap-envelope"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;soapenv:Header</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;soapenv:Body<span style="font-weight: bold; color: black;">&gt;</span></span></span>
         <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ns1:upload</span> xmlns:ns1=<span style="color: #ff0000;">"http://php.axis2.org/samples/mtom"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ns1:fileName<span style="font-weight: bold; color: black;">&gt;</span></span></span>test.jpg<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/ns1:fileName<span style="font-weight: bold; color: black;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ns1:image</span> <span style="color: #000066;">xmlmime:contentType</span>=<span style="color: #ff0000;">"text/txt"</span> <span style="color: #000066;">xmlns:xmlmime</span>=<span style="color: #ff0000;">"http://www.w3.org/2004/06/xmlmime"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
               <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xop:Include</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">"cid:1.594037a2-6d95-1dd1-2b71-00197e732d4d@apache.org"</span> <span style="color: #000066;">xmlns:xop</span>=<span style="color: #ff0000;">"http://www.w3.org/2004/08/xop/include"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/ns1:image<span style="font-weight: bold; color: black;">&gt;</span></span></span>
         <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/ns1:upload<span style="font-weight: bold; color: black;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/soapenv:Body<span style="font-weight: bold; color: black;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/soapenv:Envelope<span style="font-weight: bold; color: black;">&gt;</span></span></span>32--MIMEBoundary594038a6-6d95-1dd1-2b72-00197e732d4d27econtent-transfer-encoding: binarycontent-id:
   <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;<span style="color: #cc66cc;">1</span></span>.594037a2-6d95-1dd1-2b71-00197e732d4d@apache.org<span style="font-weight: bold; color: black;">&gt;</span></span>content-type: text/txtf<strong>TEXT as BINARY</strong>234--MIMEBoundary594038a6-6d95-1dd1-2b72-00197e732d4d--0</pre>
<p>Note that in the last line you see the data you send as it is. Here the binary is sent as an attachment and the element which suppose to keep the binary data refers to the attachment using the content id (check &#8220;href&#8221; attribute). It is obvious for a large binary data this is really optimized way of sending binaries.</p>
<p><strong>&#8220;useMTOM&#8221; =&gt; &#8220;SWA&#8221;</strong></p>
<p>WSF/PHP supports 1.3.2 supports SWA (Soap with Attachment) as well. you can enable this by setting &#8220;useMTOM&#8221; =&gt; &#8220;swa&#8221;. It is also send the binary as an attachment.  But it is not a recommended approach since you can&#8217;t secure the message when using SWA, because it can not be represented in the XML infoset. Here is the message generated enabling the &#8220;SWA&#8221;,</p>
<pre>POST /samples/mtom/mtom_upload_service.php HTTP/1.1
User-Agent: Axis2C/1.5.0
Transfer-Encoding: chunked
Content-Type: multipart/related; boundary=MIMEBoundarybc636bdc-6d96-1dd1-31c0-00197e732d4d; type="application/xop+xml"; start="<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;<span style="color: #cc66cc;">0</span></span>.bc636c40-6d96-1dd1-31c1-00197e732d4d@apache.org<span style="font-weight: bold; color: black;">&gt;</span></span>"; start-info="application/soap+xml"; charset="UTF-8"
Host: 127.0.0.1:8080

32
--MIMEBoundarybc636bdc-6d96-1dd1-31c0-00197e732d4d
2

b2
content-transfer-encoding: binary
content-id: <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;<span style="color: #cc66cc;">0</span></span>.bc636c40-6d96-1dd1-31c1-00197e732d4d@apache.org<span style="font-weight: bold; color: black;">&gt;</span></span>content-type: application/xop+xml;charset=UTF-8;type="application/soap+xml";21b3
   <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;soapenv:Envelope</span> <span style="color: #000066;">xmlns:soapenv</span>=<span style="color: #ff0000;">"http://www.w3.org/2003/05/soap-envelope"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;soapenv:Header</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;soapenv:Body<span style="font-weight: bold; color: black;">&gt;</span></span></span>
         <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ns1:upload</span> xmlns:ns1=<span style="color: #ff0000;">"http://php.axis2.org/samples/mtom"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ns1:fileName<span style="font-weight: bold; color: black;">&gt;</span></span></span>test.jpg<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/ns1:fileName<span style="font-weight: bold; color: black;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ns1:image</span> <span style="color: #000066;">xmlmime:contentType</span>=<span style="color: #ff0000;">"text/txt"</span> <span style="color: #000066;">xmlns:xmlmime</span>=<span style="color: #ff0000;">"http://www.w3.org/2004/06/xmlmime"</span><span style="font-weight: bold; color: black;">&gt;</span></span>1.bc6368a8-6d96-1dd1-31bf-00197e732d4d@apache.org<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/ns1:image<span style="font-weight: bold; color: black;">&gt;</span></span></span>
         <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/ns1:upload<span style="font-weight: bold; color: black;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/soapenv:Body<span style="font-weight: bold; color: black;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/soapenv:Envelope<span style="font-weight: bold; color: black;">&gt;</span></span></span>

32
--MIMEBoundarybc636bdc-6d96-1dd1-31c0-00197e732d4d
2

7e
content-transfer-encoding: binary
content-id:
   <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;<span style="color: #cc66cc;">1</span></span>.bc6368a8-6d96-1dd1-31bf-00197e732d4d@apache.org<span style="font-weight: bold; color: black;">&gt;</span></span>content-type: text/txtfTEXT as BINARY234--MIMEBoundarybc636bdc-6d96-1dd1-31c0-00197e732d4d--0</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/08/19/send-binary-in-soap-with-wsfphp-132/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

