----------------------------------------------消息模式:
1.request\reply(默認)
2.one-way(單工)[Isoneway=true]
客戶端有些情況希望保證消息能正確送達;(msmq(持久性的,機子重啟后依然有效)和可靠性消息(短暫的)這兩種技術保證)
應用:日志或發布,操作需要大量時間輪訓場景,這樣不需要等待;
3.Duplex(回調;雙工)
操作必須聲明為oneway;防止發生死鎖;
回調接口不需要聲明servicecontract
tcp和命名管道支持雙工,http不支持;
--duplex案例:
--------------------------------------------雙工:
?[ServiceContract(SessionMode = SessionMode.Required, CallbackContract =typeof(IReturnuser))]
???? public interface Iuser
??? {
???????? [OperationContract(IsOneWay=true)]
???????? void SetName(string name);
??? }
???? public interface IReturnuser
???? {
???????? [OperationContract(IsOneWay = true)]
???????? void ReturnName(string name);
???? }
-----------
?[ServiceBehavior(InstanceContextMode=InstanceContextMode.PerSession)]
?? public class ServicUser:Iuser
??? {
?????? IReturnuser callback
?????? {
?????????? get { return OperationContext.Current.GetCallbackChannel<IReturnuser>(); }
?????? }
??????? public void SetName(string name)
??????? {
?????????? callback.ReturnName(name+"123");
??????? }
??? }
-----------
?public class CallbackHandler : myService.IService1Callback
??? {
??????? public void Calculate(int result)
??????? {
??????????? System.Windows.Forms.MessageBox.Show("結果為:" + result);
??????? }
??? }
---------
?InstanceContext ic = new InstanceContext(new CallbackHandler());
??????????? myService.Service1Client client = new wcfClient.myService.Service1Client(ic);
??????????? client.AddNumer(3, 4);
-----大型消息傳輸:
比如:上傳和下載數據;
1.在wcf的配置文件制定消息大小的配額;從而支持較大消息的支持;
21.開銷解決方案:
消息傳輸優化機制:MTOM;(刪除過多無用的信息并且處理base64編碼多帶來的數據開銷,改進消息傳輸的整體性能;)
通過配置文件配置Binding節點信息;messageEncoding="Mtom",
MTOM,會加載到內存中;為了降低內存使用,使用流傳輸;
配置:
? <bindings>
??? <wsHttpBinding>
???? <binding name="sdf" maxReceivedMessageSize="5000000" messageEncoding="Mtom">
????? <readerQuotas maxArrayLength="5000000"/>
???? </binding>
??? </wsHttpBinding>
?? </bindings>
22流傳輸;特點:降低內存的使用量;但可靠性和安全性降低;
--標記流傳輸:
????????????? <bindings>
??? <basicHttpBinding>
???? <binding name="sdf" transferMode="Streamed">
???? </binding>
??? </basicHttpBinding>
?? </bindings>
--流傳遞支持三種綁定:netnamedpipebinding,nettcpbinding,basichttpbinding;
transferMode:值默認buffered(緩沖式),Streamed流傳輸;
23將消息切分成較小的切片;
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
