【问题标题】:AdaptiveCards action refresh cards does not work using C# WCF ServicesAdaptiveCards 操作刷新卡无法使用 C# WCF 服务
【发布时间】:2023-01-20 08:09:10
【问题描述】:

我在通过 Outlook 电子邮件进行自适应卡片刷新时遇到问题。我在 Outlook 电子邮件中实现了一个操作按钮。我使用 .net4.5 WCF 调用刷新服务并尝试刷新卡片。我的自适应卡版本设置为 1.0,JSON 有效负载是从 MS adaptiveCards Designer here 设计的。

点击后“接受”通过电子邮件的操作按钮。

它每次都显示此错误并且卡没有更改。

世界城市基金会:

[OperationContract]
[WebInvoke(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, Method = "POST")]
JSONObject adaptiveCardsRefresh();

adaptiveCardsRefresh 方法:

public JSONObject adaptiveCardsRefresh()
{
  JSONObject obj = new JSONObject();   
  var jsonStr = GetAdaptiveCardContent("workFlowEmailApproved.json");
  obj = JsonConvert.DeserializeObject<JSONObject>(jsonStr);

  WebOperationContext.Current.OutgoingResponse.Headers.Add("CARD-UPDATE-IN-BODY", "true");
  WebOperationContext.Current.OutgoingResponse.ContentType = "application/json";
    
  return obj;
}

workFlowEmailApproved.json(已在 MS Adaptivecards Designer 中测试):

{
    "type": "AdaptiveCard",
    "version": "1.0",
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "originator": "<my-originator-id>",        
    "body": [
        {
            "type": "TextBlock",
            "text": "The action has been recorded."
        }
    ]
}

我尝试注销返回对象,它作为有效的 JSON 格式似乎很正常:

Return SerializeObject: {"type":"AdaptiveCard","$schema":"http://adaptivecards.io/schemas/adaptive-card.json","originator":"<my-originator-id>","body":[{"type":"TextBlock","text":"The action has been recorded."}]}

【问题讨论】:

  • 查找更详细的日志,帮助定位问题。在您的案例中正常返回 json 字符串表明该方法有效,但问题出在其他地方。

标签: c# asp.net wcf outlook adaptive-cards


【解决方案1】:

我认为在您的请求中,您需要确保您的帖子请求具有以下标头

  1. 授权=“”
  2. Content-type = "application/json"

    当我没有 Authorization 标头时,我收到了类似的错误消息。我认为这是因为 Outlook 会自动发送自己的 Bearer 令牌,否则

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多