winphone调用一般处理程序

来源:互联网 发布:视频特技制作软件 编辑:程序博客网 时间:2024/04/28 18:16

转自: Silverlight调用一般性处理程序模拟Silverlight调用WCF效果(2)

移动终端如果不想使用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());
        }

原创粉丝点击