偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

WCF與ExtJs實(shí)現(xiàn)項(xiàng)目分析

開發(fā) 后端
這里就WCF與ExtJs之間的跨域訪問中實(shí)現(xiàn)的項(xiàng)目,通過(guò)Stream和ContentType的聯(lián)合使用,返回原生數(shù)據(jù)給Extjs,從而實(shí)現(xiàn)跨域調(diào)用。

大家可能對(duì)理論的知識(shí)都很熟,但是往往實(shí)踐起來(lái)就很困難,我們平時(shí)就要把實(shí)踐和理論相結(jié)合,在前面文章WCF與ExtJs之間的跨域訪問已經(jīng)通過(guò)服務(wù)端代理的方式解決了WCF與ExtJs跨域訪問的問題。

#T#那個(gè)方案看起來(lái)并不怎么優(yōu)雅,而當(dāng)我在寫過(guò)用Restful方式調(diào)用WCF進(jìn)行上傳下載后,愕然發(fā)現(xiàn)原來(lái)WCF支持原生數(shù)據(jù)(Raw)的返回,這就解決了ExtJs與Wcf之間進(jìn)行跨域調(diào)用中的難題:返回?cái)?shù)據(jù)必須滿足<script>格式。下面根據(jù)WCF與ExtJs之間的跨域訪問中實(shí)現(xiàn)的項(xiàng)目,通過(guò)Stream和ContentType的聯(lián)合使用,返回原生數(shù)據(jù)給Extjs,從而實(shí)現(xiàn)跨域調(diào)用。

***步:在PageGridService.svc后臺(tái)代碼中,添加操作契約GetProductsByPageCorssDomain,代碼為:

  1. [OperationContract]  
  2. [WebInvoke(Method = "*"ResponseFormat = WebMessageFormat.Json,  
  3. UriTemplate = "GetProductsByPageCorssDomain?start={start}&limit={limit}&callback={callback}")]  
  4. public Stream GetProductsByPageCorssDomain(int start, int limit,string callback)  
  5. {  
  6. ProductsDataContext productDbContext = new ProductsDataContext();  
  7. IQueryable<Product> res = productDbContext.Product.Select(product => product);  
  8. PageData<Product[]> returnData = new PageData<Product[]>();  
  9. returnData.TotolRecord = res.ToArray<Product>().Length;  
  10. resres = res.Skip<Product>(start);  
  11. resres = res.Take<Product>(limit);  
  12. returnData.Data = res.ToArray<Product>();  
  13. System.Runtime.Serialization.Json.DataContractJsonSerializer formater = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(PageData<Product[]>));  
  14. MemoryStream ms = new MemoryStream();  
  15. formater.WriteObject(ms, returnData);  
  16. ms.Position = 0;  
  17. StreamReader sr = new StreamReader(ms);  
  18. string objContent = sr.ReadToEnd();  
  19. string returnStr = callback+"("+objContent+")";  
  20. sr.Close();  
  21. ms = new MemoryStream();  
  22. StreamWriter sw = new StreamWriter(ms);  
  23. sw.AutoFlush = true;  
  24. sw.Write(returnStr);  
  25. ms.Position = 0;  
  26. WebOperationContext.Current.OutgoingResponse.ContentType = "text/plain";  
  27. return ms;  

第二步:在項(xiàng)目中創(chuàng)建一個(gè)新的htm頁(yè)面:PageGridCorssDomainWithRow.htm,代碼為:

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
  2. <html xmlns="http://www.w3.org/1999/xhtml" > 
  3. <head> 
  4. <title>ExtJs+WCF+LINQ打造分頁(yè)Grid</title> 
  5. <link rel="stylesheet" type="text/css" href="resources/css/ext-all.css" /> 
  6. <script type="text/javascript" src="adapter/ext/ext-base.js" charset="gb2312"></script> 
  7. <script type="text/javascript" src="ext-all-debug.js" charset="gb2312"></script> 
  8. <link rel="stylesheet" type="text/css" href="shared/examples.css" /> 
  9. <script type="text/javascript" src="shared/examples.js" charset="gb2312"></script> 
  10. <script type="text/javascript" src="PageGridCrossDomainWithRow.js" charset="gb2312"></script> 
  11. </head> 
  12. <body> 
  13. <h1> 
  14. ExtJs+WCF+LINQ打造分頁(yè)跨域Grid</h1> 
  15. <div id="page-grid"> 
  16. </div> 
  17. </body> 
  18. </html> 
責(zé)任編輯:田樹 來(lái)源: 博客
相關(guān)推薦

2021-01-20 05:46:51

自動(dòng)化Coco項(xiàng)目

2009-11-05 17:00:34

WCF有序傳遞

2023-11-30 11:45:07

大數(shù)據(jù)ODPS

2010-05-11 09:29:44

數(shù)據(jù)中心節(jié)能項(xiàng)目

2010-03-02 13:36:23

WCF事務(wù)投票

2009-11-05 14:40:08

WCF KnownTy

2010-02-25 13:48:23

WCF動(dòng)態(tài)創(chuàng)建代碼

2009-11-06 09:22:46

WCF應(yīng)用

2009-11-06 13:33:56

WCF Dispatc

2009-11-05 10:37:58

WCF Address

2010-02-26 16:20:56

WCF程序事務(wù)

2009-12-08 14:28:16

XTemplate +

2009-11-05 13:21:41

WCF架構(gòu)

2009-11-05 13:54:07

WCF Service

2009-12-08 18:31:58

WCF WEB

2009-12-21 10:00:46

WCF基礎(chǔ)開發(fā)

2012-04-20 10:05:16

WCF

2010-02-25 13:35:27

WCF tcpTrac

2010-02-24 12:49:39

WCF枚舉

2009-11-05 16:01:51

WCF單調(diào)服務(wù)
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)