Import Web Service(WSDL) Wizard in Flex 3.0
Posted by shardulbartwal on March 20, 2008
Using webService In Flex 3.0 Application
Flex 3.0 provides the easiest way to use the web services. Under the ‘Data’ Menu on your Flex Builder IDE there is a submenu namely ‘Import Web Service(WSDL)’,We can use it to Directly use the Web Services.Just create a Flex Project. No need to chose any ’Applciation Server Type’ under ‘Server Technology’ title. After that just go to the Import Web Service(WSDL)’ under ‘ Data’ menu.
After clicking on this you will see like below.
Just click on the ‘Next’ button.
Now you have to enter your webService url in the box with label ‘WSDL URI‘,and after that just click on the ‘Next’ button.
Here you can change the service if you are having more than one service. Also you can change package.If you don’t want just click on ‘Finish‘. After you will click on the ‘Finsh’ button you will find a folder ‘generated’ under your ’src’ folder in your application. Under this ‘generated’ folder there you will saw a ‘webservice’ folder. Just open it and find the total conversion of your webservice in now action Script 3. Just open the ‘Service.as’ file you will find how to use these classess for retreving results from your WebService. I am just telling you the way of using it via MXML tags,you can also use these with action script. Just copy and paste the code below in you Application file,and run it to find out the result.
*******************************************************************************************
<?xml version=”1.0″ encoding=”utf-8″?>
<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml” layout=”horizontal”
xmlns:myService=”generated.webservices.*”>
<mx:Script>
<![CDATA[
import generated.webservices.*;
private var number1:int;
private var number2:int;
private function f1():void
{
number1=(int)(txtInput1.text);
number2=(int)(txtInput2.text);
}
]]>
</mx:Script>
<myService:Service id=”myService”>
<myService:multi_request_var>
<myService:Multi_request/>
</myService:multi_request_var>
</myService:Service>
<mx:VBox width=”50%” horizontalAlign=”center”>
<mx:HBox width=”100%” horizontalAlign=”center”>
<mx:Label width=”150″ text=”Enter First Number”/>
<mx:TextInput id=”txtInput1″ width=”100″ height=”30″ change=”f1()”/>
</mx:HBox>
<mx:HBox width=”100%” horizontalAlign=”center”>
<mx:Label width=”150″ text=”Enter Second Number”/>
<mx:TextInput id=”txtInput2″ width=”100″ height=”30″ change=”f1()”/>
</mx:HBox>
<mx:Button id=”myButton” label=”Call WebService” click=”myService.multi(number1,number2)”/>
<mx:Label id=”l1″ text=”{isNaN(myService.multi_lastResult)? ”: myService.multi_lastResult}” width=”150″/>
</mx:VBox>
</mx:Application>
*****************************************************************************************
Hope you will enjoy it……
Enjoy Flexing……………………..
















ali said
Dear first of thx a lot i its reallz nice exmple i have one wsdl file and flex3 also genenrate code for this but can u tell me what i have to do next how can i use first Login and password …..wsdl link than other wsdl to retrive data help me please i am very greatfull to you thanks
Alkan ARSLAN said
Thanks Shardul Singh Bartwal
Nayeli said
Hello… I’m having trouble importing a web service, every time I try I get the same error: Unable to load the WSDL. Specify another URI. I’m online… and everybody is able to import that web service, can you help me out? what can be wrong?? thanks
ngo tan cuong said
Thanks so much!
Salvador Bravo said
I have the same error as Nayeli, anybody have an idea of what could be happening?
Regards
SB
Shardul singh Bartwal said
Hi,
Salvador Bravo,
The only reason which i suppose is that you r not using wsdl with the url of your
webservice.Pls check the url of your webservice in the same format as mentioned above.
Thnx…….
Shardul S. Bartwal
Alkan ARSLAN said
text=”{isNaN(myService.multi_lastResult)? ”: myService.multi_lastResult}”
Problem
Olivier said
Hello and thanks for ur tutorial.
I’m trying to set up this kind of behavior but especillay with https web service. The problem I’m facing is that it does work well with HTTP normal WS and the wizard is telling me that he was unable to locate my WSDL file when using the HTTPS protocol.
I checked many posts and threads about the cross domain file but couldn’t fix it .
Do you have any idea ?
Olivier ROMAND
pulkit kaushik said
what is the of the option “import web service(wsdl)….”
info said
excellent flex example
Ram said
The following line got errors:
text=”{isNaN(myService.multi_lastResult)? ”: myService.multi_lastResult}”
Shardul Singh Bartwal said
It means myService.multi_lastResult is giving the value which is something undefined….
Alex Dove said
I have been working on a solution which appears like it would work fine. The source code and examples are found on Code Project http://www.codeproject.com/KB/aspnet/FlexASPWebService.aspx?msg=3270246#xx3270246xx This Flex/ASP example uses a web service to communicate to a SQL database. Flex makes a web service call to the .asmx file via WSDL and the magic happens. I am running into a roadblock as I receive an error that the app cannot find the WSDL. I have tried to run the same WSDL URL in a browser and I get an server application error.
I also am getting an error when using the example posted here. When I place my URL into the WSDL URI text box I receive an error that Flex cannot find the WSDL.
The Code for the Flex file is as follows…
Any ideas?
shardulbartwal said
Hi…….
Your flex file code is not included here.Pls add that.
Olivier said
Hi everyone,
In case some of you were still facing problem with the importation of the WSDL in Flex, in particular with HTTPS the trick is that in the case of a self signed certificate (no idea for a real certif) flex builder won’t trust it.
So you have to add it manually to the certificate repository of flex builder so it can then discuss with the server.
In the flex builder directory there’s this file so called “cacerts” which has all the certificate that flex builder accepted. When I had to use it, I played with a class Java found on the web that allow to manually accept self signed certificate. This class also re created a new repository so that I could change the one from Flex Builder
You may want to look into that direction …
Hope it might help
Olivier ROMAND