本篇随笔主要是关于flex与asp.net的webservice通讯,其中利用了soapheader。(如果你对soapheader不了解,可以参考webservice开发(一) 如何使用soap头)。由此可见webservice在跨平台方面的优势。
asp.net的webservice代码
using system;
using system.web;
using system.web.services;
using system.web.services.protocols;
[webservice(namespace = "http://davidfan.cnblogs.com")]//名称空间应该和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 "请提供验证信息.";
}
else
{
if (header.name == "admin" && header.password == "admin")
{
if (header.exdate < datetime.now)
{
return "帐号过期";
}
else
{
return "验证成功";
}
}
else
{
return "用户名或密码错误";
}
}
}
}
/**//// <summary>
/// 继承自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; }
}
}
flex的mxml、as代码
mxml
as
新闻热点
疑难解答
图片精选