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

Silverligh訪問數(shù)據(jù)庫方法技巧指導(dǎo)

開發(fā) 開發(fā)工具
Silverligh訪問數(shù)據(jù)庫雖然不能夠以直接的方式進行,但是我們可以通過其他的方式來實現(xiàn)這一功能。在這里就為大家介紹一下相關(guān)實現(xiàn)方法。

Silverligh的應(yīng)用范圍比較廣泛。在開發(fā)人員實際使用中,可以輕松的實現(xiàn)各種基于多媒體方面功能。基于安全原因的考慮,Silverlight是不允許直接訪問數(shù)據(jù)庫的。但還是有很多方法來間接實現(xiàn)Silverlight對數(shù)據(jù)庫的訪問。#t#

比如以下的三種方式:1 RESTful API;2 在Silverlight下借助JavaScript來實現(xiàn)訪問數(shù)據(jù)庫;3 利用.NET Web服務(wù)模板——Silverlight-enabled。本文將主要介紹一下后倆種方法。

利用JavaScript實現(xiàn)Silverlight與數(shù)據(jù)庫的交互

只要在Silverlight事件處理的后面添加調(diào)用以下簡單的JavaScript代碼即可。其中”callWebService”是JavaScript的函數(shù)。

  1. protected void btnSubmit
    (object sender,EventArgs e)  
  2. {  
  3. System.Windows.Browser.HtmlPage.
    Window.Invoke("callWebService", null);  

關(guān)于JavaScript的調(diào)用可以參照一下內(nèi)容:

通過ScriptServiceAttribute添加

  1. [ScriptService]  
  2. public class UserValidationService: 
    System.Web.Services.WebService  
  3. {  
  4. [WebMethod]  
  5. public bool ValidateUserName
    (string strInput)  
  6. {  
  7. return !GetUserByUserName(strInput); 
    //If user exists return false 
    indicates the name is no longer availabe.  
  8. }  
  9. private bool GetUserByUserName
    (string strUserName)  
  10. {  
  11. bool blnIsUserExists = false;   
  12. //Call database API to see if the 
    username is availabe, set blnIsUser
    Exists to true if exists.  
  13. return blnIsUserExists;  
  14. }  

通過頁面添加ScriptMananger控件

  1. < asp:ScriptManager runat="server"
     ID="scriptManagerId"> 
  2. < Services> 
  3. < asp:ServiceReference Path=
    "UserValidationService.asmx" /> 
  4. < /Services> 
  5. < /asp:ScriptManager> 

像調(diào)用JavaScript局部函數(shù)一樣調(diào)用Webservice

  1. < script type="text/javascript"> 
  2. function validateUserName()  
  3. {  
  4. var userName = document.getElementById
    ("txtUserName").value;  
  5. UserValidationService.ValidateUserName
    (userName,showValidateResult,validate
    UserNameError);  
  6. }   
  7. function validateUserNameError(result)  
  8. {  
  9. //Do nothing if any error, ideally, 
    we should log this error to database.  
  10. }  
  11. function showValidateResult(result)  
  12. {  
  13. //Since it is only a boolean value, 
    no need to get result.d, if result 
    contains .net object,  
  14. // use result.length and result.d 
    to retrieve the object.  
  15. if(!result)  
  16. {   
  17. //Not available  
  18. }else  
  19. {  
  20. //Username is still available  
  21. }  
  22. }  
  23. < /script> 

利用Silverlight-enabled Webservice實現(xiàn)Silverlight與數(shù)據(jù)庫的交互

首先通過模板創(chuàng)建一個Silverlight-enabled Webservice,然后將數(shù)據(jù)庫和其他Server-related添加到服務(wù)里。接下來,將此服務(wù)添加引用到Silverlight 應(yīng)用中。***利用如下代碼從Silverlight 應(yīng)用中調(diào)用webservice。

  1. using MySilver.MyService;  
  2. ......  
  3. .....  
  4. private void btnSend_Click
    (object sender, RoutedEventArgs e)  
  5. {  
  6. if (!String.IsNullOrEmpty
    (txtMessage.Text.Trim()))   
  7. {  
  8. lstHisotryMessage.Items.Add("Gene: " 
    + txtMessage.Text.Trim());   
  9. GeneMessage message = new GeneMessage();   
  10. message.Body = txtMessage.Text.Trim();  
  11. MyServiceclient = new MyService();   
  12. client.SendMessageCompleted += 
    new EventHandler
    < SendMessageCompleted
    EventArgs
    >(client_SendMessageCompleted);   
  13. client.SendMessageAsync(message);  
  14. }  
  15. else  
  16. {  
  17. MessageBox.Show("You cannot send empty message!");   
  18. }  
  19. }  
  20. protected void client_SendMessage
    Completed(object sender, SendMessage
    CompletedEventArgs e)  
  21. {  
  22. txtMessage.Text = e.Result.MessageID.ToString(); 

 

責(zé)任編輯:曹凱 來源: IT168
相關(guān)推薦

2011-03-07 17:35:09

JavaACCESS數(shù)據(jù)庫

2011-04-13 14:07:17

OracleSybase數(shù)據(jù)庫

2011-03-04 14:13:02

MySQL數(shù)據(jù)庫

2011-01-21 11:12:01

Spring

2011-03-10 11:17:03

數(shù)據(jù)庫設(shè)計技巧

2010-01-18 17:45:33

VB.NET線程訪問數(shù)

2011-03-29 12:59:53

SilverlightWCF RIA Ser訪問數(shù)據(jù)庫

2011-06-24 15:57:35

SQL AzureDAC

2011-03-22 16:31:35

Access數(shù)據(jù)庫

2010-05-12 17:45:03

MySQL數(shù)據(jù)庫引擎

2010-11-03 11:36:53

訪問DB2表

2011-03-16 17:26:22

動態(tài)數(shù)據(jù)庫

2013-11-26 09:47:47

ORM

2009-09-15 10:02:44

Linq to SQL

2010-05-20 14:52:42

MySQL數(shù)據(jù)庫

2011-03-03 11:07:57

Spring數(shù)據(jù)庫訪問ORM

2009-07-02 09:35:02

hibernate訪問

2010-01-26 16:55:35

Android數(shù)據(jù)庫操

2011-04-12 09:43:17

Sybase數(shù)據(jù)庫修復(fù)技巧

2010-11-29 11:51:59

Sybase數(shù)據(jù)庫維護
點贊
收藏

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