[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Adobe Flex AIR---  How to call WSDL when Internet goes Down

Posted on 2011-04-25
11
Medium Priority
?
1,089 Views
Last Modified: 2012-05-11
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..........
 
<?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>

Open in new window


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";



0
Comment
Question by:SreeramojuPradeep
  • 6
  • 5
11 Comments
 
LVL 29

Expert Comment

by:dgofman
ID: 35463763
You may need to implement reconnect button or popup login window for reestablish a server session.
0
 

Author Comment

by:SreeramojuPradeep
ID: 35464624
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...
0
 
LVL 29

Expert Comment

by:dgofman
ID: 35464658
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
0
Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

 

Author Comment

by:SreeramojuPradeep
ID: 35464811
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 ......



0
 
LVL 29

Expert Comment

by:dgofman
ID: 35467855
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/
0
 

Author Comment

by:SreeramojuPradeep
ID: 35472939
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...


 
0
 

Author Comment

by:SreeramojuPradeep
ID: 35720205
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

_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;
    }
     
}

}

Open in new window


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
{

               
}

}

Open in new window

0
 
LVL 29

Expert Comment

by:dgofman
ID: 35726295
Try comment your services from MXML

<!--testclassport:TestClassPort id="testClassPort"
                                                       result="testClassPort_resultHandler(event)"
                                                       fault="Alert.show(event.fault.faultString + '\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.TestClassPort;

private function init():void{
      var testClassPort:TestClassPort = new TestClassPort();
      testClassPort.showBusyCursor = true;
      testClassPort.addEventListener(ResultEvent.RESULT, testClassPort_resultHandler);
      testClassPort.addEventListener(FaultEvent.FAULT, function(event:FaultEvent):void{
            Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)
      });
      getTestResult.token = testClassPort.getTest();
}

Is the same as MXML
0
 

Author Comment

by:SreeramojuPradeep
ID: 35726434
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 ?????/
0
 

Author Comment

by:SreeramojuPradeep
ID: 35767740
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??????????
0
 
LVL 29

Accepted Solution

by:
dgofman earned 2000 total points
ID: 35773013
I think I already gave you a solution how you can handle HTTP and Wireless  connection usign AIR


import air.net.URLMonitor;

private var monitor: URLMonitor;


private var networkAvailable:Boolean = false;
private function checkNetworkConnection():void{
     monitor = new URLMonitor(new URLRequest("http://www.google.com") );
     monitor.addEventListener(StatusEvent.STATUS, announceStatus);
     monitor.start();
}


private function announceStatus(e:StatusEvent):void {
    trace("Status change. Current status: " + monitor.available);
     if(monitor.available) {
          networkAvailable = true;
          init();
      }else{
          networkAvailable = false;
}

}
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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…
This article will help to fix the below errors for MS Exchange Server 2016 I. Certificate error "name on the security certificate is invalid or does not match the name of the site" II. Out of Office not working III. Make Internal URLs and Externa…
Integration Management Part 2
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

810 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