步骤 9:生成并部署 Echo 适配器

第 9 步(共 9

完成时间: 10 分钟

在此步骤中,你将执行部署 Echo 适配器所需的任务。 这涉及以下所有事项:

  • 创建强名称文件并将其分配给 Echo 适配器程序集

  • 生成 Echo 适配器

  • 将程序集发布到 GAC

  • 将 Echo 适配器注册到 Windows Communication Foundation (WCF)

必备条件

若要成功完成此步骤,应熟悉强名称文件和 GAC。 基本了解 Windows Communication Foundation (WCF) 配置很有帮助,但这不是必需的。

指定程序集的强名称

  1. 在 解决方案资源管理器中,右键单击 EchoAdapter 项目,然后单击“属性”。

  2. 在“EchoAdapter 属性页”对话框中,从左窗格中选择“ 签名 ”。

  3. 单击“ 为程序集签名 ”选项卡。

  4. 对于强名称文件,请选择“<新建...”>。 当系统提示输入文件名时,键入 EchoAdapter.snk,取消选择“使用密码保护密钥文件”选项,然后单击“ 确定”。

  5. 单击“应用程序” 选项卡。

  6. 将程序集名称更改为 Microsoft.Adapters.Samples.EchoV2

  7. 单击 Visual Studio 菜单上的“ 文件 ”,然后选择“ 全部保存”。

生成和部署 Echo 适配器

  1. 在解决方案资源管理器中,右键单击 EchoAdapter 项目,然后单击“生成”。 如果生成不成功,请修复任何错误并尝试重新生成 Echo 适配器。

  2. 打开 Visual Studio 命令提示。

  3. 输入以下命令:

    gacutil.exe /if ”<路径 >assembly\Microsoft.Adapters.Samples.EchoV2.dll”

    此命令将程序集安装到 GAC,覆盖任何具有相同程序集名称的现有程序集。

向 Windows Communication Foundation 注册 Echo 适配器

  1. 编辑位于 Microsoft .NET 配置文件夹中的 machine.config 文件。 为此,请单击“ 开始”,单击“ 运行”,键入 记事本 <Windows install path>\Microsoft.NET\Framework\<version>\CONFIG\machine.config,然后单击“ 确定”。

  2. 更新 machine.config 文件。 如果 machine.config 不包含 system.serviceModel 节,请在配置文件末尾、结束根标记之前添加以下部分。

    注意

    将版本、区域性、公钥令牌和其他特定于程序集的信息替换为适配器的信息。

    <system.serviceModel>  
      <client>  
        <endpoint binding="echoAdapterBindingV2" contract="IMetadataExchange"  
          name="echov2" />  
      </client>  
      <extensions>  
        <bindingElementExtensions>  
          <add name="echoAdapterV2" type="Microsoft.Adapters.Samples.EchoV2.EchoAdapterBindingElementExtensionElement,Microsoft.Adapters.Samples.EchoV2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxx" />  
        </bindingElementExtensions>  
        <bindingExtensions>  
          <add name="echoAdapterBindingV2" type="Microsoft.Adapters.Samples.EchoV2.EchoAdapterBindingCollectionElement,Microsoft.Adapters.Samples.EchoV2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxx" />  
        </bindingExtensions>  
      </extensions>  
    </system.serviceModel>  
    
    • 或 -

      如果 machine.config 包含 system.serviceModel 节,请确定缺少哪些元素并添加它们。

    注意

    将版本、区域性、公钥令牌和其他特定于程序集的信息替换为适配器的信息。

    <client>  
      <endpoint binding="echoAdapterBindingV2" contract="IMetadataExchange"  
        name="echov2" />  
    </client>  
    <extensions>  
      <bindingElementExtensions>  
        <add name="echoAdapterV2" type="Microsoft.Adapters.Samples.EchoV2.EchoAdapterBindingElementExtensionElement,Microsoft.Adapters.Samples.EchoV2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxx" />  
      </bindingElementExtensions>  
      <bindingExtensions>  
        <add name="echoAdapterBindingV2" type="Microsoft.Adapters.Samples.EchoV2.EchoAdapterBindingCollectionElement,Microsoft.Adapters.Samples.EchoV2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxx" />  
      </bindingExtensions>  
    </extensions>  
    
  3. 保存 machine.config 文件。

我只是做什么?

在回显适配器教程的最后一步中,你向 Echo 适配器添加了强名称,生成并部署了适配器,然后修改了 Machine.config 以包含有关适配器的信息。 此时,回显适配器应可供使用的应用程序使用。

后续步骤

本教程已完成。 如果要在 .NET 项目中测试 Echo Adapter 功能,请参阅 教程 2:从 .NET 使用 Echo Adapter

另请参阅

步骤 8:实现 Echo 适配器的同步入站处理程序
教程 2:从 .NET 使用 Echo 适配器