<?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>Jonathan Wijaya Loe&#039;s blog &#187; soap</title>
	<atom:link href="http://blog.jloe.net/tag/soap/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.jloe.net</link>
	<description>A blog about technology blogging, tips and tricks, troubleshooting, and step by step tutorial with specialties in Microsoft .NET, C#, Zend, and PHP. Also includes wonderful and inspiring stories and jokes.</description>
	<lastBuildDate>Mon, 02 May 2011 00:05:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Start SOAP with Zend Framework</title>
		<link>http://blog.jloe.net/2009/04/23/start-soap-with-zend-framework/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=start-soap-with-zend-framework</link>
		<comments>http://blog.jloe.net/2009/04/23/start-soap-with-zend-framework/#comments</comments>
		<pubDate>Thu, 23 Apr 2009 01:37:51 +0000</pubDate>
		<dc:creator>Jonathan Loe</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[client]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[soap]]></category>
		<category><![CDATA[wampserver]]></category>
		<category><![CDATA[web service]]></category>
		<category><![CDATA[wsdl]]></category>
		<category><![CDATA[zend]]></category>
		<category><![CDATA[zend_soap_client]]></category>
		<category><![CDATA[zend_soap_server]]></category>

		<guid isPermaLink="false">http://blog.jloe.net/?p=139</guid>
		<description><![CDATA[SOAP? Hang on.. This is not the soap you probably first think of from your daily life. This is the SOAP in Information Technology term. Sorry but don't mean to discriminate anyone out there ;)]]></description>
			<content:encoded><![CDATA[<p>SOAP? Hang on.. This is not the soap you probably first think of from your daily life. This is the SOAP in Information Technology term. Sorry but don&#8217;t mean to discriminate anyone out there <img src='http://blog.jloe.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>For readers who have no idea what SOAP is. Here&#8217;s a short explanation about SOAP as defined by <a title="What is SOAP?" href="http://searchsoa.techtarget.com/sDefinition/0,,sid26_gci214295,00.html" target="_blank">TechTarget</a>.</p>
<blockquote><p>SOAP (Simple Object Access Protocol) is a way for a program running in one kind of operating system (such as Windows 2000) to communicate with a program in the same or another kind of an operating system (such as Linux) by using the World Wide Web&#8217;s Hypertext Transfer Protocol (HTTP)and its Extensible Markup Language (XML) as the mechanisms for information exchange.</p></blockquote>
<p>Here I will share my step-by-step guide on how to start your SOAP application using PHP and Zend as your Model View Controller (MVC) framework. First, I have the following application and framework installed. But I will not explain in detail about them in this post.</p>
<ul>
<li><a title="WampServer" href="http://www.wampserver.com/" target="_blank">WampServer</a></li>
<li><a title="Zend Framework" href="http://framework.zend.com/download" target="_blank">Zend Framework 1.7.5</a></li>
</ul>
<p>To start, first you need to enable a php extension called <em>php_soap</em>. In WampServer, this module has been pre-installed but you need to enable the module by the following steps.</p>
<ol>
<li>Click WampServer icon on the tray.</li>
<li>Select PHP &gt; PHP Extension.</li>
<li>And finally click php_soap to enable it.</li>
</ol>
<p>Then, we create a simple class called <em>Models_Writer</em> which has a function <em>write</em> that returns the specified string to the calling function.</p>
<pre name="code" class="php">
class Models_Writer
{
  /**
   * Return the specified text
   *
   * @param string $string
   * @return string
   */
  public function write( $string )
  {
    return $string;
  }
}
</pre>
<p>Followed by a simple action function called <em>wsdlAction</em> which renders generated <em>WSDL</em> for the class <em>Models_Writer</em> using <em>Zend_Soap_AutoDiscover</em>. Hey hey stop! what the heck is <em>WSDL</em>?. In short,</p>
<blockquote><p>WSDL or Web Services Description Language is an XML-based language that provides a model for describing Web services.</p></blockquote>
<p>Follow this <a href="http://en.wikipedia.org/wiki/Web_Services_Description_Language">link</a> on wikipedia to help you along with what exactly is WSDL.</p>
<p>Moving on&#8230;</p>
<pre name="code" class="php">
/**
 * Render the WSDL
 */
public function wsdlAction()
{
  $wsdl = new Zend_Soap_AutoDiscover();
  $wsdl-&gt;setUri( APP_URL . '/index/' );
  $wsdl-&gt;setClass( 'Models_Writer' );
  $wsdl-&gt;handle();
  exit;
}
</pre>
<p><!--adsense#az-edeal-->As shown on line 7, <em>APP_URL</em> is to be replaced with the url of the application (ie. http://localhost/). You may define <em>APP_URL</em> inside <em>bootstrap.php</em> for global use. Function <em>setUri</em> is used to define the url used as the server. In this example, the <em>indexAction</em> is used to serve as the Soap server. And to verify the generated <em>WSDL</em> is correct, use your browser and type http://localhost/index/wsdl<strong><span style="text-decoration: underline;">/</span></strong> with the assumption that all Action functions in this example will be coded inside <em>IndexController</em> class. This url should returns with the correct <em>WSDL</em>. Please take note of the url though, that it must end with a backslash &#8216;/&#8217;.</p>
<p>And if browser returns with an error message below.</p>
<pre name="code" class="html">
XML Parsing Error: XML or text declaration not at start of entity
</pre>
<p>Please make sure there isn&#8217;t any trailing spaces before the <em>&lt;?php</em> and after <em>?&gt;</em> in your php file.</p>
<p>Next, we shall look at the code to create your Soap server.</p>
<pre name="code" class="php">
/**
 * Serve as the web service
 */
public function indexAction()
{
  $server = new Zend_Soap_Server( APP_URL . '/index/wsdl/' );
  $server-&gt;setClass( 'Models_Writer' );
  $server-&gt;handle();
  exit;
}
</pre>
<p>The above code instantiates <em>Zend_Soap_Server</em> with the url to the generated <em>WSDL</em> and set the class as <em>Models_Writer</em> and finally quits upon handling the request. Ok, now the <em>indexAction</em> is ready to serve as a Soap server.</p>
<p>Finally, to make sure that the server is handling the request correctly, let&#8217;s create the Soap client that makes a Soap request to the server.</p>
<pre name="code" class="php">
/**
 * Client to request from web service
 */
public function clientAction()
{
  $client = new Zend_Soap_Client( APP_URL . '/index/wsdl/' );
  $response = $client-&gt;write( 'hello world' );
  var_dump( $response );
  exit;
}
</pre>
<p>The above code first instantiates <em>Zend_Soap_Client</em> with the specified url to the <em>WSDL</em>. Line below then calls the function <em>write</em> from the server. Here, you were probably wondering where in the code have we specified the server url. Well, if you recall the previous code when we first created the <em>WSDL</em>, we has actually specified the Soap server url. As a result, Soap client is able to know the server url from the <em>WSDL</em>.</p>
<p>Now try access http://localhost/index/client/, the page should return you with the following line:</p>
<pre name="code" class="html">
string(11) "hello world"
</pre>
<p>Phew! it&#8217;s along explanation for a simple task. My arms are getting cramped now. I hope you are following well with my explanation. If not, well, I have a sample file you can <a href="http://blog.jloe.net/wp-content/uploads/2009/04/jloe-soap.zip">download</a> and test it on your local. I hope it works well. If not, let me know of your encounter.</p>
<p>Well, while experimenting this I have a stumbling block which I managed to find a solution to it. Here goes the encounter.</p>
<p>If you encounter the following error message:</p>
<pre name="code" class="html">
Warning: domdocument::domdocument() expects at least 1 parameter, 0 given in C:wampbinphpphp5.2.8
includesZendSoapWsdl.php on line 94
Fatal error: Call to undefined method domdocument::loadXML() in C:wampbinphpphp5.2.8
includesZendSoapWsdl.php on line 95
</pre>
<p>You need disable <em>php_domxml</em> on your WampServer.</p>
<p>I hope I give enough information. Feel free to give your feedback. If you find this post useful, please help leave your rating below. Thanks! Happy coding! <img src='http://blog.jloe.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Source:</p>
<ul>
<li><a target="_blank" href="http://electrotek.wordpress.com/2008/04/19/soap-web-service-with-zend-framework/">SOAP web service with Zend Framework</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.jloe.net/2009/04/23/start-soap-with-zend-framework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

