2012-01-30 34 views

回答

2

我用這個代碼,但我不知道,最好的解決辦法是什麼

服務器端

public string GetUserPhoto(string Username) 
      { 
      byte[] Photo = DomainController.GetUserPhoto(Username); 

      StringBuilder hex = new StringBuilder(Photo.Length * 2); 
      foreach (byte b in Photo) 
       hex.AppendFormat("{0:x2}", b); 
      return hex.ToString(); 

      } 

客戶端

InvokeOperation<string> InvokeOp = context.GetUserPhoto(username); 
     InvokeOp.Completed += (s, e) => 
      { 
      if (!InvokeOp.HasError) 
      { 
       string photo = ((InvokeOperation<string>)s).Value; 

       int NumberChars = photo.Length; 
       byte[] bytes = new byte[NumberChars/2]; 
       for (int i = 0; i < NumberChars; i += 2) 
       bytes[i/2] = Convert.ToByte(photo.Substring(i, 2), 16); 

       _UserPhoto = bytes; 

       onPropertyChanged("UserPhoto"); 
      } 
      }; 
+0

是的,我知道我可以簡單地只是將字節或字符串返回給客戶端,讓客戶端按照自己想要的方式使用內容,或創建文件等。我想我很想知道如何做到這些,以便我可以將服務器上的字節流式傳輸到客戶端,有客戶t處理字節,因爲它們以塊形式進入。除非我錯過了某些東西,否則我沒有看到任何使用RIA的本地方式。 – user1060500 2012-01-31 14:59:12

相關問題