Flex Web Service Simple / Complex Data Type

Let's say you want to invoke a WCF/ASMX web service using Flex and you need to pass in simple and also complex data type.

This is my web service (I'm using ASMX) . SayHi requires Username parameter of type string. While Welcome method uses a complex data type as its parameter.


[WebMethod]
public void SayHi (string Username )
{

}

[WebMethod]
public void Welcome(Person p)
{

}


public class Person
{
public string Name { get; set; }

public string Ability { get; set; }

}

To show how it is called in Flex just use the following MXML code



With MXML :








function InvokeService():void
{
svcTest.SayHi("Jeremy");
}


function InvokeComplexType():void
{
var p = new Person();
p.Name = "Jeremy";
p.Ability = "Coder";
svcTest.Welcome(p);
}



Using Actionscripts

The code here is almost the same with MXML markup.

function InvokeService():void
{
var ws:WebService = new WebService();
ws.wsdl ="http://localhost:2400/TestTest.asmx?wsdl";
ws.useProxy = false;
ws.loadWSDL();
ws.SayHi("Jeremy");
}

function InvokeComplexService():void
{

var p = new Person();
p.Name = "Jeremy2";
p.Ability = "Coder2";

var ws:WebService = new WebService();
ws.wsdl ="http://localhost:2400/Takedown2/Test.asmx?wsdl";
ws.useProxy = false;
ws.loadWSDL();

ws.Welcome(p);
}

Comments

Popular posts from this blog

The specified initialization vector (IV) does not match the block size for this algorithm