移动终端如果不想使用WCF,也可以调用一般性处理程序模拟对服务器数据调用。
Silverlight调用一般性处理程序模拟Silverlight调用WCF效果避免跨域访问问题
实现关键技术代码如下:
1.Web建立一般性处理程序
public class Handler1 : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
string username = context.Request["UserName"];
string psw = context.Request["Psw"];
if (username == "Admin" && psw == "123")
{
context.Response.Write("登陆成功");
}
else
{
context.Response.Write("登陆失败");
}
}
}
2.Silverlight客户端异步调用
private void btnLogin_Click(object sender,RoutedEventArgs e)
{
WebClient wb = new WebClient();
wb.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wb_DownloadStringCompleted);
wb.DownloadStringAsync(new Uri("http://localhost:8888/Handler1.ashx?UserName=" + this.txtUserName.Text + "&Psw=" + this.txtPsw.Password));
}
void wb_DownloadStringCompleted(object sender,DownloadStringCompletedEventArgs e)
{
MessageBox.Show(e.Result.ToString());
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。