使用 Enterprise Integration Pack 对 Azure 逻辑应用中的平面文件进行编码或解码Encode and decode flat files in Azure Logic Apps by using the Enterprise Integration Pack

在企业对企业 (B2B) 方案中将 XML 内容发送给业务合作伙伴之前,你可能希望先对该内容进行编码。Before you send XML content to a business partner in a business-to-business (B2B) scenario, you might want to encode that content first. 通过构建逻辑应用,你可以使用平面文件连接器对平面文件进行编码和解码。By building a logic app, you can encode and decode flat files by using the Flat File connector. 逻辑应用可以从各种源(例如请求触发器、其他应用,或其他由 Azure 逻辑应用支持的连接器)获取此 XML 内容。Your logic app can get this XML content from various sources, such as the Request trigger, another app, or other connectors supported by Azure Logic Apps. 有关详细信息,请参阅什么是 Azure 逻辑应用?For more information, see What is Azure Logic Apps?

先决条件Prerequisites

  • Azure 订阅。An Azure subscription. 如果没有订阅,可以注册 Azure 试用帐户If you don't have a subscription, sign up for a trial Azure account.

  • 你要在其中使用平面文件连接器的逻辑应用,以及用于启动逻辑应用工作流的触发器。The logic app where you want to use the Flat File connector and a trigger that starts your logic app's workflow. 平面文件连接器只提供操作,不提供触发器。The Flat File connector provides only actions, not triggers. 可以使用触发器或其他操作将 XML 内容送入逻辑应用进行编码或解码。You can use either the trigger or another action to feed the XML content into your logic app for encoding or decoding. 如果不熟悉逻辑应用,请查看快速入门:创建第一个逻辑应用If you're new to logic apps, review Quickstart: Create your first logic app.

  • 一个集成帐户,该帐户与你的 Azure 订阅相关联,并已关联到逻辑应用(你计划在其中使用平面文件连接器)。An integration account that's associated with your Azure subscription and linked to the logic app where you plan to use the Flat File connector. 逻辑应用和集成帐户必须位于同一位置或 Azure 区域。Both your logic app and integration account must exist in the same location or Azure region.

  • 已上传到集成帐户的平面文件架构,用于对 XML 内容进行编码或解码A flat file schema that you've uploaded to your integration account for encoding or decoding the XML content

  • 已在集成帐户中定义的至少两个贸易合作伙伴At least two trading partners that you've already defined in your integration account

添加平面文件编码操作Add flat file encode action

  1. Azure 门户的逻辑应用设计器中打开逻辑应用。In the Azure portal, open your logic app in the Logic App Designer.

  2. 在你的逻辑应用中的触发器或操作下,选择“新建步骤” > “添加操作”。 Under the trigger or action in your logic app, select New step > Add an action. 此示例使用“请求”触发器,该触发器被命名为“收到 HTTP 请求时”,用于处理来自逻辑应用外部的入站请求。This example uses the Request trigger, which is named When a HTTP request is received, and handles inbound requests from outside the logic app.

    提示

    提供 JSON 架构是可选的操作。Providing a JSON schema is optional. 如果你有来自入站请求的示例有效负载,请选择“使用示例有效负载生成架构”,输入示例有效负载,然后选择“完成”。If you have a sample payload from the inbound request, select Use sample payload to generate schema, enter the sample payload, and select Done. 架构将显示在“请求正文 JSON 架构”框中。The schema appears in the Request Body JSON Schema box.

  3. 在“选择操作”下,输入 flat fileUnder Choose an action, enter flat file. 在操作列表中选择此操作:平面文件编码From the actions list, select this action: Flat File Encoding

    选择“平面文件编码”操作

  4. 在“内容”框中单击,以显示动态内容列表。Click inside the Content box so that the dynamic content list appears. 从列表的“收到 HTTP 请求时”部分选择“正文”属性,其中包含来自触发器的请求正文输出和要编码的内容。From the list, in the When a HTTP request is received section, select the Body property, which contains the request body output from the trigger and the content to encode.

    从动态内容列表中选择要编码的内容

    提示

    如果在动态内容列表中未看到“正文”属性,请选择“收到 HTTP 请求时”节标签旁边的“查看更多”。 If you don't see the Body property in the dynamic content list, select See more next to the When a HTTP request is received section label. 还可以直接在“内容”框中输入要解码的内容。You can also directly enter the content to decode in the Content box.

  5. 从“架构名称”列表中,选择你的关联集成帐户中要用于编码的架构,例如:From the Schema Name list, select the schema that's in your linked integration account to use for encoding, for example:

    选择要用于编码的架构

    备注

    如果列表中未显示任何架构,则表明你的集成帐户未包含任何可用于编码的架构文件。If no schema appears in the list, your integration account doesn't contain any schema files to use for encoding. 请将你要使用的架构上传到你的集成帐户。Upload the schema that you want to use to your integration account.

  6. 保存逻辑应用。Save your logic app. 若要测试连接器,请向 HTTPS 终结点(显示在“请求”触发器的“HTTP POST URL”属性中)发出一个请求,并在请求正文中包含要编码的 XML 内容。To test your connector, make a request to the HTTPS endpoint, which appears in the Request trigger's HTTP POST URL property, and include the XML content that you want to encode in the request body.

你现在已经完成了平面文件编码操作的设置。You're now done with setting up your flat file encoding action. 在实际应用中,你可能需要将已编码的数据存储在业务线 (LOB) 应用(如 Salesforce)中。In a real world app, you might want to store the encoded data in a line-of-business (LOB) app, such as Salesforce. 你也可以将已编码的数据发送给贸易合作伙伴。Or, you can send the encoded data to a trading partner. 若要将编码操作的输出发送到 Salesforce 或贸易合作伙伴,请使用其他在 Azure 逻辑应用中提供的连接器To send the output from the encoding action to Salesforce or to your trading partner, use the other connectors available in Azure Logic Apps.

添加平面文件解码操作Add flat file decode action

  1. Azure 门户的逻辑应用设计器中打开逻辑应用。In the Azure portal, open your logic app in the Logic App Designer.

  2. 在你的逻辑应用中的触发器或操作下,选择“新建步骤” > “添加操作”。 Under the trigger or action in your logic app, select New step > Add an action. 此示例使用“请求”触发器,该触发器被命名为“收到 HTTP 请求时”,用于处理来自逻辑应用外部的入站请求。This example uses the Request trigger, which is named When a HTTP request is received, and handles inbound requests from outside the logic app.

    提示

    提供 JSON 架构是可选的操作。Providing a JSON schema is optional. 如果你有来自入站请求的示例有效负载,请选择“使用示例有效负载生成架构”,输入示例有效负载,然后选择“完成”。If you have a sample payload from the inbound request, select Use sample payload to generate schema, enter the sample payload, and select Done. 架构将显示在“请求正文 JSON 架构”框中。The schema appears in the Request Body JSON Schema box.

  3. 在“选择操作”下,输入 flat fileUnder Choose an action, enter flat file. 在操作列表中选择此操作:平面文件解码From the actions list, select this action: Flat File Decoding

    选择“平面文件解码”操作

  4. 在“内容”框中单击,以显示动态内容列表。Click inside the Content box so that the dynamic content list appears. 从列表的“收到 HTTP 请求时”部分选择“正文”属性,其中包含来自触发器的请求正文输出和要解码的内容。From the list, in the When a HTTP request is received section, select the Body property, which contains the request body output from the trigger and the content to decode.

    从动态内容列表中选择要解码的内容

    提示

    如果在动态内容列表中未看到“正文”属性,请选择“收到 HTTP 请求时”节标签旁边的“查看更多”。 If you don't see the Body property in the dynamic content list, select See more next to the When a HTTP request is received section label. 还可以直接在“内容”框中输入要解码的内容。You can also directly enter the content to decode in the Content box.

  5. 从“架构名称”列表中,选择你的关联集成帐户中要用于解码的架构,例如:From the Schema Name list, select the schema that's in your linked integration account to use for decoding, for example:

    选择要用于解码的架构

    备注

    如果列表中未显示任何架构,则表明你的集成帐户未包含任何可用于解码的架构文件。If no schema appears in the list, your integration account doesn't contain any schema files to use for decoding. 请将你要使用的架构上传到你的集成帐户。Upload the schema that you want to use to your integration account.

  6. 保存逻辑应用。Save your logic app. 若要测试连接器,请向 HTTPS 终结点(显示在“请求”触发器的“HTTP POST URL”属性中)发出一个请求,并在请求正文中包含要解码的 XML 内容。To test your connector, make a request to the HTTPS endpoint, which appears in the Request trigger's HTTP POST URL property, and include the XML content that you want to decode in the request body.

你现在已经完成了平面文件解码操作的设置。You're now done with setting up your flat file decoding action. 在实际应用中,你可能需要将已解码的数据存储在业务线 (LOB) 应用(如 Salesforce)中。In a real world app, you might want to store the decoded data in a line-of-business (LOB) app, such as Salesforce. 你也可以将已解码的数据发送给贸易合作伙伴。Or, you can send the decoded data to a trading partner. 若要将解码操作的输出发送到 Salesforce 或贸易合作伙伴,请使用其他在 Azure 逻辑应用中提供的连接器To send the output from the decoding action to Salesforce or to your trading partner, use the other connectors available in Azure Logic Apps.

后续步骤Next steps