读书人

WCF技术黑幕 第6章(3)

发布时间: 2013-04-09 16:45:09 作者: rapoo

WCF技术内幕 第6章(3)

Close和Abort方法

CommunicationObject类型展示了可以销毁对象的方法。通常,Close和BeginClose方法可以以一种优雅的方式关闭CommunicationObject对象,而Abort方法则会立即关闭对象。

Close方法包含一个异步的实现,而Abort方法则没有。

Fault方法

虽然保护方法Fault也是一种关闭CommunicationObject对象的方式,但它不属于ICommunicationObject接口,它只适用于CommunicationObject对象的子类型。

调用Fault方法会把State属性转换为CommunicationState.Faulted,并且调用OnFaulted虚方法。大部分情况下,OnFaulted方法都会调用Abort方法。


6.3 通道形状介绍

消息交换模式与通道形状的关系

MEPSenderReceiver数据报IOutputChannelIInputChannel请求/应答IRequestChannelIReplyChannel双工IDuplexChannelIDuplexChannelP2PIDuplexChannelIDuplexChannel

通道需要实现System.ServiceModel.Channels.ISessionChannel<T>接口来支持会话。ISessionChannel<T>的泛型参数必须实现System.ServiceModel.Channels.ISession接口。

在WCF中,实现ISessionChannel<T>接口的通道类型成为会话通道。

消息交换模式与会话通道形状的关系

MEPSenderReceiver数据报IOutputSessionChannelIInputSessionChannel请求/应答IRequestSessionChannelIReplySessionChannel双工IDuplexSessionChannelIDuplexSessionChannelP2PIDuplexSessionChannelIDuplexSessionChannel

6.4 通道接口和基本类型

IChannel接口

    public interface IInputChannel : IChannel, ICommunicationObject    {        EndpointAddress LocalAddress { get; }        IAsyncResult BeginReceive(AsyncCallback callback, object state);        IAsyncResult BeginReceive(TimeSpan timeout, AsyncCallback callback, object state);        IAsyncResult BeginTryReceive(TimeSpan timeout, AsyncCallback callback, object state);        IAsyncResult BeginWaitForMessage(TimeSpan timeout, AsyncCallback callback, object state);        Message EndReceive(IAsyncResult result);        bool EndTryReceive(IAsyncResult result, out Message message);        bool EndWaitForMessage(IAsyncResult result);        Message Receive();        Message Receive(TimeSpan timeout);        bool TryReceive(TimeSpan timeout, out Message message);        bool WaitForMessage(TimeSpan timeout);    }

接收程序会消极地等待消息的到来。









读书人网 >软件开发

热点推荐