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

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

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
WCF消息模式基本內(nèi)容簡(jiǎn)述

WCF使用方式比較靈活,在程序員眼中,它占據(jù)著非常重要的地位。我們?cè)谶@篇文章中將會(huì)為大家詳細(xì)講解一下有關(guān)WCF消息模式的相關(guān)應(yīng)用方式,以方便大家在實(shí)際應(yīng)用中能夠獲得一些幫助。

目前成都創(chuàng)新互聯(lián)已為超過千家的企業(yè)提供了網(wǎng)站建設(shè)、域名、網(wǎng)站空間、網(wǎng)站運(yùn)營(yíng)、企業(yè)網(wǎng)站設(shè)計(jì)、新寧網(wǎng)站維護(hù)等服務(wù),公司將堅(jiān)持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長(zhǎng),共同發(fā)展。

最簡(jiǎn)單就是WCF消息模式就是方法參數(shù),所有的基本類型可以直接被序列化。我們還可以使用 MessageParameterAttribute 為參數(shù)定義消息名稱。

 
 
 
  1. [ServiceContract]
  2. public interface IContract
  3. {
  4. [OperationContract]
  5. double Add(double a, double b);
  6. [OperationContract]
  7. void Test([MessageParameter(Name="myString")]string s);
  8. }

對(duì)于WCF消息模式中的自定義類型,我們可以使用 DataContractAttribute 或 MessageContractAttribute 來定義,這些在前面的章節(jié)已經(jīng)提過,此處不再做進(jìn)一步說明。

WCF 服務(wù)方法支持 ref / out 關(guān)鍵字,也就是說底層引擎會(huì)重新為添加了關(guān)鍵字的對(duì)象賦予返回值。我們使用 "Message Logging" 和 "Service Trace Viewer" 查看一下 Reply Message。

Server.cs

 
 
 
  1. [ServiceContract]
  2. public interface IContract
  3. {
  4. [OperationContract]
  5. double Add(double a, ref double b);
  6. }
  7. public class MyService : IContract
  8. {
  9. public double Add(double a, ref double b)
  10. {
  11. b += 2;
  12. return a + b;
  13. }
  14. }

client.cs

 
 
 
  1. using (ContractClient client = new ContractClient
    (new BasicHttpBinding(), 
  2. new EndpointAddress("http://localhost:8080/myservice")))
  3. {
  4. double b = 2;
  5. double c = client.Add(1, ref b);
  6. Console.WriteLine("c={0};b={1}", c, b);
  7. }

Reply Message

 
 
 
  1. < MessageLogTraceRecord>
  2. < s:Envelope xmlns:s="http://...">
  3. < s:Header>
  4. < Action s:mustUnderstand="1" xmlns="http://...">
    http://tempuri.org/IContract/AddResponse< /Action>
  5. < /s:Header>
  6. < s:Body>
  7. < AddResponse xmlns="http://tempuri.org/">
  8. < AddResult>5< /AddResult>
  9. < b>4< /b>
  10. < /AddResponse>
  11. < /s:Body>
  12. < /s:Envelope>
  13. < /MessageLogTraceRecord>

在 Reply Message 中除了返回值 "AddResult" 外,還有 "b"。:-)

在進(jìn)行WCF消息模式的處理時(shí),需要注意的是,即便我們使用引用類型的參數(shù),由于 WCF 采取序列化傳送,因此它是一種 "值傳遞",而不是我們習(xí)慣的 "引用傳遞"??纯聪旅娴睦?,注意方法參數(shù)和數(shù)據(jù)結(jié)果的不同。

Server.cs

 
 
 
  1. [DataContract]
  2. public class Data
  3. {
  4. [DataMember]
  5. public int I;
  6. }
  7. [ServiceContract]
  8. public interface IContract
  9. {
  10. [OperationContract]
  11. void Add(Data d);
  12. [OperationContract]
  13. void Add2(ref Data d);
  14. }
  15. public class MyService : IContract
  16. {
  17. public void Add(Data d)
  18. {
  19. d.I += 10;
  20. }
  21. public void Add2(ref Data d)
  22. {
  23. d.I += 10;
  24. }
  25. }

Client.cs

 
 
 
  1. using (ContractClient client = 
    new ContractClient(new BasicHttpBinding(), 
  2. new EndpointAddress("http://localhost:8080/myservice")))
  3. {
  4. Data d = new Data();
  5. d.I = 1;
  6. client.Add(d);
  7. Console.WriteLine("d.I={0}", d.I);
  8. Data d2 = new Data();
  9. d2.I = 1;
  10. client.Add2(ref d2);
  11. Console.WriteLine("d2.I={0}", d2.I);
  12. }

輸出:

d.I=1

d2.I=11

以上就是對(duì)WCF消息模式的相關(guān)介紹。


標(biāo)題名稱:WCF消息模式基本內(nèi)容簡(jiǎn)述
網(wǎng)站鏈接:http://m.5511xx.com/article/coepodj.html