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

 

[置顶] Silverlight调用一般性处理程序模拟Silverlight调用WCF效果(2)

分类: 技术 548人阅读 评论(0) 收藏 举报

代码下载

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

 代码下载

 
@原文引入:http://blog.csdn.net/zhaoyu_1979/article/details/7415218
原文地址:https://www.cnblogs.com/meimao5211/p/3276793.html