This essay is mainly about Flex and ASP.net WebService communication, which utilizes the SoapHeader. (If you don't understand soapheader, you can refer to WebService development (a) How to use the SOAP header). This shows the advantages of webservice in Cross-platform.
Asp. NET's WebService code
Using System;
Using System.Web;
Using System.Web.Services;
Using System.Web.Services.Protocols;
[WebService (Namespace = "http://davidfan.cnblogs.com")]//namespace should be the same as defined in Flex
[WebServiceBinding (ConformsTo = wsiprofiles.basicprofile1_1)]
public class Service:System.Web.Services.WebService
{
public Validatesoapheader header;
[WebMethod]
[SoapHeader ("header")]
public string HelloWorld ()
{
if (header = null)
{
Return "Please provide verification information.";
}
Else
{
if (header. Name = = "Admin" && header. Password = "admin")
{
if (header. Exdate < DateTime.Now)
{
Return "Account Expired";
}
Else
{
Return "Validation Successful";
}
}
Else
{
Return "User name or password error";
}
}
}
}
/**////<summary>
Inheriting custom classes from SoapHeader
</summary>
public class ValidateSoapHeader:System.Web.Services.Protocols.SoapHeader
{
Public Validatesoapheader ()
{
}
Public Validatesoapheader (string name, string password, DateTime dt)
{
THIS.name = name;
This.password = password;
this.exdate = DT;
}
private string name;
public string Name
{
get {return name;}
set {name = value;}
}
private string password;
public string Password
{
get {return password;}
set {password = value;}
}
Private DateTime exdate;
Public DateTime Exdate
{
get {return exdate;}
set {exdate = value;}
}
}