Azure API管理集合-带液体模板的主体



我有一个SOAP服务,在将请求发送到后端服务之前,我需要向XML Body添加一个属性。

我的邮差请求如下:

<?xml version="1.0" encoding="utf-8"?>
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<gprnEnquiry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.somedomain.com">
<gprn>123456</gprn>
<registrationstatus>registrationstatus1</registrationstatus>
</gprnEnquiry>
</Body>
</Envelope>

我正在传递text/xml 的Content-Type标头

我的APIM入站策略如下:

<set-body template="liquid">
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<gprnEnquiry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.somedomain.com">
<gprn>{{body.gprnEnquiry.gprn}}</gprn>
<registrationstatus>{{body.gprnEnquiry.registrationstatus}}</registrationstatus>
<authKey>{{My-NamedValue}}</authKey>
</gprnEnquiry>
</Body>
</Envelope>
</set-body>

通过在APIM中启用请求和响应主体捕获,我可以看到来自请求的值正在进入,而响应却没有值。

后端请求

<Envelope
xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<gprnEnquiry
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.somedomain.com">
<gprn></gprn>
<registrationstatus></registrationstatus>
<authKey>xxxxxxxxxxx</authKey>
</gprnEnquiry>
</Body>
</Envelope>

有人知道为什么源请求中的值没有映射到后端请求吗?

好的,这里的答案是由于请求主体的格式以及APIM策略如何映射元素。通过包括<?xml>并且请求内的信封节点阻止液体模板正确映射值。

此外,APIM不允许您指定信封在请求主体内,例如{{Envelope.body.gprnEnquiry.gprn}}。

将请求主体更改为以下内容解决了问题:

<Body>
<gprnEnquiry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.somedomain.com">
<gprn>123456</gprn>
<registrationstatus></registrationstatus>
</gprnEnquiry>
</Body>

您的路径{{body.gprnEnquiry.gprn}}不正确。如果使用此示例SOAP消息,则路径应为:{{body.Envelope.body.gprnEnquiry.gprn}},因为SOAP主体不是自动链接的。液体标签"body"代表您的完整请求。

最新更新