azure-api-management - 无法使用 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>
解决方案
您不必为命名空间添加前缀。此请求有效
<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>
我可以看到您的请求存在两个潜在问题。
- 您可能缺少
SOAPAction
标题,例如 submitOrder
<set-header name="SOAPAction" exists-action="override">
<value>http://tempuri.org/IFazioService/submitOrder</value>
</set-header>
- 此外,您可能希望设置后端 url 并重写资源路径(如果 APIM 路径与 SOAP 服务不同)
<set-backend-service base-url="{{s-iserve-store-inventory-backend-url}}" />
<rewrite-uri template="?" copy-unmatched-params="false" />
推荐阅读
- hyperledger-fabric - Hyperledger Fabric - 实现交易类型并为每种交易类型配置背书策略
- bash - Bash遍历数组 - 获取索引
- python - xlwings 错误:未打开 excel 工作簿在调用 wb.open 时出现错误
- html - 在 html 表上结合锚点偏移和目标样式
- reactjs - 状态未在 React Router v5 中传递
- typescript - 打字稿模数不起作用:测试失败
- reactjs - React Axios 调用返回整个函数
- haskell - 给定类型级别的起始 KnownNat,查找 KnownNat 的下一个因子
- java - 上下文表单循环中的多个 RestTemplateBuilders
- excel - 基于带有宏的模板创建第二个文档后文件损坏