【问题标题】:Expression inside set-body policy not workingset-body 策略中的表达式不起作用
【发布时间】:2021-02-05 09:28:34
【问题描述】:

我不知道我做错了什么,但内部获取值形式变量的表达式在发送请求策略中的 set-body 策略中不起作用。同样的事情也适用于回复。 场景是我必须进行 2 次调用,我将在第一次调用中将数据作为输入传递给第二次调用。 E.G

<set-body template="liquid">
                        <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:tem="http://tempuri.org/">
                            <soap:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
        
                            </soap:Header>
                            <soap:Body>
                                <tem:GetSomething>
                                    <tem:contactId>
                                    @{ context.Variables.GetValueOrDefault<string>("ContactId").ToString(); }
                                    </tem:contactId>
                                </tem:GetSomething>
                            </soap:Body>
                        </soap:Envelope>
                    </set-body>

Here In ContactId 是我创建的变量,其中包含来自第一个调用输出的值。 上面的 sn-p 线出现以下错误

**'There was an error deserializing the object of type System.Guid. The value '
                                    @{ context.Variables.GetValueOrDefault&lt;string&gt;("ContactId").ToString(); }
                                    ' cannot be parsed as the type 'Guid'.'.  Please see InnerException for more details.**

谁能告诉我缺少什么

【问题讨论】:

    标签: azure azure-api-management policy


    【解决方案1】:

    来自Codit Blog

    访问上下文变量

    上下文变量也可以从 Liquid 模板中访问。与 C# 表达式相比,有一个类似的对象模型,但语法不同。例如,在 C# 中读取查询字符串参数的工作方式如下:@(context.Request.Url.Query.GetValueOrDefault(“orderId”, “”)). 在 Liquid 模板中,您需要应用以下符号:{{context.Request.Url.Query[“orderId”]}}

    【讨论】:

      猜你喜欢
      • 2019-08-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-19
      • 2013-03-30
      • 2023-04-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多