創(chuàng)建WCF跨域交互界面
作者:佚名
由于WCF跨域交互代碼太多,這里顯示部分代碼,所以大家有communitysever的可以從里面獲得然后反編譯為自己所用,沒(méi)有的就到網(wǎng)絡(luò)上搜下吧,有許多資源呢!
接下來(lái)我們將學(xué)習(xí)WCF跨域交互各個(gè)角度出來(lái),來(lái)講述WCF跨域交互的功能,這主要包括C#3.0,VB9.0,WCF,WPF,WP,LINQ,AJAX,mobile開(kāi)發(fā),Cardspace,智能客戶(hù)端。
下面是我掃除這一障礙的一個(gè)笨得不能再笨的方法 #t#
第一步:在項(xiàng)目中創(chuàng)建一個(gè)頁(yè)面Proxy.aspx,作為ExtJs與Wcf跨域操作的代理頁(yè)面。這個(gè)頁(yè)面和ExtJs位于一個(gè)位置,并且去除頁(yè)面中的HTML代碼:
WCF跨域交互后臺(tái)代碼為:
- Proxy.aspx.cs
- using System;
- using System.Collections;
- using System.Configuration;
- using System.Data;
- using System.Linq;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.HtmlControls;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Xml.Linq;
- using System.Collections.Specialized;
- namespace ExtJs_Wcf_Linq_PageGrid
- {
- public partial class Proxy : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- string remoteUrl = Request.QueryString["remote"];
- using(System.Net.WebClient wc = new System.Net.WebClient())
- {
- NameValueCollection nvc = Request.QueryString;
- foreach (string key in nvc.Keys)
- {
- if (key != "remote")
- {
- if (remoteUrl.IndexOf("?") == -1)
- {
- remoteUrlremoteUrl = remoteUrl + "?"+key+"="+ nvc[key];
- continue;
- }
- remoteUrlremoteUrl = remoteUrl + "&" + key + "=" + nvc[key];
- }
- }
- string response = wc.DownloadString(remoteUrl);
- Response.Write(response);
- Response.End();
- }
- }
- }
- }
責(zé)任編輯:chenqingxiang
來(lái)源:
NET130