首页 > 解决方案 > 无法使用 Azure API 管理液体模板解析肥皂响应

问题描述

我想在将肥皂响应传递给客户端之前更改其输出格式。我正在使用文档https://azure.microsoft.com/en-ca/blog/soap-pass-through/中指定的肥皂直通

此示例中使用的 Soap 服务托管在 https://fazioapisoap.azurewebsites.net/FazioService.svc?singleWsdl

我无法在液体模板中提取肥皂响应。确实会生成肥皂响应,但是没有数据。

在此处输入图像描述

这段代码有什么问题吗?

<policies>
    <inbound>
        <set-header name="Content-Type" exists-action="override">
            <value>text/xml</value>
        </set-header>
        <set-body template="liquid">
            <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
                <soapenv:Header />
                <soapenv:Body>
                    <tem:GetOpenOrders>
                        <!--Optional:-->
                        <tem:cust>{{body.Envelope.Body.GetOpenOrders.cust}}</tem:cust>
                    </tem:GetOpenOrders>
                </soapenv:Body>
            </soapenv:Envelope>
        </set-body>
        <base />
    </inbound>
    <backend>
        <base />
    </backend>
    <outbound>
        <set-body template="liquid">
            <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
                <s:Body>
                    <GetOpenOrdersResponse xmlns="http://tempuri.org/">
                        <GetOpenOrdersResult xmlns:a="http://schemas.datacontract.org/2004/07/FazioAPISoap" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">                        
  {% for summary in body.Envelope.Body.GetOpenOrdersResponse.GetOpenOrdersResult.OrderSummary -%}
    <a:OrderSummary><a:order_id>{{summary.order_id}}</a:order_id></a:OrderSummary>
  {% endfor -%}
     </GetOpenOrdersResult>
                    </GetOpenOrdersResponse>
                </s:Body>
            </s:Envelope>
        </set-body>
        <set-header name="Content-Type" exists-action="override">
            <value>text/xml</value>
        </set-header>
        <base />
    </outbound>
    <on-error>
        <base />
    </on-error>
</policies>

标签: azure-api-managementliquid-template

解决方案


您不必为命名空间添加前缀。此请求有效

<set-body template="liquid">
    <Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
        <Body>
            <GetOpenOrdersResponse xmlns="http://tempuri.org/">
                <GetOpenOrdersResult xmlns:a="http://schemas.datacontract.org/2004/07/FazioAPISoap" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">                        
  {% for summary in body.Envelope.Body.GetOpenOrdersResponse.GetOpenOrdersResult.OrderSummary -%}
                    <OrderSummary>
                        <order_id>
                            {{summary.order_id}}
                        </order_id>
                    </OrderSummary>
  {% endfor -%}
                </GetOpenOrdersResult>
            </GetOpenOrdersResponse>
        </s:Body>
    </s:Envelope>
</set-body>

我可以看到您的请求存在两个潜在问题。

  1. 您可能缺少SOAPAction标题,例如 submitOrder
<set-header name="SOAPAction" exists-action="override">
    <value>http://tempuri.org/IFazioService/submitOrder</value>
</set-header>
  1. 此外,您可能希望设置后端 url 并重写资源路径(如果 APIM 路径与 SOAP 服务不同)
<set-backend-service base-url="{{s-iserve-store-inventory-backend-url}}" />
<rewrite-uri template="?" copy-unmatched-params="false" />

推荐阅读