步骤 2:对适配器和连接属性进行分类

步骤 2(共 9 步)

完成时间: 30 分钟

在此步骤中,更新 EchoAdapterBindingElementEchoAdapterBindingElementExtensionElement 类,以将类别分配给适配器和连接属性。 这样做会使属性在“添加适配器服务引用插件”和“使用适配器服务外接程序”工具中根据类别进行逻辑分组。 例如,如果希望 应用程序EnableAuthentication主机名 属性显示在 “连接 ”类别下面,则需要将“连接”类别分配给每个应用程序、EnableAuthentication 和主机名属性。

显示“URI 属性”选项卡的屏幕截图。

同样,如果希望 InboundFileFilterInboundFleSystemWatcherFolder 属性显示在 入站类别下 ,如下所示,则需要将入站类别分配给每个类别。 如果希望 CountEnableConnectionPooling 显示在 Misc 类别下,则需要将 Misc 类别分配给每个类别。

显示“绑定属性”选项卡的屏幕截图。

请记住,您可以为属性指定任何您选择的类别名称。 在此示例中,由于 EnableConnnectionPooling 属性不属于任何其他类别,因此我们将它归类为 Misc (杂项)。 至于 InboundFileFilter 属性,由于它在示例中的入站处理期间使用,因此更适合将 Inbound 分配到该属性,而不是“杂项”。 下面是回显适配器的完整自定义属性分类。

财产 类别
InboundFileFilter 入站
InboundFileSystemWatcherFolder 入站
计数 杂项
启用连接池 杂项
应用程序 连接
启用身份验证 连接
主机名 连接
EchoInUpperCase 格式

除了这些更改,还修改 EchoAdapterHandlerBase 的 Dispose 方法。

有关回显适配器公开的适配器属性,请参阅 教程 1:开发回显适配器 中的适配器属性部分。

先决条件

在开始此步骤之前,必须完成 步骤 1:使用 WCF LOB 适配器开发向导创建 Echo 适配器项目。 您还应熟悉 System.ServiceModel.Configuration.BindingElementExtensionElement 类和 System.ServiceModel.Configuration.StandardBindingElement 类。

更新 EchoAdapterHandlerBase Dispose 方法

  1. 解决方案资源管理器中,双击 EchoAdapterHandlerBase.cs 文件。

  2. Dispose 方法中删除以下语句:

    throw new NotImplementedException("The method or operation is not implemented.");  
    

    修订后的方法应如下所示:

    protected virtual void Dispose(bool disposing)  
    {  
       //  
       //TODO: Implement Dispose. Override this method in respective Handler classes  
       //  
    }  
    

更新 Adapter 属性类

  1. 解决方案资源管理器中,双击 EchoAdapterBindingElement.cs 文件。

  2. 在 Visual Studio 编辑器中,展开 “自定义生成的属性” 区域。

  3. 若要将 Misc 类别分配给 Count 属性,请将以下单个语句添加到 Count 实现的开头。

    [System.ComponentModel.Category("")]  
    

    计数实现现在应与以下内容匹配:

    [System.ComponentModel.Category("")]  
    [System.Configuration.ConfigurationProperty("count", DefaultValue = 5)]  
    public int Count  
    {  
        get  
        {  
            return ((int)(base["Count"]));  
        }  
        set  
        {  
            base["Count"] = value;  
        }  
    }  
    
  4. 若要将 Misc 类别分配给 EnableConnectionPooling 属性,请将以下单个语句添加到 EnableConnectionPooling 实现的开头。

    [System.ComponentModel.Category("")]  
    
  5. 若要将 Inbound 类别分配给 InboundFileFilter 属性,请将以下单个语句添加到 InboundFileFilter 实现的开头。

    [System.ComponentModel.Category("Inbound")]  
    
  6. 若要将 Inbound 类别分配给 inboundFleSystemWatcherFolder 属性,请在 inboundFleSystemWatcherFolder 实现的开头添加以下单个语句。

    [System.ComponentModel.Category("Inbound")]  
    
  7. 检查以确保 自定义生成的属性 区域中的代码与以下内容匹配:

    [System.ComponentModel.Category("")]  
    [System.Configuration.ConfigurationProperty("count", DefaultValue = 5)]  
    public int Count  
    {  
        get  
        {  
            return ((int)(base["Count"]));  
        }  
        set  
        {  
            base["Count"] = value;  
        }  
    }  
    
    [System.ComponentModel.Category("")]  
    [System.Configuration.ConfigurationProperty("enableConnectionPooling", DefaultValue = true)]  
    public bool EnableConnectionPooling  
    {  
        get  
        {  
            return ((bool)(base["EnableConnectionPooling"]));  
        }  
        set  
        {  
            base["EnableConnectionPooling"] = value;  
        }  
    }  
    
    [System.ComponentModel.Category("Inbound")]  
    [System.Configuration.ConfigurationProperty("inboundFileFilter", DefaultValue = "*.txt")]  
    public string InboundFileFilter  
    {  
        get  
        {  
            return ((string)(base["InboundFileFilter"]));  
        }  
        set  
        {  
            base["InboundFileFilter"] = value;  
        }  
    }  
    
    [System.ComponentModel.Category("Inbound")]  
    [System.Configuration.ConfigurationProperty("inboundFileSystemWatcherFolder", DefaultValue = "{InboundFileSystemWatcherFolder}")]  
    public string InboundFileSystemWatcherFolder  
    {  
        get  
        {  
            return ((string)(base["InboundFileSystemWatcherFolder"]));  
        }  
        set  
        {  
            base["InboundFileSystemWatcherFolder"] = value;  
        }  
    }  
    
    #endregion Custom Generated Properties  
    

更新连接属性

  1. 解决方案资源管理器中,双击 EchoAdapterConnectionUri.cs 文件。

  2. 在 Visual Studio 编辑器中,展开 “自定义生成的属性” 区域。

  3. 若要将 Format 类别分配给 EchoInUpperCase 属性,请将以下单个语句添加到 EchoInUpperCase 实现的开头。

    [System.ComponentModel.Category("Format")]  
    
  4. 若要将 Connection 类别分配给 Hostname 属性,请将以下单个语句添加到 Hostname 实现的开头。

    [System.ComponentModel.Category("Connection")]  
    
  5. 若要将 Connection 类别分配给 Application 属性,请将以下单个语句添加到 Application 实现的开头。

    [System.ComponentModel.Category("Connection")]  
    
  6. 若要分配 Connection categoryto EnableAuthentication 属性,请将以下单一语句添加到 EnableAuthentication 实现的开头。

    [System.ComponentModel.Category("Connection")]  
    
  7. 检查以确保 自定义生成的属性 区域中的代码与以下内容匹配:

    #region Custom Generated Properties  
            [System.ComponentModel.Category("Format")]  
            public bool EchoInUpperCase  
            {  
                get  
                {  
                    return this.echoInUpperCase;  
                }  
                set  
                {  
                    this.echoInUpperCase = value;  
                }  
            }  
    
            [System.ComponentModel.Category("Connection")]  
            public string Hostname  
            {  
                get  
                {  
                    return this.hostname;  
                }  
                set  
                {  
                    this.hostname = value;  
                }  
            }  
    
            [System.ComponentModel.Category("Connection")]  
            public string Application  
            {  
                get  
                {  
                    return this.application;  
                }  
                set  
                {  
                    this.application = value;  
                }  
            }  
    
            [System.ComponentModel.Category("Connection")]  
            public bool EnableAuthentication  
            {  
                get  
                {  
                    return this.enableAuthentication;  
                }  
                set  
                {  
                    this.enableAuthentication = value;  
                }  
            }  
            #endregion Custom Generated Properties  
    
  8. 在 Visual Studio 的 “文件” 菜单中,单击“ 全部保存”。

注释

你保存了你的工作。 此时可以安全地关闭 Visual Studio,也可以转到下一步 :步骤 3:实现 Echo 适配器的连接

我刚刚做了什么?

你刚刚更新了类,以便将类别分配给回显适配器公开的每个适配器和连接属性。

后续步骤

实现连接、元数据浏览、搜索和解析功能以及出站消息交换。 最后,构建并部署回显适配器。

另请参阅

步骤 3:实现 Echo 适配器的连接
教程 1:开发 Echo 适配器