We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

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

SreeramojuPradeep
on
Medium Priority
1,186 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";



Comment
Watch Question

Top Expert 2011

Commented:
You may need to implement reconnect button or popup login window for reestablish a server session.

Author

Commented:
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...
Top Expert 2011

Commented:
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

Author

Commented:
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 ......



Top Expert 2011

Commented:
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/

Author

Commented:
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...


 

Author

Commented:
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

Top Expert 2011

Commented:
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

Author

Commented:
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 ?????/

Author

Commented:
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??????????
Top Expert 2011
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.