SreeramojuPradeep
asked on
Adobe Flex AIR--- How to call WSDL when Internet goes Down
Hi,
In my Desktop Application, I have connected the WSDL to the server using the DataServices..............
Here is the WSDL am using... http://121.243.253.109:8080/TestService/TestClassPort?wsdl
and my Code is as below..........
Initially if the Internet Connection is there, I can access the data from the server and it works fine.....
If the internet connection is not there Intially, the below values are becoming null in the service package. HowEver the I have placed the Timer to check the Internet Connection but its not working when Internet Connection is not there Initially.
_serviceControl.service = "TestClassService";
_serviceControl.port = "TestClassPort";
wsdl = "http://121.243.253.109:8080/TestService/TestClassPort?wsdl";
In my Desktop Application, I have connected the WSDL to the server using the DataServices..............
Here is the WSDL am using... http://121.243.253.109:8080/TestService/TestClassPort?wsdl
and my Code is as below..........
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
creationComplete="checkNetworkConnection()"
xmlns:testclassport="services.testclassport.*"
>
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.rpc.events.ResultEvent;
private var networkAvailable : Boolean = false;
private var timer:Timer = new Timer(5000);
private function checkNetworkConnection():void{
var request:URLRequest = new URLRequest();
request.method = "HEAD";
request.url = "http://www.google.com";
var urlLoader:URLLoader = new URLLoader();
urlLoader.addEventListener( HTTPStatusEvent.HTTP_STATUS, connectHttpStatusHandler );
urlLoader.addEventListener( IOErrorEvent.IO_ERROR, connectErrorHandler );
urlLoader.load( request);
}
private function connectHttpStatusHandler( event:HTTPStatusEvent):void
{
networkAvailable = ( event.status == 0 ? false : true );
handleNetworkChange();
}
private function connectErrorHandler(event:IOErrorEvent):void
{
networkAvailable = false;
}
private function handleNetworkChange() : void
{
if( networkAvailable ) {
init();
trace( "Online" );
} else {
timer.addEventListener(TimerEvent.TIMER,recheckInternetConnection);
timer.start();
trace( "Offline" );
}
}
private function recheckInternetConnection(event:TimerEvent):void{
timer.removeEventListener(TimerEvent.TIMER,recheckInternetConnection);
checkNetworkConnection();
}
private function init():void{
getTestResult.token = testClassPort.getTest();
}
[Bindable]
private var getStr:String;
protected function testClassPort_resultHandler(event:ResultEvent):void
{
getStr = event.result.toString();
}
]]>
</fx:Script>
<fx:Declarations>
<s:CallResponder id="getTestResult"/>
<testclassport:TestClassPort id="testClassPort"
result="testClassPort_resultHandler(event)"
fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)" showBusyCursor="true"/>
</fx:Declarations>
<mx:Label id="str" text="{getStr}" />
</s:WindowedApplication>
Initially if the Internet Connection is there, I can access the data from the server and it works fine.....
If the internet connection is not there Intially, the below values are becoming null in the service package. HowEver the I have placed the Timer to check the Internet Connection but its not working when Internet Connection is not there Initially.
_serviceControl.service = "TestClassService";
_serviceControl.port = "TestClassPort";
wsdl = "http://121.243.253.109:8080/TestService/TestClassPort?wsdl";
You may need to implement reconnect button or popup login window for reestablish a server session.
ASKER
However i have set the timer to check internet connection....so when the connection is up it automaticaaly calls the services...so what is the the point of reconnect button...
For example you are using Java as webserver. By default Java stores user session maximum 30 minutes. So, your timer will ping dead connection every 1000 ms, but user will not able to continue working on your website, until pass authentication. If you are doing test application, you can use your approach but in commercial applications we are using user session
ASKER
But we are developing desktop application pertaining to individuals.....
So using sessions????...
Handling the same when no internet connection on application start up the wsdl services will not be called...even if timer is placed ......
So using sessions????...
Handling the same when no internet connection on application start up the wsdl services will not be called...even if timer is placed ......
No, doesn't matter you are using AIR, Browser SWF, JavaScript on backend JSP, Java, Java Servlets always creating user session
http://sujitreddyg.wordpress.com/2008/05/16/session-data-management-in-flex-remoting/
http://sujitreddyg.wordpress.com/2008/05/16/session-data-management-in-flex-remoting/
ASKER
Hi,
I agree with ur session concept ......
But i am calling web services at the application startup itself...when net conection is down on startup i am not able to call any web services (WSDL) once the net connection is up...
I have sent my appln source code via mail to make u clear what problem actually i am facing....
Can u pls let me know where i go wrong...
I agree with ur session concept ......
But i am calling web services at the application startup itself...when net conection is down on startup i am not able to call any web services (WSDL) once the net connection is up...
I have sent my appln source code via mail to make u clear what problem actually i am facing....
Can u pls let me know where i go wrong...
ASKER
Hi Gofman,
You told me to use loadWSDL(uri:String = null):void .......
Here in Flash builder IDE, am selecting Data from Main menu then am going into Connect to Data/Services
from there if I give the WSDL, automatically a package is generating
Here is the packages that is generated
where I need to use loadWSDL() so that I can access the services once the Internet is up.......
You told me to use loadWSDL(uri:String = null):void .......
Here in Flash builder IDE, am selecting Data from Main menu then am going into Connect to Data/Services
from there if I give the WSDL, automatically a package is generating
Here is the packages that is generated
_Super_TestClassPort.as
/**
* This is a generated class and is not intended for modification. To customize behavior
* of this service wrapper you may modify the generated sub-class of this class - TestClassPort.as.
*/
package services.testclassport
{
import com.adobe.fiber.core.model_internal;
import com.adobe.fiber.services.wrapper.WebServiceWrapper;
import com.adobe.serializers.utility.TypeUtility;
import mx.rpc.AbstractOperation;
import mx.rpc.AsyncToken;
import mx.rpc.soap.mxml.Operation;
import mx.rpc.soap.mxml.WebService;
[ExcludeClass]
internal class _Super_TestClassPort extends com.adobe.fiber.services.wrapper.WebServiceWrapper
{
// Constructor
public function _Super_TestClassPort()
{
// initialize service control
_serviceControl = new mx.rpc.soap.mxml.WebService();
var operations:Object = new Object();
var operation:mx.rpc.soap.mxml.Operation;
operation = new mx.rpc.soap.mxml.Operation(null, "getTest");
operation.resultElementType = String;
operations["getTest"] = operation;
_serviceControl.operations = operations;
try
{
_serviceControl.convertResultHandler = com.adobe.serializers.utility.TypeUtility.convertResultHandler;
}
catch (e: Error)
{ /* Flex 3.4 and eralier does not support the convertResultHandler functionality. */ }
_serviceControl.service = "TestClassService";
_serviceControl.port = "TestClassPort";
_serviceControl.wsdl = "http://121.243.253.109:8080/TestService/TestClassPort?wsdl";
_serviceControl.loadWSDL();
model_internal::loadWSDLIfNecessary();
model_internal::initialize();
}
/**
* This method is a generated wrapper used to call the 'getTest' operation. It returns an mx.rpc.AsyncToken whose
* result property will be populated with the result of the operation when the server response is received.
* To use this result from MXML code, define a CallResponder component and assign its token property to this method's return value.
* You can then bind to CallResponder.lastResult or listen for the CallResponder.result or fault events.
*
* @see mx.rpc.AsyncToken
* @see mx.rpc.CallResponder
*
* @return an mx.rpc.AsyncToken whose result property will be populated with the result of the operation when the server response is received.
*/
public function getTest() : mx.rpc.AsyncToken
{
model_internal::loadWSDLIfNecessary();
var _internal_operation:mx.rpc.AbstractOperation = _serviceControl.getOperation("getTest");
var _internal_token:mx.rpc.AsyncToken = _internal_operation.send() ;
return _internal_token;
}
}
}
where I need to use loadWSDL() so that I can access the services once the Internet is up.......
TestClassPort.as
/**
* This is a generated sub-class of _TestClassPort.as and is intended for behavior
* customization. This class is only generated when there is no file already present
* at its target location. Thus custom behavior that you add here will survive regeneration
* of the super-class.
**/
package services.testclassport
{
public class TestClassPort extends _Super_TestClassPort
{
}
}
Try comment your services from MXML
<!--testclassport:TestClas sPort id="testClassPort"
result="testClassPort_resu ltHandler( event)"
fault="Alert.show(event.fa ult.faultS tring + '\n' + event.fault.faultDetail)" showBusyCursor="true"/-->
and create using ActionScript
import mx.controls.Alert;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import services.testclassport.Tes tClassPort ;
private function init():void{
var testClassPort:TestClassPor t = new TestClassPort();
testClassPort.showBusyCurs or = true;
testClassPort.addEventList ener(Resul tEvent.RES ULT, testClassPort_resultHandle r);
testClassPort.addEventList ener(Fault Event.FAUL T, function(event:FaultEvent) :void{
Alert.show(event.fault.fau ltString + '\n' + event.fault.faultDetail)
});
getTestResult.token = testClassPort.getTest();
}
Is the same as MXML
<!--testclassport:TestClas
result="testClassPort_resu
fault="Alert.show(event.fa
and create using ActionScript
import mx.controls.Alert;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import services.testclassport.Tes
private function init():void{
var testClassPort:TestClassPor
testClassPort.showBusyCurs
testClassPort.addEventList
testClassPort.addEventList
Alert.show(event.fault.fau
});
getTestResult.token = testClassPort.getTest();
}
Is the same as MXML
ASKER
This solved my problem....
But when net connection is disabled after calling init() method...how to handle the net connectivity in such cases....is there any way in which we can handle this issue of calling different web services.....
Internet connectivity becomes major issue at this point.. how to handle ?????/
But when net connection is disabled after calling init() method...how to handle the net connectivity in such cases....is there any way in which we can handle this issue of calling different web services.....
Internet connectivity becomes major issue at this point.. how to handle ?????/
ASKER
Can the above issue handled...since mine is a air application handling checking remote server reachable is very important....
The solution u gave was very much ok...
But if server is not reachable in between the init() method....
Any alternative way to be used??????????
The solution u gave was very much ok...
But if server is not reachable in between the init() method....
Any alternative way to be used??????????
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.