0

我有一个 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>

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

4

2 回答 2

0

好的,这里的答案是由于请求正文的格式以及 APIM 策略映射元素的方式。通过在请求中包含 <?xml> 和 Envelope 节点,可以防止 Liquid 模板正确映射值。

此外,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>
于 2020-12-11T12:40:51.190 回答
-1

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

于 2021-12-10T11:27:47.473 回答