An Azure service that provides a hybrid, multi-cloud management platform for APIs.
Instead of a cast, try using Guid.NewGuid().ToString().
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi, we want to use message-id to correlate request/response log and return this message-id to the client for future issue solving.
What bothers us is how we reuse message-id in the set-header
<policies>
<inbound>
<set-variable name="message-id" value="@(Guid.NewGuid())" />
<log-to-eventhub logger-id="logger1" partition-id="1">@{
var jsonReq = new JObject(
new JProperty("message-type", "request"),
new JProperty("message-id", context.Variables["message-id"]))
);
return jsonReq.ToString()
}
</log-to-eventhub>
</inbound>
<outbound>
<log-to-eventhub logger-id="logger1" partition-id="2">@{
var jsonRes = new JObject(
new JProperty("message-type", "response"),
new JProperty("message-id", context.Variables["message-id"]))
);
return jsonRes.ToString()
}
</log-to-eventhub>
<set-header name="message-id" exists-action="append">
<value>@(context.Variables["message-id"])</value>
</set-header>
<outbound>
Here's what we've tried so far
@(context.Variables["message-id"])
==> can't save . error msg : Cannot implicitly convert type 'object' to 'string'. An explicit conversion exists (are you missing a cast?)
@((string)context.Variables["message-id"])
@(context.Variables.GetValueOrDefault<string>("message-id"))
==> can save, but failed when postman call
{ "statusCode": 500, "message": "Internal server error", "activityId": "xxxx" }
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
Answer accepted by question author
Instead of a cast, try using Guid.NewGuid().ToString().