创建WCF跨域交互界面

接下来我们将学习WCF跨域交互各个角度出来,来讲述WCF跨域交互的功能,这主要包括C#3.0,VB9.0,WCF,WPF,WP,LINQ,AJAX,mobile开发,Cardspace,智能客户端。

下面是我扫除这一障碍的一个笨得不能再笨的方法 #t#

第一步:在项目中创建一个页面Proxy.aspx,作为ExtJs与Wcf跨域操作的代理页面。这个页面和ExtJs位于一个位置,并且去除页面中的HTML代码:

WCF跨域交互后台代码为:

 
 
  1. Proxy.aspx.cs  
  2. using System;  
  3. using System.Collections;  
  4. using System.Configuration;  
  5. using System.Data;  
  6. using System.Linq;  
  7. using System.Web;  
  8. using System.Web.Security;  
  9. using System.Web.UI;  
  10. using System.Web.UI.HtmlControls;  
  11. using System.Web.UI.WebControls;  
  12. using System.Web.UI.WebControls.WebParts;  
  13. using System.Xml.Linq;  
  14. using System.Collections.Specialized;  
  15.     
  16. namespace ExtJs_Wcf_Linq_PageGrid  
  17. {  
  18. public partial class Proxy : System.Web.UI.Page  
  19. {  
  20. protected void Page_Load(object sender, EventArgs e)  
  21. {  
  22. string remoteUrl = Request.QueryString["remote"];  
  23. using(System.Net.WebClient wc = new System.Net.WebClient())  
  24. {  
  25. NameValueCollection nvc = Request.QueryString;  
  26. foreach (string key in nvc.Keys)  
  27. {  
  28. if (key != "remote")  
  29. {  
  30. if (remoteUrl.IndexOf("?") == -1)  
  31. {  
  32. remoteUrlremoteUrl = remoteUrl + "?"+key+"="+ nvc[key];  
  33. continue;  
  34. }  
  35. remoteUrlremoteUrl = remoteUrl + "&" + key + "=" + nvc[key];  
  36. }  
  37. }  
  38. string response = wc.DownloadString(remoteUrl);  
  39. Response.Write(response);  
  40. Response.End();  
  41. }  
  42. }  
  43. }  
THE END