.net - 如何在 BeforeSendRequest 中取消请求

标签 .net wcf iclientmessageinspector

使用 IClientMessageInspector 时接口(interface),我可以取消来自BeforeSendRequest 的请求吗?方法?返回 null无论如何发送请求。

 public object BeforeSendRequest(ref Message request, IClientChannel channel)
 {
    if(Condition)
    {
        return null; //I want cancel my send
    }
    else
    {
       return request;
    }
  }

最佳答案

您可以使用 IClientChannel 的 Abort 方法取消请求。但是您客户的调度方法抛出 CommunicationObjectAbortedException .

public object BeforeSendRequest(ref Message request, IClientChannel channel)
 {
    if(Condition)
    {
        channel.Abort();
        return null;
    }
    else
    {
       return request;
    }
  }

关于.net - 如何在 BeforeSendRequest 中取消请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16696750/

相关文章:

c# - 使用 Web 服务作为数据访问层开发 ASP.NET MVC 应用程序

c# - 将 application/x-www-form-urlencoded 发布到 SOAP/JSON WCF 服务

c# - 如何使用 Azure 存储队列发送 XML 文件?

c# - Telerik RadTabStrip 的问题

wcf - 使用Fiddler测试WCF REST服务时如何完成基本身份验证握手?

wcf - 使用 WCF 服务防止 Http 重定向 307

c# - 如何在 IClientMessageInspector 中获取调用的操作名称?

.net - 为什么我们需要 IEqualityComparer,IEqualityComparer<T> 接口(interface)?

c# - 是否可以从 Windows 窗体中的 SplitContainer 中删除 panel2?