日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

WCF中双工协议

發布時間:2024/4/15 编程问答 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 WCF中双工协议 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
服務端配置文件 1 <system.serviceModel> 2 <behaviors> 3 <serviceBehaviors> 4 <behavior name="CallBackContractServicebehavior"> 5 <serviceDebug httpHelpPageEnabled="false"/> 6 <serviceMetadata httpGetEnabled="false"/> 7 <serviceTimeouts transactionTimeout="00:10:00"/> 8 <serviceThrottling maxConcurrentCalls="1000" maxConcurrentInstances="1000" maxConcurrentSessions="1000"/> 9 </behavior> 10 </serviceBehaviors> 11 </behaviors> 12 13 <bindings> 14 <netTcpBinding> 15 <binding name="tcpbinding"> 16 <security mode="None"> 17 <transport clientCredentialType="None" protectionLevel="None"/> 18 </security> 19 </binding> 20 </netTcpBinding> 21 </bindings> 22 <services> 23 <service name="MyWCF.CallBack.Service.CallBackContractService" behaviorConfiguration="CallBackContractServicebehavior"> 24 <host> 25 <baseAddresses> 26 <add baseAddress="net.tcp://localhost:12475/CalculatorService"/> 27 </baseAddresses> 28 </host> 29 <endpoint address="" binding="netTcpBinding" bindingConfiguration="tcpbinding" contract="MyWCF.CallBack.Interfac.ICallBackContract"/> 30 <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/> 31 </service> 32 </services> 33 <!--<behaviors> 34 <serviceBehaviors> 35 <behavior name="MathServicebehavior"> 36 <serviceDebug httpHelpPageEnabled="false"/> 37 <serviceMetadata httpGetEnabled="false"/> 38 <serviceTimeouts transactionTimeout="00:10:00"/> 39 <serviceThrottling maxConcurrentCalls="1000" maxConcurrentInstances="1000" maxConcurrentSessions="1000"/> 40 </behavior> 41 </serviceBehaviors> 42 </behaviors> 43 <bindings> 44 <basicHttpBinding> 45 <binding name="httpbinding"/> 46 </basicHttpBinding> 47 </bindings> 48 <services> 49 <service name="SOA.WCF.Service.MathService" behaviorConfiguration="MathServicebehavior"> 50 <host> 51 <baseAddresses> 52 <add baseAddress="http://localhost:11113/MathService"/> 53 </baseAddresses> 54 </host> 55 <endpoint address="" binding="basicHttpBinding" bindingConfiguration="httpbinding" contract="SOA.WCF.Interface.IMathService"/> 56 <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> 57 </service> 58 </services>--> 59 60 </system.serviceModel> 配置文件

?

服務端雙工協議執行類接口注明回調約束ICallBack

[ServiceContract(CallbackContract =typeof(ICallBack))]public interface ICallBackContract{[OperationContract]int Plus(int x,int y); }

服務端設置回掉類庫

public interface ICallBack{/// <summary>/// 回調/// </summary>/// <param name="x"></param>/// <param name="y"></param>/// <param name="iResult"></param>[OperationContract(IsOneWay =true)]void Show(int x,int y,int iResult);} 回調類庫

服務端實現方法

public class CallBackContractService : ICallBackContract{public int Plus(int x, int y){int result = x + y;Thread.Sleep(2000);ICallBack callBack = OperationContext.Current.GetCallbackChannel<ICallBack>();callBack.Show(x, y, result);return result;}} 服務端實現類

客服端實現調用繼承服務端的實現類庫

public class CallBackService : MyCallBack.ICallBackContractCallback{public void Show(int x, int y, int iResult){Console.WriteLine($"回調顯示:{x}+{y}={iResult}");}} 客戶端實現回掉邏輯

客戶端調用代碼

static void Main(string[] args){MyCallBack.CallBackContractClient client = null;try{InstanceContext instanceContext = new InstanceContext(new CallBackService());client = new MyCallBack.CallBackContractClient(instanceContext);int a=client.Plus(1, 2);client.Close();}catch (Exception ex){if (client != null)client.Abort();Console.WriteLine(ex);}Console.Read();} 調用邏輯

?

轉載于:https://www.cnblogs.com/zxp6/p/10597112.html

總結

以上是生活随笔為你收集整理的WCF中双工协议的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。