Swiz Framework : Invoking a WebService call

On June 6, 2010, in Flex, by Anuj Gakhar

As I blogged before, I spent the weekend trying to get my head around Swiz framework. The project I did uses HTTPService and WebService calls to fetch data into the UI. While this sounds pretty straightforward, I came across a little gotcha which I thought I should blog about here.

So, in my Beans.mxml I have defined this Webservice like this:-

<mx:WebService
wsdl="http://url.cfc?wsdl"
id="linkService"
showBusyCursor="true" />

And in my Controller, I have this :-

        [Mediate("GetLinkEvent.GET_LINK", properties="_item" )]
        public function getLinksByObject(item:String) : void
        {
        	executeServiceCall( delegate.getLinksByObject( item ), getLinksHandler );
        }
       private function getLinksHandler( event : ResultEvent ):void{}

and in my Delegate,

    	[Inject(source="linkService")]
    	public var linkService:WebService;

		public function getLinksByObject(_item:String):AsyncToken
		{
			//send the request
			return this.linkService.getLinksByObject(_item);
		}

The problem I faced was that getLinksHandler() was never being called. Although the code looks alright, whats missing is that the Webservice’s load() method had never been called, because of which Swiz silently fails to perform the webservice call. I simply added the following line of code to load the WSDL before the method invocation and that seemed to do the trick.

		public function getLinksByObject(_item:String):AsyncToken
		{
			//send the request
			this.linkService.loadWSDL();
			return this.linkService.getLinksByObject(_item);
		}

By calling the loadWSDL() before the actual call, things start to work as normal but I was hoping that this would be taken care of by the framework itself. If someone knows of a solution to this, please let me know.

Tagged with:  

4 Responses to Swiz Framework : Invoking a WebService call

  1. Brian Kotek says:

    I’ve updated the Swiz FAQ to explain this (http://swizframework.jira.com/wiki/display/SWIZ/FAQ#FAQ-IdefinedaWebServiceobjectinmyBeans.mxml%2Cbutmywebservicecallsdon%27tseemtowork.What%27swrong%3F). But the quick explanation is that Flex only loads the WSDL if you declare the WebService in a display object. Since BeanProvider is not a display object, you need to load the WSDL using loadWSDL() before you can use it, since it’s using the AS3 implementation of the WebService. Hope that helps explain what’s going on. Thanks.

  2. Anuj Gakhar says:

    @Brian, thanks for the explanation. Isnt there a way BeanLoader checks for a WebService and loads the wsdl? Just wondering…

  3. Brian Kotek says:

    Hi Anuj, no it doesn’t. It might be possible to add something like that, but since there are numerous classes in the Flex SDK with MXML and AS implementations, we probably don’t want to start down the road of trying to invisibly trigger behavior on the beans. The simpler option would be for you to simply extend BeanProvider and add whatever logic you’d like to your custom implementation.

  4. Anuj Gakhar says:

    Yeah that makes sense. Thanks again. 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 446 other subscribers

© 2011 Anuj Gakhar
%d bloggers like this: