<?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>PHP Made Simple &#187; soap</title>
	<atom:link href="http://www.phpmadesimple.info/tag/soap/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.phpmadesimple.info</link>
	<description>To support simplicity, possiibility and cost effective of PHP</description>
	<lastBuildDate>Tue, 03 Aug 2010 14:13:56 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Using XML web services</title>
		<link>http://www.phpmadesimple.info/2008/09/02/using-xml-web-services/</link>
		<comments>http://www.phpmadesimple.info/2008/09/02/using-xml-web-services/#comments</comments>
		<pubDate>Tue, 02 Sep 2008 04:36:42 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[rest]]></category>
		<category><![CDATA[soap]]></category>
		<category><![CDATA[webservice]]></category>

		<guid isPermaLink="false">http://artemis.com.vn/blogvui/index.php/2008/09/02/using-xml-web-services/</guid>
		<description><![CDATA[Web services allow you to exchange  information over HTTP using XML. When you want to find out the weather forecast, the current stock price, or the cost of a product on eBay, you can write a short script to gather that data in a format you can  easily manipulate. From a developer&#8217;s perspective, [...]]]></description>
			<content:encoded><![CDATA[<p class="docText">Web services allow you to exchange  information over HTTP using XML. When you want to find out the weather forecast, the current stock price, or the cost of a product on eBay, you can write a short script to gather that data in a format you can  easily manipulate. From a developer&#8217;s perspective, it&#8217;s as if you&#8217;re calling a  local function that returns a value.</p>
<p class="docText">Web services empowers your application with a straightforward idea that you, your team or even the whole your company cannot develop everything but can use lot of professional services for free or by paying some money. There is also the situation when you need data that your web application is not the one collecting those information. Web services, in this case, provide data collectors a mean to expand their business by selling data or by publishing data on other websites to drive more traffics or generate more purchases. <span id="more-43"></span></p>
<p class="docText">The key behind web services is platform-independent  communication by using XML and standard protocols. Your PHP script running on Apache/Linux can invoke a function written by ASP.NET on IIS/Windows or JSP on Tomcat/Solaris. There are two major types of web services: REST and SOAP. A REST request  is relatively straightforward, as they involve making an HTTP request of a  server and processing an XML document that&#8217;s returned as the response. Since  most developers are familiar with HTTP and XML, the learning curve for REST is  short and shallow.</p>
<p class="docText">The other popular web services format is SOAP, which is a W3C standard for  passing messages across the network and calling functions on remote computers.  SOAP provides developers with many options; however, this flexibility comes at a  price. SOAP is quite complex, and the full specification is large and growing.</p>
<p class="docText">Beyond REST and SOAP, there&#8217;s one other web services format  that&#8217;s relatively common, XML-RPC. XML-RPC is similar in spirit to SOAP, as it  also converts native data into a language-netural format that you can pass into  functions and receive replies. However, XML-RPC is far less complex than  SOAP.</p>
<h1 class="docText">Making real calls</h1>
<p class="docText">One of the very interesting places to learn about web services is eBay developer site and I will use eBay services to demonstrate many aspects of using web services in real. Of course, you have to goto <a href="http://developer.ebay.com" target="_blank">http://developer.ebay.com</a> and register your own account as the security key I use here is fake.</p>
<p class="docText">Just in case you are not familiar with eBay, it&#8217;s a place for users to sell their stuff, either old or brand new. In order to make it easier for sellers and buyers, eBay provide API set to let developers retrieve information about items, deals, bids, etc. The API sets are available for many programming languages of course as they are web services and the reason I use eBay is their document is perfect and me and my company was together with a client in US won eBay top prize for widget design contenst 2008.</p>
<p class="docText">For you to get first hand experience with web service, this is a <a href="http://developer.ebay.com/DevZone/shopping/docs/Concepts/ShoppingAPIGuide.html" target="_blank">good reference</a> about how web service is setup, how you call it and how to use the result on your website.</p>
<p class="docText">Now, I know that not everyone is comfortable with handling XML. While we are talking about XML web services, it&#8217;s not true that returned result must be in XML format. Well, anyway business is to make ease for consumers and eBay did it. You will see that for one service call, you can specify the return format you want which can be NV (name-value pair), XML, JSON or SOAP. That&#8217;s to encourage you taking the next step because it&#8217;s more fun to make result into use without a need of knowledge about XML parsers. Though I am sure you will need some XML parsers sooner or later.</p>
<h2 class="docText">Calling a REST method</h2>
<p class="docText">As REST is a style of web services in which you make requests using HTTP methods such as get and post, it is very easy to make a test before writing any PHP code. Open your browser with this URL:</p>
<p class="docText">http://open.api.ebay.com/shopping?version=517&amp;appid=YourAppID&amp;callname=FindItems&amp;QueryKeywords=dog&amp;ItemSort=BestMatch</p>
<p class="docText">And you should get some readable XML result if you remember to change YourAppID with a real value. Now you know what is the result of this FindItems method. Writing a PHP code for REST method is just something you already know.</p>
<pre class="brush: php">
$base = &#039;http://open.api.ebay.com/shopping&#039;;
$params = array(&#039;version&#039; =&gt; &#039;517&#039;, &#039;appid&#039; =&gt; &#039;...&#039;, &#039;callname&#039; =&gt; &#039;FindItems&#039;, &#039;QueryKeyword&#039; =&gt; &#039;dog&#039;, &#039;ItemSort&#039; =&gt; &#039;BestMatch&#039;);
$url = $base . &#039;?&#039; . http_build_query($params);
$response = file_get_contents($url); ?&gt;
</pre>
<p class="docText">or if you want to use cURL:</p>
<p class="docText">
<pre class="brush: php">
//Prepare the $url
$c = curl_init($url);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($c);
curl_close($c);
</pre>
<h2 class="docText">Calling a SOAP method with WSDL</h2>
</p>
<p class="docText">To call a method using SOAP, you need SoapClient object. As SOAP is strictly typed, whenever possible you want to know the method description file which is described using WSDL (Web Service Description Language) and available in .wsdl format at the service provider host.</p>
<p>$client = new SOAPClient(&#8217;http://api.example.com/service.wsdl&#8217;);</p>
<p>SOAPClient construction method let you provide other options and an important one is the service location. Although the WSDL may specify these options by itself, it&#8217;s not the case of eBay WSDL for shopping API. This code shows how to call eBay FindItems method using SOAPClient.</p>
<pre class="brush: php">
$wsdl_url =     &#039;http://developer.ebay.com/webservices/latest/ShoppingService.wsdl&#039;;

$client = new SOAPClient($wsdl_url,
array(&#039;location&#039; =&gt; &#039;http://open.api.ebay.com/shopping?&amp;callname=FindItems&amp;version=517&amp;siteid=3&amp;appid=xxx&#039;));

$result = $client-&gt;FindItems(array(                                 &#039;QueryKeywords&#039;=&gt;&#039;iphone&#039;,                                 &#039;MaxEntries&#039; =&gt; 30                                 ));
$items = $result-&gt;Item;

foreach($items as $item){
echo $item-&gt;Title.&#039;&lt;br /&gt;&#039;;
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.phpmadesimple.info/2008/09/02/using-xml-web-services/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
