{"id":18,"date":"2008-06-22T13:17:45","date_gmt":"2008-06-22T20:17:45","guid":{"rendered":"http:\/\/www.nayansavla.com\/blog\/?p=18"},"modified":"2008-06-22T13:17:45","modified_gmt":"2008-06-22T20:17:45","slug":"cairngorm-and-web-services","status":"publish","type":"post","link":"https:\/\/www.nayansavla.com\/blog\/?p=18","title":{"rendered":"Cairngorm and Web Services"},"content":{"rendered":"<p>I had to use Cairngorm where the data was coming from web services and i had little trouble initially setting up services in my command class. But after a few tries and misses i was able to get web services to work. This is how i have implemented it.<\/p>\n<p>Service class just defines a webservice as follows,<\/p>\n<p><mx :WebService id=\"signUpService\" showBusyCursor=\"true\" useProxy=\"false\" wsdl=\"http:\/\/serviceserver\/Webservices\/SignupService.asmx?wsdl\" \/>\u00a0<\/p>\n<p>Pretty straightforward and the services are global so any changes in the server can be easily changed. Now the execute method of the command class which calls this service looks like this.<\/p>\n<p>\u00a0<\/p>\n<div class=\"codecolorer-container actionscript default\" style=\"overflow:auto;white-space:nowrap;width:435px;height:300px;\"><div class=\"actionscript codecolorer\"><span class=\"kw3\">public<\/span> <span class=\"kw2\">function<\/span> execute<span class=\"br0\">&#40;<\/span>event:CairngormEvent<span class=\"br0\">&#41;<\/span>:<span class=\"kw3\">void<\/span> <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw2\">var<\/span> service:WebService;<br \/>\n&nbsp; &nbsp; <span class=\"kw2\">var<\/span> operation:Operation;<br \/>\n&nbsp; &nbsp; <span class=\"kw2\">var<\/span> token:AsyncToken;<br \/>\n&nbsp; &nbsp; <span class=\"kw2\">var<\/span> requestObj:<span class=\"kw3\">Object<\/span>;<br \/>\n&nbsp; &nbsp; <span class=\"kw2\">var<\/span> email:<span class=\"kw3\">String<\/span> = event.<span class=\"kw3\">data<\/span>.<span class=\"me1\">email<\/span>;<br \/>\n&nbsp; &nbsp; <span class=\"kw2\">var<\/span> <span class=\"kw3\">password<\/span>:<span class=\"kw3\">String<\/span> = event.<span class=\"kw3\">data<\/span>.<span class=\"kw3\">password<\/span>;<br \/>\n<br \/>\n&nbsp; &nbsp; service = ServiceLocator.<span class=\"me1\">getInstance<\/span><span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span>.<span class=\"me1\">getWebService<\/span><span class=\"br0\">&#40;<\/span><span class=\"st0\">&quot;signUpService&quot;<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\n<span class=\"co1\">\/\/load the wsdl file<\/span><br \/>\n&nbsp; &nbsp; service.<span class=\"me1\">loadWSDL<\/span><span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\n<br \/>\n<span class=\"co1\">\/\/we assign the operation to the function that needs to be called inside the wsdl<\/span><br \/>\n&nbsp; &nbsp; operation = service.<span class=\"me1\">getOperation<\/span><span class=\"br0\">&#40;<\/span><span class=\"st0\">&quot;GetItemsFromStore&quot;<\/span><span class=\"br0\">&#41;<\/span> as Operation;<br \/>\n<span class=\"co1\">\/\/the result format we need is e4x<\/span><br \/>\n&nbsp; &nbsp; operation.<span class=\"me1\">resultFormat<\/span> = <span class=\"st0\">&quot;e4x&quot;<\/span>;<br \/>\n<span class=\"co1\">\/\/this object will pass all the required parameters for this function<\/span><br \/>\n&nbsp; &nbsp; requestObj = <span class=\"kw2\">new<\/span> <span class=\"kw3\">Object<\/span><span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\n&nbsp; &nbsp; requestObj.<span class=\"me1\">email<\/span> = email;<br \/>\n&nbsp; &nbsp; requestObj.<span class=\"kw3\">password<\/span> = <span class=\"kw3\">password<\/span>;<br \/>\n&nbsp; &nbsp; operation.<span class=\"me1\">request<\/span> = requestObj;<br \/>\n&nbsp; &nbsp; token = operation.<span class=\"kw3\">send<\/span><span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span> as AsyncToken;<br \/>\n<span class=\"co1\">\/\/this is the line where the responder object is passed to the Asynctoken<\/span><br \/>\n&nbsp; &nbsp; token.<span class=\"me1\">addResponder<\/span><span class=\"br0\">&#40;<\/span>event.<span class=\"kw3\">data<\/span>.<span class=\"me1\">responderObj<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\n<br \/>\n<span class=\"br0\">&#125;<\/span><\/div><\/div>\n<p>Disclaimer: The above code is a copy paste and then modified so please forgive the coding style.<\/p>\n<p>Now the fault or the result method of our responderObj will be called accordingly.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I had to use Cairngorm where the data was coming from web services and i had little trouble initially setting up services in my command class. But after a few tries and misses i was able to get web services to work. This is how i have implemented it. Service class just defines a webservice [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[21,66,25],"class_list":["post-18","post","type-post","status-publish","format-standard","hentry","category-flex","tag-cairngorm","tag-flex","tag-web-services"],"_links":{"self":[{"href":"https:\/\/www.nayansavla.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/18","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.nayansavla.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nayansavla.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nayansavla.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nayansavla.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=18"}],"version-history":[{"count":0,"href":"https:\/\/www.nayansavla.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/18\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.nayansavla.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=18"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nayansavla.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=18"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nayansavla.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=18"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}