<?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>Alkim Gozen</title>
	<atom:link href="http://blog.alkimake.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.alkimake.com</link>
	<description>Just another Software Developer</description>
	<lastBuildDate>Fri, 25 Sep 2009 21:15:24 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=4.3.10</generator>
	<item>
		<title>JSON-RPC Bridge to XML Web Services and usage in Objective-C in iPhone</title>
		<link>http://blog.alkimake.com/2009/09/json-rpc-bridge-to-xml-web-services-and-usage-in-objective-c-in-iphone/</link>
		<comments>http://blog.alkimake.com/2009/09/json-rpc-bridge-to-xml-web-services-and-usage-in-objective-c-in-iphone/#comments</comments>
		<pubDate>Thu, 10 Sep 2009 18:49:00 +0000</pubDate>
		<dc:creator><![CDATA[Alkım Gözen]]></dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[ASIHTTPRequest]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[JSON-RPC]]></category>
		<category><![CDATA[JSP]]></category>
		<category><![CDATA[Netbeans]]></category>
		<category><![CDATA[Objective-C]]></category>

		<guid isPermaLink="false">http://blog.alkimake.com/?p=22</guid>
		<description><![CDATA[For me, the main problem about SOAP Web Servicess that they are using XML technology which is useless for both ajax and mobile programming (such as Obj-C and J2ME). I don&#8217;t compare JSON and XML in this post, i just like JSON more&#8230;
For 2 years XML Web services have not been problem for me because [...]]]></description>
				<content:encoded><![CDATA[<p>For me, the main problem about SOAP Web Servicess that they are using XML technology which is useless for both ajax and mobile programming (such as Obj-C and J2ME). I don&#8217;t compare JSON and XML in this post, i just like JSON more&#8230;</p>
<p>For 2 years XML Web services have not been problem for me because Java handles SOAP web services really good. On the other hand, i really used to get mad when i was using SOAP Web Services via Java Mobile (J2ME). But the idea of converting SOAP Web Services to JSON had never came up.</p>
<p>When i try to write a cocoa application for iPhone which has to use a SOAP Web Service to get the data on air, i totally get insane :). If you want to know how bad is, try to visit these site : <a href="http://icodeblog.com/2008/11/03/iphone-programming-tutorial-intro-to-soap-web-services/" target="_blank">iPhone Programming Tutorial : Intro To Soap Web Services</a> (or Turkish version : <a href="http://www.yazarbozar.com/2009/04/14/iphone-ile-web-service-kullanimi/" target="_blank">iPhone ile Web Service Kullanımı</a>)</p>
<p>Thankfully there is a JSON RPC supported by oss.metaparadigm for Java web applications. You can find the details of this library <a title="JSON-RPC" href="http://oss.metaparadigm.com/jsonrpc/" target="_blank">here</a>. I will tell you how easy to build a JSON Bridge to your existing SOAP Web Services and use this bridge to get data from service in iPhone application development.</p>
<h4><span id="more-22"></span></h4>
<h4>We Need,</h4>
<p>A Java Servlet container like Sun&#8217;s <a title="Glassfish Server" href="https://glassfish.dev.java.net/" target="_blank">GlassFish Server</a> which i use. ( There are plenty servlet containers for J2EE. I assume that you have basic knowledge of web applications in Java)</p>
<p>Than of course we need Sun&#8217;s IDE for Java; Java Web and EE enabled <a href="http://www.netbeans.org/" target="_blank">Netbeans</a></p>
<p>JSON-RPC <a href="http://oss.metaparadigm.com/jsonrpc/download.html" target="_blank">library</a> (Also we need <a href="http://oss.metaparadigm.com/jsonrpc-1.0/jsonrpc.js.txt" target="_blank">jsonrpc.js</a> for testing JSON service at Web Browser. You do not need this file to implement iPhone application)</p>
<p>For the iPhone development part, we do not need anything to connect to the service and get data back. But in this post i will use <a href="http://allseeing-i.com/ASIHTTPRequest/" target="_blank">ASIHTTPRequest</a> open source connection library to connect to JSON-RPC service (Thanks to Umut GÖKBAYRAK let me know this brilliant connection library) and <a href="http://code.google.com/p/json-framework/" target="_blank">JSON Cocoa Framework</a> to create and parse JSON data. ( I am not even mentioning about how you can develop iPhone applications <img src="http://s.w.org/images/core/emoji/72x72/1f600.png" alt="😀" class="wp-smiley" style="height: 1em; max-height: 1em;" /> )</p>
<h4>Prepare Java Class,</h4>
<p>In this example we use w3school&#8217;s test web service</p>
<pre>http://www.w3schools.com/webservices/tempconvert.asmx?WSDL</pre>
<p>We can see methods when we go <a href="http://www.w3schools.com/webservices/tempconvert.asmx" target="_blank">http://www.w3schools.com/webservices/tempconvert.asmx</a> via web browser.</p>
<p><a rel="lightbox" href="http://blog.alkimake.com/wp-content/uploads/2009/09/Picture-1.png"><img class="alignnone size-full wp-image-29" title="TempConvert Web Service" src="http://blog.alkimake.com/wp-content/uploads/2009/09/Picture-1.png" alt="TempConvert Web Service" width="681" height="188" /></a></p>
<p>First we create Java Web Application project in netbeans. We call it, <em>TempConvertBridge.</em></p>
<p><em> </em></p>
<p>Then we create a web service from WSDL under New menu. We create this Web Service because Netbeans automatically generates Web Service Client for this application and also creates a new Web Service and includes all methods described in WSDL document. So we can grab every methods for class to register to JSON-RPC.</p>
<p>Lets call this Web Service name <em>BridgeService </em>and you have to paste Web Service WSDL address.</p>
<p><a rel="lightbox" href="http://blog.alkimake.com/wp-content/uploads/2009/09/Picture-5.png"><img class="alignnone size-medium wp-image-34" title="Web Service from WSDL Settings" src="http://blog.alkimake.com/wp-content/uploads/2009/09/Picture-5-300x277.png" alt="Web Service from WSDL Settings" width="300" height="277" /></a></p>
<p>Lets create a new Java Class named; <em>Bridge</em>. This process is not needed so importantly but if we create a new bridge, we can add or edit something on this bridge after data comes from Web Service.</p>
<p>Under created Web Service from WSDL <em>TempConvert</em> copy all methods and paste into class <em>Bridge.</em></p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;">    <span style="color: #000000; font-weight: bold;">public</span> java.<span style="color: #006633;">lang</span>.<span style="color: #003399;">String</span> fahrenheitToCelsius<span style="color: #009900;">&#40;</span>java.<span style="color: #006633;">lang</span>.<span style="color: #003399;">String</span> fahrenheit<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">//TODO implement this method</span>
        <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">UnsupportedOperationException</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Not implemented yet.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> java.<span style="color: #006633;">lang</span>.<span style="color: #003399;">String</span> celsiusToFahrenheit<span style="color: #009900;">&#40;</span>java.<span style="color: #006633;">lang</span>.<span style="color: #003399;">String</span> celsius<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">//TODO implement this method</span>
        <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">UnsupportedOperationException</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Not implemented yet.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>You can see  every method created to throw an exception UnsupportedOperationException(&#8220;Not implemented yet.&#8221;); So we have to implement :). We add web service connection to our class <em>Bridge</em>. The Class would be like :</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Bridge <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> org.<span style="color: #006633;">tempuri</span>.<span style="color: #006633;">TempConvertSoap</span> service <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> org.<span style="color: #006633;">tempuri</span>.<span style="color: #006633;">TempConvert</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getTempConvertSoap</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> java.<span style="color: #006633;">lang</span>.<span style="color: #003399;">String</span> fahrenheitToCelsius<span style="color: #009900;">&#40;</span>java.<span style="color: #006633;">lang</span>.<span style="color: #003399;">String</span> fahrenheit<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> service.<span style="color: #006633;">fahrenheitToCelsius</span><span style="color: #009900;">&#40;</span>fahrenheit<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> java.<span style="color: #006633;">lang</span>.<span style="color: #003399;">String</span> celsiusToFahrenheit<span style="color: #009900;">&#40;</span>java.<span style="color: #006633;">lang</span>.<span style="color: #003399;">String</span> celsius<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> service.<span style="color: #006633;">celsiusToFahrenheit</span><span style="color: #009900;">&#40;</span>celsius<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>We created a class represents to return data of Web Service. Now we are ready to implement JSON-RPC.</p>
<h4>Add JSON-RPC to our project,</h4>
<p>We also added <em>json-rpc.jar</em> to library in project, but we have to define <em>com.metaparadigm.jsonrpc.JSONRPCServlet </em>as a servlet to use as Java Bean. So we include this xml node as chid of web-app element in web.xml file of our project.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.metaparadigm.jsonrpc.JSONRPCServlet<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.metaparadigm.jsonrpc.JSONRPCServlet<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.metaparadigm.jsonrpc.JSONRPCServlet<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/TempBridge<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Value of &lt;url-pattern&gt; element describes where we post and get JSON data at server. In this project we post data to http://localhost:8080/TempConvertBridge/TempBridge ( I am using local GlassFih server at port 8080)</p>
<p>As we prepared servlet <em>JSONRPCServlet</em> we have to register <em>Bridge</em> class to <em>JSONRPCServlet</em> as a session object. So we edit <em>index.jsp</em> page coded below:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;%</span><span style="color: #339933;">@</span>page contentType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/html&quot;</span><span style="color: #000000; font-weight: bold;">%&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;%</span><span style="color: #339933;">@</span>page pageEncoding<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">%&gt;</span>
&nbsp;
&lt;jsp:useBean id=&quot;JSONRPCBridge&quot; scope=&quot;session&quot;
             class=&quot;com.metaparadigm.jsonrpc.JSONRPCBridge&quot; /&gt;
&lt;jsp:useBean id=&quot;bridge&quot; scope=&quot;session&quot;
             class=&quot;Services.Bridge&quot; /&gt;
<span style="color: #000000; font-weight: bold;">&lt;%</span> JSONRPCBridge<span style="color: #339933;">.</span>registerObject<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;bridge&quot;</span><span style="color: #339933;">,</span> bridge<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">%&gt;</span>
&nbsp;
Registration Successful...</pre></td></tr></table></div>

<p>First content type of page is not important. You can leave the value as it is. And also page encoding.Then we add <em>com.metaparadigm.jsonrpc.JSONRPCBridge</em> and <em>Services.Bridge</em> as java beans. At last we register object bridge to <em>JSONRPCBridge</em>. I also added &#8220;Registration Successfull&#8230;&#8221; text to get some string <img src="http://s.w.org/images/core/emoji/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p>This page is so vital that we have to register the object and let <em>JSONRPCBridge</em> to create methods to be used as it is.</p>
<p>JSON-RPC integration is ready to use in iPhone application. But lets go in deeply and test our JSON-RPC service via test jsp page.</p>
<h4>Test Time,</h4>
<p>Lets create a new jsp page called <em>testBridge.jsp</em> and includes ;</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;%</span><span style="color: #339933;">@</span>page contentType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/html&quot;</span><span style="color: #000000; font-weight: bold;">%&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;%</span><span style="color: #339933;">@</span>page pageEncoding<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">%&gt;</span>
&nbsp;
&lt;jsp:useBean id=&quot;JSONRPCBridge&quot; scope=&quot;session&quot;
             class=&quot;com.metaparadigm.jsonrpc.JSONRPCBridge&quot; /&gt;
&lt;jsp:useBean id=&quot;bridge&quot; scope=&quot;session&quot;
             class=&quot;Services.Bridge&quot; /&gt;
<span style="color: #000000; font-weight: bold;">&lt;%</span> JSONRPCBridge<span style="color: #339933;">.</span>registerObject<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;bridge&quot;</span><span style="color: #339933;">,</span> bridge<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">%&gt;</span>
&nbsp;
&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;
    &quot;http://www.w3.org/TR/html4/loose.dtd&quot;&gt;
&lt;html&gt;
&nbsp;
    &lt;head&gt;
        &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=UTF-8&quot;&gt;
        &lt;title&gt;JSP Page&lt;/title&gt;
        &lt;script type=&quot;text/javascript&quot; src=&quot;jsonrpc.js&quot;&gt;&lt;/script&gt;
        &lt;script type=&quot;text/javascript&quot;&gt;
            function onLoad()
            {
                jsonrpc = new JSONRpcClient(&quot;TempBridge&quot;);
            }
&nbsp;
            function convertToC()
            {
                var valNode = document.getElementById(&quot;val&quot;);
                var result = jsonrpc.bridge.fahrenheitToCelsius(valNode.value);
                alert(valNode.value + &quot;F is : &quot; + result + &quot; C&quot;);
            }
&nbsp;
            function convertToF()
            {
                var valNode = document.getElementById(&quot;val&quot;);
                var result = jsonrpc.bridge.celsiusToFahrenheit(valNode.value);
                alert(valNode.value + &quot;C is : &quot; + result + &quot; F&quot;);
            }
&nbsp;
        &lt;/script&gt;
    &lt;/head&gt;
    &lt;body onload=&quot;onLoad();&quot;&gt;
        &lt;h1&gt;TempConvert JSON RPC Test&lt;/h1&gt;
        &lt;input type=&quot;text&quot; id=&quot;val&quot; name=&quot;val&quot; value=&quot;&quot; /&gt;
        &lt;input type=&quot;button&quot; value=&quot;Convert to C&quot; name=&quot;submit&quot; onclick=&quot;convertToC();&quot; /&gt;
        &lt;input type=&quot;button&quot; value=&quot;Convert to F&quot; name=&quot;submit&quot; onclick=&quot;convertToF();&quot; /&gt;
    &lt;/body&gt;
&lt;/html&gt;</pre></td></tr></table></div>

<p>Lets run this file and see what happens with Firebug ultimate plug-in for Firefox. We can see what we post and get data when we press &#8220;Convert to C&#8221; and &#8220;Convert to F&#8221; buttons.</p>
<p>We Post,</p>
<p><a rel="lightbox" href="http://blog.alkimake.com/wp-content/uploads/2009/09/Picture-7.png"><img class="alignnone size-full wp-image-38" title="JSON-RPC Posted Data" src="http://blog.alkimake.com/wp-content/uploads/2009/09/Picture-7.png" alt="JSON-RPC Posted Data" width="473" height="71" /></a></p>
<p>And we get,</p>
<p><a rel="lightbox" href="http://blog.alkimake.com/wp-content/uploads/2009/09/Picture-8.png"><img class="alignnone size-full wp-image-39" title="JSON-RPC Returned Data" src="http://blog.alkimake.com/wp-content/uploads/2009/09/Picture-8.png" alt="JSON-RPC Returned Data" width="458" height="72" /></a></p>
<p>as a JSON data and i am very happy to see it <img src="http://s.w.org/images/core/emoji/72x72/1f600.png" alt="😀" class="wp-smiley" style="height: 1em; max-height: 1em;" /> So we can continue with implementing to iPhone Application.</p>
<h4>At the Objective-C side,</h4>
<p>As i said i used <em>ASIHTTPRequest</em> library to create connections. But first and again i want to say, we have to register <em>Bridge</em> class to <em>JSONRPCBridge</em> so we have to call <em>index.jsp</em> page once. But you have to remember that this registration is time limited by session timeout. If you develop an application exceeds this time limit, you have to connect index.jsp asynchronously at the backgound <img src="http://s.w.org/images/core/emoji/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /> This was the tip of the day <img src="http://blog.alkimake.com/wp-includes/images/smilies/simple-smile.png" alt=":)" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p>I create a DataHandler class in Xcode and i put first connection on constructor (init method) like;</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> init
<span style="color: #002200;">&#123;</span>
	self <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>super init<span style="color: #002200;">&#93;</span>;
	<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>self <span style="color: #002200;">!=</span> <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
		<span style="color: #400080;">NSURL</span> <span style="color: #002200;">*</span>url <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSURL</span> URLWithString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;http://localhost:8080/TempConvertBridge/&quot;</span><span style="color: #002200;">&#93;</span>;
		ASIHTTPRequest <span style="color: #002200;">*</span>request <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>ASIHTTPRequest alloc<span style="color: #002200;">&#93;</span> initWithURL<span style="color: #002200;">:</span>url<span style="color: #002200;">&#93;</span> autorelease<span style="color: #002200;">&#93;</span>;
		<span style="color: #002200;">&#91;</span>request start<span style="color: #002200;">&#93;</span>;
		<span style="color: #400080;">NSError</span> <span style="color: #002200;">*</span>error <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>request error<span style="color: #002200;">&#93;</span>;
		<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>response;
		<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">!</span>error<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
			response <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>request responseString<span style="color: #002200;">&#93;</span>;
			NSLog<span style="color: #002200;">&#40;</span>response<span style="color: #002200;">&#41;</span>;
		<span style="color: #002200;">&#125;</span> <span style="color: #a61390;">else</span> <span style="color: #002200;">&#123;</span>
			NSLog<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>error description<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>;
		<span style="color: #002200;">&#125;</span>
	<span style="color: #002200;">&#125;</span>
	<span style="color: #a61390;">return</span> self;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>We also check that if there is an error on this connection as <em>NSError</em> object. Lets prepare an async connection and self delegated method to convert Celsius to Fahrenheit.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>IBAction<span style="color: #002200;">&#41;</span> convertToC<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span>fValue
<span style="color: #002200;">&#123;</span>
	<span style="color: #400080;">NSURL</span> <span style="color: #002200;">*</span>url <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSURL</span> URLWithString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;http://localhost:8080/TempConvertBridge/TempBridge&quot;</span><span style="color: #002200;">&#93;</span>;
	ASIHTTPRequest <span style="color: #002200;">*</span>request <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>ASIHTTPRequest alloc<span style="color: #002200;">&#93;</span> initWithURL<span style="color: #002200;">:</span>url<span style="color: #002200;">&#93;</span> autorelease<span style="color: #002200;">&#93;</span>;
	<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>sendData <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSString</span> stringWithFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;{<span style="color: #2400d9;">\&quot;</span>id<span style="color: #2400d9;">\&quot;</span>: 2, <span style="color: #2400d9;">\&quot;</span>method<span style="color: #2400d9;">\&quot;</span>: <span style="color: #2400d9;">\&quot;</span>bridge.fahrenheitToCelsius<span style="color: #2400d9;">\&quot;</span>, <span style="color: #2400d9;">\&quot;</span>params<span style="color: #2400d9;">\&quot;</span>: [ <span style="color: #2400d9;">\&quot;</span>%d<span style="color: #2400d9;">\&quot;</span> ]}&quot;</span>, fValue<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>request appendPostData<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>sendData dataUsingEncoding<span style="color: #002200;">:</span>NSUTF8StringEncoding<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>request setRequestMethod<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;PUT&quot;</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>request setDelegate<span style="color: #002200;">:</span>self<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>request setDidFinishSelector<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>requestDone<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>request setDidFailSelector<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>requestWentWrong<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>self queue<span style="color: #002200;">&#93;</span> addOperation<span style="color: #002200;">:</span>request<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>requestDone<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>ASIHTTPRequest <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>request
<span style="color: #002200;">&#123;</span>
	<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>response <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>request responseString<span style="color: #002200;">&#93;</span>;
	NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;message = %@&quot;</span>, reponse<span style="color: #002200;">&#41;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>requestWentWrong<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>ASIHTTPRequest <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>request
<span style="color: #002200;">&#123;</span>
	<span style="color: #400080;">NSError</span> <span style="color: #002200;">*</span>error <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>request error<span style="color: #002200;">&#93;</span>;
	NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;message = %@&quot;</span>, <span style="color: #002200;">&#91;</span>error description<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>We created a <em>ASIHTTPRequest</em> connection protocol to <em>&#8220;http://localhost:8080/TempConvertBridge/TempBridge&#8221;</em> .  We use <em>ASIHTTPRequest </em>by<em> &#8220;PUT&#8221;</em> method rather than <em>POST</em> method to avoid multi-part form data format. I used <em>sendData</em> as a string, but if you prefer you can create by <em>JSON-Framework</em>. That would be necessary in more complicated projects. We appended post data and defined the delegation class as self. If connection is ok and we can get data, the application will run <em>requestDone</em> method, else <em>requestWentWrong</em> will be fired. Both we can log and see what happens.</p>
<p>One last thing if we create a method called <em>convertToC</em> we have to get the result clearly. So lets use <em>JSON-Framework</em> to get result. We change <em>requestDone</em> like;</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>requestDone<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>ASIHTTPRequest <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>request
<span style="color: #002200;">&#123;</span>
	<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>response <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>request responseString<span style="color: #002200;">&#93;</span>;
	SBJSON <span style="color: #002200;">*</span>parser <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>SBJSON alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
	<span style="color: #400080;">NSDictionary</span> <span style="color: #002200;">*</span>object <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>parser objectWithString<span style="color: #002200;">:</span>response error<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
	NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;message = %@&quot;</span>, <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>object objectForKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;result&quot;</span><span style="color: #002200;">&#93;</span> description<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>I dont know if it is a good way for you to use SOAP Web Services via JSON-RPC Bridge, but this method saved me so much time rather than preparing SOAP Envelopes in Objective-C.</p>
<p>I hope you enjoy <img src="http://blog.alkimake.com/wp-includes/images/smilies/simple-smile.png" alt=":)" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p>PS. Java Web Application project can be found here <a href="http://blog.alkimake.com/wp-content/uploads/2009/09/TempConvertBridge.zip">TempConvertBridge Project</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.alkimake.com/2009/09/json-rpc-bridge-to-xml-web-services-and-usage-in-objective-c-in-iphone/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Ready to write a blog :)</title>
		<link>http://blog.alkimake.com/2009/09/ready-to-write-a-blog/</link>
		<comments>http://blog.alkimake.com/2009/09/ready-to-write-a-blog/#comments</comments>
		<pubDate>Wed, 09 Sep 2009 12:38:13 +0000</pubDate>
		<dc:creator><![CDATA[Alkım Gözen]]></dc:creator>
				<category><![CDATA[Stuff]]></category>
		<category><![CDATA[Alkimake]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[Fun]]></category>

		<guid isPermaLink="false">http://blog.alkimake.com/?p=1</guid>
		<description><![CDATA[After i quit my job, i start to do some good things for myself. This blog is one of them. I am not planning writing down posts in a specific area. I will share mostly code in here but, i am gonna write some stuff about my life 
I hope you enjoy.
]]></description>
				<content:encoded><![CDATA[<p>After i quit my job, i start to do some good things for myself. This blog is one of them. I am not planning writing down posts in a specific area. I will share mostly code in here but, i am gonna write some stuff about my life <img src="http://blog.alkimake.com/wp-includes/images/smilies/simple-smile.png" alt=":)" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p>I hope you enjoy.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.alkimake.com/2009/09/ready-to-write-a-blog/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
