ClientBase 未实现 IDisposable 成员

2024-01-07

如果 Dispose() 方法声明不可见/声明,那么 System.ServiceModel.ClientBase 抽象类如何实现 IDisposable 接口?

如果我尝试做同样的事情,我会收到错误并且无法编译

abstract class ATeste : IDisposable
{
}

“ATste”未实现接口成员“System.IDisposable.Dispose()”

我正在使用 VS 2010 和 Framework 4.0。

检查 ClientBase 声明:

    // Summary:
//     Provides the base implementation used to create Windows Communication Foundation
//     (WCF) client objects that can call services.
//
// Type parameters:
//   TChannel:
//     The channel to be used to connect to the service.
public abstract class ClientBase<TChannel> : ICommunicationObject, IDisposable where TChannel : class
{
    // Summary:
    //     Initializes a new instance of the System.ServiceModel.ClientBase<TChannel>
    //     class using the default target endpoint from the application configuration
    //     file.
    //
    // Exceptions:
    //   System.InvalidOperationException:
    //     Either there is no default endpoint information in the configuration file,
    //     more than one endpoint in the file, or no configuration file.
    protected ClientBase();
    //
    // Summary:
    //     Initializes a new instance of the System.ServiceModel.ClientBase<TChannel>
    //     class using the callbackInstance as the callback object in a duplex conversation.
    //
    // Parameters:
    //   callbackInstance:
    //     The callback object that the client application uses to listen for messages
    //     from the connected service.
    //
    // Exceptions:
    //   System.ArgumentNullException:
    //     The callback instance is null.
    //
    //   System.InvalidOperationException:
    //     Either there is no default endpoint information in the configuration file,
    //     more than one endpoint in the file, or no configuration file.
    protected ClientBase(InstanceContext callbackInstance);
    //
    // Summary:
    //     Initializes a new instance of the System.ServiceModel.ClientBase<TChannel>
    //     class using the configuration information specified in the application configuration
    //     file by endpointConfigurationName.
    //
    // Parameters:
    //   endpointConfigurationName:
    //     The name of the endpoint in the application configuration file.
    //
    // Exceptions:
    //   System.ArgumentNullException:
    //     The specified endpoint information is null.
    //
    //   System.InvalidOperationException:
    //     The endpoint cannot be found or the endpoint contract is not valid.
    protected ClientBase(string endpointConfigurationName);
    //
    // Summary:
    //     Initializes a new instance of the System.ServiceModel.ClientBase<TChannel>
    //     class using the specified binding and target address.
    //
    // Parameters:
    //   binding:
    //     The binding with which to make calls to the service.
    //
    //   remoteAddress:
    //     The address of the service endpoint.
    //
    // Exceptions:
    //   System.ArgumentNullException:
    //     The binding is null.
    //
    //   System.ArgumentNullException:
    //     The remote address is null.
    protected ClientBase(Binding binding, EndpointAddress remoteAddress);
    //
    // Summary:
    //     Initializes a new instance of the System.ServiceModel.ClientBase<TChannel>
    //     class using the specified callback service and endpoint configuration information.
    //
    // Parameters:
    //   callbackInstance:
    //     The callback object that the client uses to listen for messages from the
    //     connected service.
    //
    //   endpointConfigurationName:
    //     The name of the endpoint in the application configuration file.
    //
    // Exceptions:
    //   System.ArgumentNullException:
    //     The callback instance is null.
    //
    //   System.ArgumentNullException:
    //     The endpoint is null.
    //
    //   System.InvalidOperationException:
    //     The endpoint cannot be found or the endpoint contract is not valid.
    protected ClientBase(InstanceContext callbackInstance, string endpointConfigurationName);
    //
    // Summary:
    //     Initializes a new instance of the System.ServiceModel.ClientBase<TChannel>
    //     class using the specified target address and endpoint information.
    //
    // Parameters:
    //   endpointConfigurationName:
    //     The name of the endpoint in the application configuration file.
    //
    //   remoteAddress:
    //     The address of the service.
    //
    // Exceptions:
    //   System.ArgumentNullException:
    //     The endpoint is null.
    //
    //   System.ArgumentNullException:
    //     The remote address is null.
    //
    //   System.InvalidOperationException:
    //     The endpoint cannot be found or the endpoint contract is not valid.
    protected ClientBase(string endpointConfigurationName, EndpointAddress remoteAddress);
    //
    // Summary:
    //     Initializes a new instance of the System.ServiceModel.ClientBase<TChannel>
    //     class.
    //
    // Parameters:
    //   endpointConfigurationName:
    //     The name of the endpoint in the application configuration file.
    //
    //   remoteAddress:
    //     The address of the service.
    //
    // Exceptions:
    //   System.ArgumentNullException:
    //     The endpoint is null.
    //
    //   System.ArgumentNullException:
    //     The remote address is null.
    //
    //   System.InvalidOperationException:
    //     The endpoint cannot be found or the endpoint contract is not valid.
    protected ClientBase(string endpointConfigurationName, string remoteAddress);
    //
    // Summary:
    //     Initializes a new instance of the System.ServiceModel.ClientBase<TChannel>
    //     class.
    //
    // Parameters:
    //   callbackInstance:
    //     The callback service.
    //
    //   binding:
    //     The binding with which to call the service.
    //
    //   remoteAddress:
    //     The address of the service endpoint.
    //
    // Exceptions:
    //   System.ArgumentNullException:
    //     The callback instance is null.
    //
    //   System.ArgumentNullException:
    //     The binding is null.
    //
    //   System.ArgumentNullException:
    //     The remote address is null.
    protected ClientBase(InstanceContext callbackInstance, Binding binding, EndpointAddress remoteAddress);
    //
    // Summary:
    //     Initializes a new instance of the System.ServiceModel.ClientBase<TChannel>
    //     class.
    //
    // Parameters:
    //   callbackInstance:
    //     The callback object that the client uses to listen for messages from the
    //     connected service.
    //
    //   endpointConfigurationName:
    //     The name of the endpoint in the application configuration file.
    //
    //   remoteAddress:
    //     The address of the service.
    //
    // Exceptions:
    //   System.ArgumentNullException:
    //     The callback instance is null.
    //
    //   System.ArgumentNullException:
    //     The endpoint is null.
    //
    //   System.ArgumentNullException:
    //     The remote address is null.
    //
    //   System.InvalidOperationException:
    //     The endpoint cannot be found or the endpoint contract is not valid.
    protected ClientBase(InstanceContext callbackInstance, string endpointConfigurationName, EndpointAddress remoteAddress);
    //
    // Summary:
    //     Initializes a new instance of the System.ServiceModel.ClientBase<TChannel>
    //     class.
    //
    // Parameters:
    //   callbackInstance:
    //     The callback object that the client uses to listen for messages from the
    //     connected service.
    //
    //   endpointConfigurationName:
    //     The name of the endpoint in the application configuration file.
    //
    //   remoteAddress:
    //     The address of the service.
    //
    // Exceptions:
    //   System.ArgumentNullException:
    //     The callback instance is null.
    //
    //   System.ArgumentNullException:
    //     The endpoint is null.
    //
    //   System.ArgumentNullException:
    //     The remote address is null.
    //
    //   System.InvalidOperationException:
    //     The endpoint cannot be found or the endpoint contract is not valid.
    protected ClientBase(InstanceContext callbackInstance, string endpointConfigurationName, string remoteAddress);

    // Summary:
    //     Gets the inner channel used to communicate with the service.
    //
    // Returns:
    //     An implementation of the target service contract interface passed as the
    //     type parameter to the constructor.
    protected TChannel Channel { get; }
    //
    // Summary:
    //     Gets the underlying System.ServiceModel.ChannelFactory<TChannel> object.
    //
    // Returns:
    //     A System.ServiceModel.ChannelFactory<TChannel> object.
    public ChannelFactory<TChannel> ChannelFactory { get; }
    //
    // Summary:
    //     Gets the client credentials used to call an operation.
    //
    // Returns:
    //     Returns a System.ServiceModel.Description.ClientCredentials that represents
    //     the proof of identity presented by the client.
    public ClientCredentials ClientCredentials { get; }
    //
    // Summary:
    //     Gets the target endpoint for the service to which the WCF client can connect.
    //
    // Returns:
    //     The target endpoint.
    public ServiceEndpoint Endpoint { get; }
    //
    // Summary:
    //     Gets the underlying System.ServiceModel.IClientChannel implementation.
    //
    // Returns:
    //     The client channel for the WCF client object.
    public IClientChannel InnerChannel { get; }
    //
    // Summary:
    //     Gets the current state of the System.ServiceModel.ClientBase<TChannel> object.
    //
    // Returns:
    //     The value of the System.ServiceModel.CommunicationState of the object.
    public CommunicationState State { get; }

    // Summary:
    //     Causes the System.ServiceModel.ClientBase<TChannel> object to transition
    //     immediately from its current state into the closed state.
    public void Abort();
    //
    // Summary:
    //     Causes the System.ServiceModel.ClientBase<TChannel> object to transition
    //     from its current state into the closed state.
    public void Close();
    //
    // Summary:
    //     Returns a new channel to the service.
    //
    // Returns:
    //     A channel of the type of the service contract.
    protected virtual TChannel CreateChannel();
    //
    // Summary:
    //     Instructs the inner channel to display a user interface if one is required
    //     to initialize the channel prior to using it.
    public void DisplayInitializationUI();
    //
    // Summary:
    //     Replicates the behavior of the default keyword in C#.
    //
    // Type parameters:
    //   T:
    //
    // Returns:
    //     Returns null if T is a reference type and zero if T is a numeric value type.
    protected T GetDefaultValueForInitialization<T>();
    protected void InvokeAsync(ClientBase<TChannel>.BeginOperationDelegate beginOperationDelegate, object[] inValues, ClientBase<TChannel>.EndOperationDelegate endOperationDelegate, SendOrPostCallback operationCompletedCallback, object userState);
    //
    // Summary:
    //     Causes the System.ServiceModel.ClientBase<TChannel> object to transition
    //     from the created state into the opened state.
    public void Open();

    // Summary:
    //     A delegate that is used by System.ServiceModel.ClientBase<TChannel>.InvokeAsync(System.ServiceModel.ClientBase.BeginOperationDelegate,System.Object[],System.ServiceModel.ClientBase.EndOperationDelegate,System.Threading.SendOrPostCallback,System.Object)
    //     for calling asynchronous operations on the client.
    //
    // Parameters:
    //   inValues:
    //     The input values to the asynchronous call.
    //
    //   asyncCallback:
    //     Reference to the method to be called when the corresponding asynchronous
    //     operation completes.
    //
    //   state:
    //     An System.Object that lets the client distinguish between different asynchronous
    //     calls. It is made available to the client in the arguments parameter of the
    //     event completion callback.
    //
    // Returns:
    //     The result of the asynchronous call.
    protected delegate IAsyncResult BeginOperationDelegate(object[] inValues, AsyncCallback asyncCallback, object state);

    // Summary:
    //     A delegate that is invoked by System.ServiceModel.ClientBase<TChannel>.InvokeAsync(System.ServiceModel.ClientBase.BeginOperationDelegate,System.Object[],System.ServiceModel.ClientBase.EndOperationDelegate,System.Threading.SendOrPostCallback,System.Object)
    //     on successful completion of the call made by System.ServiceModel.ClientBase<TChannel>.InvokeAsync(System.ServiceModel.ClientBase.BeginOperationDelegate,System.Object[],System.ServiceModel.ClientBase.EndOperationDelegate,System.Threading.SendOrPostCallback,System.Object)
    //     to System.ServiceModel.ClientBase<TChannel>.BeginOperationDelegate.
    //
    // Parameters:
    //   result:
    //     The result returned by the call made by System.ServiceModel.ClientBase<TChannel>.InvokeAsync(System.ServiceModel.ClientBase.BeginOperationDelegate,System.Object[],System.ServiceModel.ClientBase.EndOperationDelegate,System.Threading.SendOrPostCallback,System.Object)to
    //     System.ServiceModel.ClientBase<TChannel>.BeginOperationDelegate.
    //
    // Returns:
    //     An array of System.Object that contains the results of the call to the asynchronous
    //     method. The operation may have multiple return values, which are all returned
    //     in this object array.
    protected delegate object[] EndOperationDelegate(IAsyncResult result);

    // Summary:
    //     Stores the results from an asynchronous call made by the client.
    protected class InvokeAsyncCompletedEventArgs : AsyncCompletedEventArgs
    {
        // Summary:
        //     Gets the results from an asynchronous call made by the client.
        //
        // Returns:
        //     An array of System.Object that contains the results from an asynchronous
        //     call made by the client.
        public object[] Results { get; }
    }
}

我再次测试,但这次明确实现 IDisposable。现在有道理了

abstract class ATest : IDisposable
{
    void IDisposable.Dispose()
    {
        throw new NotImplementedException();
    }
}

class Test : ATest
{
}

现在,当我实例化测试类时,我无法访问 Dispose() 方法:

        Test t = new Test();
        t.Dispose();

使用显式接口实现 http://msdn.microsoft.com/en-us/library/aa288461%28v=vs.71%29.aspx.

IDisposable是可见的并且可以被调用为

var client = new WCFTestServiceClient(); // assumingWCFTestServiceClient is WCF client proxy that inherits from ClientBase
(client as IDisposable).Dispose();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

ClientBase 未实现 IDisposable 成员 的相关文章

随机推荐

  • 如何在 Android 中恢复文件上传过程?

    我正在使用此代码在服务器上上传文件 但我想要这样的功能 如果在过程中由于网络丢失或任何其他中断而停止 那么它不应该从第二次开始上传 来自服务器的响应也是可定制的 在安卓上可以吗 我应该使用什么方法来做到这一点 请指导我 如果可能的话 请向我
  • 如何在 SunOs 的 df -k 命令中省略标题

    Input df k Output Filesystem kbytes used avail capacity Mounted on dev dsk c0t0d0s0 10332220 443748 9785150 5 devices 0
  • MVVM + 用户控件 + 依赖属性

    好吧 这与这个问题有些相关 WPF 从单个视图模型打印多个页面 https stackoverflow com questions 15162274 wpf printing multiple pages from a single vie
  • 检查 XML 中是否存在某个元素

    XML
  • asp.net mvc TextAreaFor 未验证为必填字段

    我有一个数据输入字段 我可以在其中收集笔记 每个注释都需要注释数据元素 这是我的模型 public interface INoteDataEntryViewModel IMobilePageDataContract int CourseId
  • 如何获取 svg:g 元素的宽度

    我目前正在与一个svgJavaScript 中的元素 我对此很陌生 我的问题是我有一个svg我有多个元素svg g元素 而在我的svg gelements 我有各种其他 svg 元素
  • 现实世界中的递归示例[关闭]

    Closed 这个问题需要多问focused help closed questions 目前不接受答案 什么是真实世界除了深度优先搜索 DFS 之外 递归方法是自然解决方案的问题吗 我不考虑河内塔 http en wikipedia or
  • 熊猫拆分列

    给定以下数据框 import pandas as pd import numpy as np df pd DataFrame A a b c d B Y gt abcd abcd efgh Y gt efgh df A B 0 a Y gt
  • 根据 C++ 标准的定义实现“is_similar”类型特征

    我正在尝试实施一个is similar基于标准给出的定义的类型特征 详细信息here http eel is c draft conv qual 2 两种类型T1 and T2如果它们具有 cv 分解 则它们是相似的 与相同的n使得对应的P
  • GAE 上的 Struts 2:无法在拦截器内设置会话值

    我正在编写一个 Struts 2 拦截器 在其中检查用户是否有效 如果无效 用户将被重定向到登录页面 但在此之前 我尝试检索用户访问此处的 URL 并将其放入会话变量中 以便在登录完成后我可以将他重定向回那里 但是当我尝试在会话中放入一个值
  • background-position-y 在 Firefox 中不起作用(通过 CSS)?

    在我的代码中background position y不起作用 在 Chrome 中可以 但在 Firefox 中不行 有人有什么解决办法吗 如果你的position x是0 除了写之外没有其他解决方案 background positio
  • Wiki 数据导入 virtuoso

    我想将维基数据加载到 virtuoso 中 经过几天的搜索 我找不到任何教程 或者至少找不到使用 virtuoso 来 sparql 查询 wikidata 的人 我不想白花钱买一台服务器来加载50G 的数据 例如 为什么是 virtuos
  • 使用polyfit来预测物体掉落的位置?

    我有一个物体以抛物线模式抛出的信息 从开始位置到结束位置 按照特定时间间隔总共拍摄了 30 张图像 现在我已经成功提取了所有 30 张图像中被抛出物体的 x y 坐标 我认为使用 polyfit 或者也许是 polyval 可以帮助我预测前
  • 如何使用 QSocketNotifier (linux) 监视串行端口?

    有人可以给我一个关于如何设置 QSocketNotifier 在发生事件时触发事件的示例吗 dev ttyS0 最好在 python pyqt4 中 下面是一个使用 QSocketNotifier 不断读取文件的示例 只需将 foo txt
  • SQL 2005中检查外键是否存在的方法

    有没有一种简单的方法来检查表中的列是否存在外键 我正在编写一个脚本 仅当外键不存在时才会添加外键 您可以使用这个脚本 IF EXISTS SELECT FROM sys foreign keys WHERE object id OBJECT
  • Google Javascript API 地理编码限制

    使用 Google Maps JavaScript API v3 进行客户端地理编码有哪些限制 我的研究 Google Maps PHP API 每天的地理编码请求限制为 2500 个 https developers google com
  • 如何将热量输出包含在 wix 文件中? (没有 Visual Studio 项目)

    我需要构建一个安装程序 并且出于多种原因 我想避免使用 WiX 项目模板 我非常高兴自己编写这些东西的脚本 并且已经有了一个适合它的自定义构建流程 我相信我很好地理解了 WiX 蜡烛 加热和照明工具的作用 我正在熟悉 wxs 文件格式 并且
  • 为什么 GDB 计算浮点运算的方式与 C++ 不同?

    我在尝试处理浮点算术问题时遇到了一些令人困惑的事情 首先 代码 我将问题的本质提炼到这个例子中 include
  • 如何向 Xcode 4.4 添加本地化语言?

    参考本指南 如何使用 Xcode 4 本地化我的应用程序 https stackoverflow com questions 5349066 how to localize my app with xcode 4 我注意到在本地化下 我的
  • ClientBase 未实现 IDisposable 成员

    如果 Dispose 方法声明不可见 声明 那么 System ServiceModel ClientBase 抽象类如何实现 IDisposable 接口 如果我尝试做同样的事情 我会收到错误并且无法编译 abstract class A