日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
WCF服務(wù)契約開發(fā)實踐

WCF是由微軟公司開發(fā)的一款.NET Framework 3.5的重要組成部件,它的影音方式很多,有很多重要的功能值得我們?nèi)ド钊胙芯?。比如今天為大家介紹的WCF服務(wù)契約就是其中一個比較重要的應(yīng)用知識。

一個WCF服務(wù)契約是一個用元數(shù)據(jù)屬性[ServiceContract]修飾的.NET接口或類。每個WCF服務(wù)可以有一個或多個契約,每個契約是一個操作集合。

首先我們定義一個.NET接口:IStuServiceContract,定義兩個方法分別實現(xiàn)添加和獲取學(xué)生信息的功能

 
 
 
  1. void AddStudent(Student stu);stuCollection GetStudent(); 

用WCF服務(wù)契約模型的元數(shù)據(jù)屬性ServiceContract標(biāo)注接口IStuServiceContract,把接口設(shè)計為WCF契約。用OperationContract標(biāo)注AddStudent,GetStudent

GetStudent()返回一個類型為stuCollection類型的集合。AddStudent()需要傳入Student實體類作為參數(shù)。

 
 
 
  1. namespace WCFStudent  
  2. {  
  3. [ServiceContract]  
  4. public interface IStuServiceContract  
  5. {  
  6. [OperationContract]  
  7. void AddStudent(Student stu);  
  8. [OperationContract]  
  9. stuCollection GetStudent();  
  10. }  
  11. [DataContract]  
  12. public class Student  
  13. {  
  14. private string _stuName;  
  15. private string _stuSex;  
  16. private string _stuSchool;  
  17. [DataMember]  
  18. public string StuName  
  19. {  
  20. get { return _stuName; }  
  21. set { _stuName = value; }  
  22. }  
  23. [DataMember]  
  24. public string StuSex  
  25. {  
  26. get { return _stuSex; }  
  27. set { _stuSex = value; }  
  28. }  
  29. [DataMember]  
  30. public string StuSchool  
  31. {  
  32. get { return _stuSchool; }  
  33. set { _stuSchool = value; }  
  34. }  
  35. }  
  36. public class stuCollection : List 
  37. {  
  38. }  

WCF服務(wù)契約和客戶交換SOAP信息。在發(fā)送端必須把WCF服務(wù)和客戶交互的數(shù)據(jù)串行化為XML并在接收端把XML反串行化。因此客戶傳遞給AddStudent操作的Student對象也必須在發(fā)送到服務(wù)器之前串行化為XML。WCF默認(rèn)使用的是一個XML串行化器DataContractSerializer,用它對WCF服務(wù)和客戶交換的數(shù)據(jù)進(jìn)行串行化和反串行化。


網(wǎng)頁標(biāo)題:WCF服務(wù)契約開發(fā)實踐
地址分享:http://www.5511xx.com/article/dhgcjio.html