Avg. Rating 3.2

Problem

There is a shortcoming in the documentation of how to consume web services that use documented-oriented WSDL's.

Solution

Here is a sample "login" web service that executes a document-oriented operation.

Detailed explanation



import mx.rpc.soap.WebService;
import mx.rpc.events.ResultEvent;
import mx.rpc.events.FaultEvent;

private var sessionID:String = new String( '' );
// Login user
public function login(event:flash.events.Event): void
{
// create login object with 'UserID' and 'Password' properties.
var login:Object = new Object();
login.UserID = userID_txt.text.toUpperCase();
login.Password = password_txt.text.toUpperCase();


// define the loginWS web service, load the wsdl
// and then execute the operation, passing to it
// the above defined login object.
loginWS.useProxy = false ;
loginWS.LoginOperation.addEventListener( "result" , loginResultHandler);
loginWS.LoginOperation.resultFormat = 'e4x' ;
loginWS.addEventListener( "fault" , loginFaultHandler);
loginWS.loadWSDL( 'https://www.mydomain.com/Login.wsdl' );
loginWS.LoginOperation(login);
}


// Handle results from login web service
private function loginResultHandler(event:ResultEvent): void
{
// retrieve web service results
var xmlDoc:XML = new XML(loginWS.LoginOperation.lastResult);
sessionID = xmlDoc.*::User.@Session;
}


// Handle faults from login web service
private function loginFaultHandler(event:FaultEvent): void
{
Alert.show( "Some error message here.");
}

The primary difference between rpc and document-oriented operations is found in how the operation is invoked. An rpc operation would be executed as:

 loginWS.LoginOperation(userID_txt.text, password_txt.text);

 However, with a document-oriented operation, you must first construct an object, add the parameters you wish to pass to the operation as properties, and then pass the object to the operation, as demonstrated in the first code block above, and reiterated here:



// create login object with 'UserID' and 'Password' properties.
var login:Object = new Object();
login.UserID = userID_txt.text.toUpperCase();
login.Password = password_txt.text.toUpperCase();
.
.
.
loginWS.LoginOperation(login);

 

Ron Grimes

Report abuse

Related recipes