介绍
WCF(Windows Communication Foundation) - 消息处理:通过操作契约的IsOneWay参数实现异步调用,基于Http, TCP, Named Pipe, MSMQ的双向通讯。
示例(异步调用OneWay)
1、服务
IOneWay.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.ServiceModel; namespace WCF.ServiceLib.Message { /**//// /// IOneWay接口 /// [ServiceContract] public interface IOneWay { /**//// /// 不使用OneWay(同步调用) /// [OperationContract] void WithoutOneWay(); /**//// /// 使用OneWay(异步调用) /// [OperationContract(IsOneWay=true)] void WithOneWay(); } } |
OneWay.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.ServiceModel; namespace WCF.ServiceLib.Message { /**//// /// OneWay类 /// public class OneWay : IOneWay { /**//// /// 不使用OneWay(同步调用) /// 抛出Exception异常 /// public void WithoutOneWay() { throw new System.Exception("抛出Exception异常"); } /**//// /// 使用OneWay(异步调用) /// 抛出Exception异常 /// public void WithOneWay() { throw new System.Exception("抛出Exception异常"); } } } |