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
双工IDuplexChannelIDuplexChannel
P2PIDuplexChannelIDuplexChannel

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

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

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

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

6.4 通道接口和基本类型

IChannel接口

    public interface IChannel : ICommunicationObject
    {
        T GetProperty<T>() where T : class;
    }

GetProperty<T>方法提供了在CommunicationObject堆栈里查询特定功能的途径。

            MessageVersion messageVersion = channel.GetProperty<MessageVersion>();
            if (messageVersion != null)
            {
            }

数据报通道 IInputChannel与IOutputChannel

    public interface IOutputChannel : IChannel, ICommunicationObject
    {
        EndpointAddress RemoteAddress { get; }
        Uri Via { get; }

        IAsyncResult BeginSend(Message message, AsyncCallback callback, object state);
        IAsyncResult BeginSend(Message message, TimeSpan timeout, AsyncCallback callback, object state);
        void EndSend(IAsyncResult result);
        void Send(Message message);
        void Send(Message message, TimeSpan timeout);
    }

对于接收者在数据报交换模式中的角色,IInoutChannel只定义了接收成员而没有定义发送成员。
    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);
    }

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









  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
WCF WebSocket是WCF 4.5中新增的一个功能,它支持在WCF中使用WebSocket协议进行通信。WebSocket是一种全双工通信协议,可以在客户端和服务器之间建立持久性的连接,实现实时的双向通信。\[1\] 然而,需要注意的是,WCF WebSocket只在Windows 8及以上的系统中支持,对于Windows 7等旧版本的系统则不支持。这是因为WCF WebSocket依赖于System.Net.WebSocket类,而该类也只在Windows 8及以上的系统中可用。\[2\] 在WCF中,可以使用NetHttpBinding和NetHttpsBinding这两个标准绑定来支持WebSocket传输。这两个绑定允许在标准的HTTP端口80和443上进行WebSocket通信,从而可以通过Web中介进行跨网络的通信。\[3\] 总结起来,WCF WebSocket是WCF 4.5中新增的功能,它支持使用WebSocket协议进行实时的双向通信。然而,需要注意的是,WCF WebSocket只在Windows 8及以上的系统中支持,并且可以使用NetHttpBinding和NetHttpsBinding这两个标准绑定来进行WebSocket通信。 #### 引用[.reference_title] - *1* *2* [在WCF中使用websocket](https://blog.csdn.net/weixin_34205826/article/details/85568070)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [WCF websocket](https://blog.csdn.net/weixin_30699741/article/details/96370576)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值