[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Problem with Flex and .net Web service

Posted on 2008-02-08
6
Medium Priority
?
1,053 Views
Last Modified: 2012-05-05
I need to pass 3 queryString parameters (via Url) to the Flex generated page.
Flex page (swf - flash file) needs to send it to .net web service in the background - which will then post back data based on parameters.

Im not good at Flex, I created web service and its working fine, but I have trouble sending parameters from Flex.

0
Comment
Question by:amaimedia
  • 3
  • 3
6 Comments
 
LVL 17

Expert Comment

by:julianopolito
ID: 20855361
send your code , I'll take a look for you. Here is an example:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application 
	xmlns:mx="http://www.adobe.com/2006/mxml" 
	layout="vertical" 
	verticalAlign="middle"
	creationComplete="initApp()">
	<mx:Script>
		<![CDATA[
 
			import mx.controls.Alert;
			import mx.collections.ArrayCollection;
			import mx.rpc.events.FaultEvent;
			import mx.rpc.events.ResultEvent;
			
			[Bindable]
			private var contatos:ArrayCollection;
			
			private function initApp():void{
				//Here is the call to the webservice method
				agendaService.GetByNames("param1","param2","param3");
			}
			private function resultHandler(e:ResultEvent):void{
				if(e.result is ArrayCollection){
					contatos = e.result as ArrayCollection;
				}
			}
			private function faultHandler(e:FaultEvent):void{
				Alert.show(e.fault.faultCode,e.fault.faultString);
			}
		]]>
	</mx:Script>
	
	<mx:WebService id="agendaService"
		wsdl="http://localhost:8082/WebService/Service.asmx?WSDL"
		showBusyCursor="true"
		result="resultHandler(event)"
		fault="faultHandler(event)">		
	</mx:WebService>
</mx:Application>

Open in new window

0
 

Author Comment

by:amaimedia
ID: 20855430
Ok, here it is:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"
	backgroundColor="#eeeeee" creationComplete="initVars()">
	
	    <mx:Script><![CDATA[
	    	import mx.rpc.events.ResultEvent;
			import com.imedia.QueryString;
			import mx.collections.ArrayCollection;
 
        // Declare bindable properties in Application scope.
        [Bindable]
        public var sym:String;
        [Bindable]
        public var dtS:String;
        [Bindable]
        public var dtE:String;
        [Bindable]
        private var myData:ArrayCollection;
        
        
	private var qs:QueryString;
 
        // Assign values to new properties.
        private function initVars():void {
	   qs = new QueryString();
	   trace(qs.url);
        }
   
       	private function dataHandler(event:ResultEvent):void
	   {
	   		myData = event.result.diffgram.NewDataSet.Table;
	   }
	   
    ]]></mx:Script>
	
	<mx:WebService id="serviceOne"
	wsdl="http://www.stockwatch.ws/srvcs/flexServ.asmx?WSDL" 
	showBusyCursor="true">
	<mx:operation name="returnSymbol" result="dataHandler(event)"/>
	</mx:WebService>
	
	<mx:VBox>
    <mx:HBox>
    	<mx:DataGrid dataProvider="{myData}"/>
    </mx:HBox>
    <mx:HBox>
    	<mx:Button label="get it" click="serviceOne.returnSymbol(sym,dtS,dtE)"/>
    </mx:HBox>
    </mx:VBox>
 
</mx:Application>

Open in new window

0
 

Author Comment

by:amaimedia
ID: 20855449
I have also class named QueryString in package com.imedia - here is code:
package com.imedia 
{
	import flash.external.*;
	import flash.utils.*;
 
	public class QueryString 
	{
 
		private var _queryString:String;
		private var _all:String;
		private var _params:Object;
		
		public function get queryString():String
		{
			return _queryString;
		}
		public function get url():String
		{
			return _all;
		}
		public function get parameters():Object
		{
			return _params;
		}		
 
		
		public function QueryString()
		{
		
			readQueryString();
		}
 
		private function readQueryString():void
		{
			_params = {};
			try 
			{
				_all =  ExternalInterface.call("window.location.href.toString");
				_queryString = ExternalInterface.call("window.location.search.substring", 1);
				if(_queryString)
				{
				
					var params:Array = _queryString.split('&');
					var length:uint = params.length;
					
					for (var i:uint=0,index:int=-1; i<length; i++) 
					{
						var kvPair:String = params[i];
						if((index = kvPair.indexOf("=")) > 0)
						{
							var key:String = kvPair.substring(0,index);
							var value:String = kvPair.substring(index+1);
							_params[key] = value;
						}
					}
				}
			}catch(e:Error) { trace("Some error occured. ExternalInterface doesn't work in Standalone player."); }
		}
 
	}
}

Open in new window

0
Live webcast with Pinal Dave

Pinal Dave will teach you tricks to help identify the real root cause of database problems rather than red herrings. Attendees will learn scripts that they can use in their environment to immediately figure out their performance Blame Shifters and fix them quickly.

 
LVL 17

Expert Comment

by:julianopolito
ID: 20855556
you can also use this format to specify parameters:


<mx:WebService>
		<mx:operation>
			<mx:request xmlns="">
				<param1>
					{param1}
				</param1>
				<param2>
					{param2}
				</param2>
			</mx:request>
		</mx:operation>
	</mx:WebService>

Open in new window

0
 
LVL 17

Accepted Solution

by:
julianopolito earned 2000 total points
ID: 20855939
let me see if I understand it better. I re-read your post and got some new info here. I'll rephrase and you tell me if I'm right.

You need to learn how to get parameters that come from the url into flex, use those as parameters for the webservice call, is that correct? Can you zip and send me all the files, including html where you publish the swf?

Anyway, reading your code again, I just saw that you already get the url string and it's parameters, and you just need to put them into the method call?


see if that is what you need. if not, send me the code and re explain that to me please.




// Declare bindable properties in Application scope.
        [Bindable]
        public var sym:String;
        [Bindable]
        public var dtS:String;
        [Bindable]
        public var dtE:String;
        [Bindable]
        private var myData:ArrayCollection;
        
        
	private var qs:QueryString;
 
        // Assign values to new properties.
        private function initVars():void {
	   qs = new QueryString();
            // set the bindable variables with the url parameters
            // so when you call serviceOne.returnSymbol(sym,dtS,dtE)
            // it will work
	   sym = qs.parameters.sym
            dtS = qs.parameters.dtS;
            dtE = qs.parameters.dtE;
        }

Open in new window

0
 

Author Comment

by:amaimedia
ID: 20857881
Yes, that was it. Thanks.
0

Featured Post

KuppingerCole Reviews AlgoSec in Executive Report

Leading analyst firm, KuppingerCole reviews AlgoSec's Security Policy Management Solution, and the security challenges faced by companies today in their Executive View report.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

First things first - Preparation We need all the part for this install and it's much nicer to have them all on hand when you need them so here's what's required. Download Eclipse 3.5 32 bit (I like the Classic flavour) from here. (http://www.e…
Here is a method which can be used to help resolve a "Content Index Failed" error on a Microsoft Exchange Server.
Is your organization moving toward a cloud and mobile-first environment? In this transition, your IT department will encounter many challenges, such as navigating how to: Deploy new applications and services to a growing team Accommodate employee…
The video will let you know the exact process to import OST/PST files to the cloud based Office 365 mailboxes. Using Kernel Import PST to Office 365 tool, one can quickly import numerous OST/PST files to Office 365. Besides this, the tool also comes…
Suggested Courses
Course of the Month9 days, 10 hours left to enroll

591 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question