从 Azure Apim 的上下文中读取命名值

Read Named values from the context in Azure Apim

我正在定义入站策略并尝试从 2 个组件构建 URL。我知道如何获得这些值 1 但 1 但是当我必须将它们组合成一个时无法弄清楚语法。

首先我调用 api 并保存响应

<send-request mode="copy" response-variable-name="createdUser" timeout="20" ignore-error="false">
        <set-url>{{Systems.One.Endpoint}}/services/rest</set-url>
</send-request> 

我可以跟踪我的反应是这样的

<trace source="Contact Id">@(((IResponse)context.Variables["createdUser"]).Body.As<JObject>()["contactId"])</trace>

但我不知道如何从 {{System.One.Endpoint}} 和 @(((IResponse)context.Variables["createdUser"]) 创建一个 url .Body.As()["contactId"])

这里不行

<send-request mode="copy" response-variable-name="createPeriod" timeout="seconds" ignore-error="true">
 <set-url>
        {{System.Two.Endpoint}}/api/@(((IResponse)context.Variables["createPeriod"]).Body.As<JObject>()["contactId"])/createperiod/{{DefaultPeriodlength}}
</set-url>

@ 之后的所有内容都只是设置为字符串,而不是从变量的实际值中加载

如何合并这两个值?

政策表达式只能用于为 element/attribute 生成完整值。合同中的命名值可用于表示任何 attribute/element 值的任何部分,并在它成为 analyzed/executed 之前插入到策略中。所以像这样:

<set-url>@("{{System.Two.Endpoint}}/api/" + ((IResponse)context.Variables["createPeriod"]).Body.As<JObject>()["contactId"].ToString() + "/createperiod/{{DefaultPeriodlength}}")</set-url>

或者如果您更喜欢字符串插值:

<set-url>@($"{{System.Two.Endpoint}}/api/{((IResponse)context.Variables["createPeriod"]).Body.As<JObject>()["contactId"]}/createperiod/{{DefaultPeriodlength}}")</set-url>