<?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>BombStrike's blog &#187; soap</title>
	<atom:link href="http://www.bombstrike.org/tag/soap/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bombstrike.org</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Sun, 07 Mar 2010 22:44:45 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Build complex SOAP requests and headers in PHP</title>
		<link>http://www.bombstrike.org/2009/02/build-complex-soap-requests-and-headers-in-php/</link>
		<comments>http://www.bombstrike.org/2009/02/build-complex-soap-requests-and-headers-in-php/#comments</comments>
		<pubDate>Wed, 18 Feb 2009 09:49:55 +0000</pubDate>
		<dc:creator>Christophe Robin</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[headers]]></category>
		<category><![CDATA[paypal]]></category>
		<category><![CDATA[request]]></category>
		<category><![CDATA[soap]]></category>

		<guid isPermaLink="false">http://bombstrike.wordpress.com/?p=19</guid>
		<description><![CDATA[When you&#8217;re writing PHP code for a company, you&#8217;ll need someday to write code that interact with a SOAP webservice. An exemple could be the Paypal SOAP API for ExpressCheckout. The original PHP API is terrible because of his handling of SOAP headers that doesn&#8217;t give the control we could want on an item.
The solution [...]]]></description>
			<content:encoded><![CDATA[<p>When you&#8217;re writing PHP code for a company, you&#8217;ll need someday to write code that interact with a SOAP webservice. An exemple could be the Paypal SOAP API for ExpressCheckout. The original PHP API is terrible because of his handling of SOAP headers that doesn&#8217;t give the control we could want on an item.</p>
<p>The solution to this is to extend the original SoapClient using PHP:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;height:560px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">class</span> SoapClientPaypal <span style="color: #000000; font-weight: bold;">extends</span> SoapClient<br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __doRequest<span style="color: #009900;">&#40;</span><span style="color: #000088;">$request</span><span style="color: #339933;">,</span> <span style="color: #000088;">$location</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$action</span><span style="color: #339933;">,</span> <span style="color: #000088;">$version</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">/* the $request element here contain the XML formatted request */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$dom</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DOMDocument<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$dom</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">loadXML</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$request</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">/* now that you've loaded the request, you can easily add elements, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* replace them, etc...*/</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">/* save the modified request for __getLastRequest() */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>__last_request <span style="color: #339933;">=</span> <span style="color: #000088;">$dom</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">saveXML</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">/* then call the parent function to do the query */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$response</span> <span style="color: #339933;">=</span> parent<span style="color: #339933;">::</span>__doRequest<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>__last_request<span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$location</span><span style="color: #339933;">,</span> <span style="color: #000088;">$action</span><span style="color: #339933;">,</span> <span style="color: #000088;">$version</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">/* $response contain the XML response returned by the webservice,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* you can also change it if needed, for exemple, in paypal I had to<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* replace each occurences of the ebl:GetExpress...DetailsType<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* by xsd:array because PHP would do some really weird things with <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* it ( like referencing the parent, preventing access to child nodes )<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* I do not store the response in __last_response because I want<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* what was returned by the server, not what I changed :D */</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000088;">$response</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>By doing that, you have a great deal of control on the request/responses coming from a SOAP webservices, the <strong>$location</strong> var contain the WS URL, the <strong>$action</strong> is the action called and <strong>$version</strong> is the SOAP version.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bombstrike.org/2009/02/build-complex-soap-requests-and-headers-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
