You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求助:Outlook邮件中Adaptive Cards通过C# WCF服务刷新失败

Outlook中Adaptive Cards点击Accept按钮后无法更新的问题排查与修复

问题场景

在Outlook邮件中实现Adaptive Cards操作按钮,采用.NET4.5 WCF服务调用刷新接口更新卡片。Adaptive Cards版本设为1.0,JSON payload通过AdaptiveCards Designer设计。点击「Accept」操作按钮后,卡片始终无法更新,返回的JSON格式验证为有效,但问题仍存在。

提供的代码片段

WCF接口定义

[OperationContract]
[WebInvoke(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, Method = "POST")]
JSONObject 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;
}

目标更新卡片JSON

{
    "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(已验证有效)

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

排查与修复步骤

1. 修正WCF返回类型与序列化逻辑

使用JSONObject作为返回类型可能导致额外的序列化包装或格式偏差。建议直接返回原始JSON字符串,避免中间类型转换:

修改接口定义:

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

修改实现方法:

public string adaptiveCardsRefresh()
{
    var jsonStr = GetAdaptiveCardContent("workFlowEmailApproved.json");
    
    WebOperationContext.Current.OutgoingResponse.Headers.Add("CARD-UPDATE-IN-BODY", "true");
    WebOperationContext.Current.OutgoingResponse.ContentType = "application/json";
    
    return jsonStr;
}

2. 确保HTTP响应头正确传递

Outlook对响应头的大小写和准确性敏感,若WCF原生方式无法正确发送CARD-UPDATE-IN-BODY头,改用HttpResponseMessage控制响应:

修改接口与实现:

[OperationContract]
[WebInvoke(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, Method = "POST")]
HttpResponseMessage adaptiveCardsRefresh();
public HttpResponseMessage adaptiveCardsRefresh()
{
    var jsonStr = GetAdaptiveCardContent("workFlowEmailApproved.json");
    var response = new HttpResponseMessage(HttpStatusCode.OK)
    {
        Content = new StringContent(jsonStr, Encoding.UTF8, "application/json")
    };
    response.Headers.Add("CARD-UPDATE-IN-BODY", "true");
    return response;
}

3. 验证Originator ID一致性

originator字段必须与发送原始邮件卡片时使用的ID完全匹配,该ID需从Microsoft 365管理中心获取,用于卡片合法性校验。确认<my-originator-id>已替换为真实有效ID。

4. 检查原始卡片的Action.Submit配置

确保原始邮件中的按钮配置正确指向WCF接口,示例配置:

{
    "type": "Action.Submit",
    "title": "Accept",
    "url": "https://your-wcf-service-domain/adaptiveCardsRefresh",
    "data": {
        "action": "accept"
    }
}

5. 配置WCF跨域访问

若WCF服务与Outlook不在同一域,需在web.config中添加CORS配置:

<system.webServer>
  <httpProtocol>
    <customHeaders>
      <add name="Access-Control-Allow-Origin" value="*" />
      <add name="Access-Control-Allow-Methods" value="POST, GET, OPTIONS" />
      <add name="Access-Control-Allow-Headers" value="Content-Type" />
    </customHeaders>
  </httpProtocol>
</system.webServer>

6. 验证Outlook客户端兼容性

Adaptive Cards 1.0的更新功能仅支持:

  • Outlook桌面客户端2016及以上版本
  • 最新版Outlook Web App
  • Exchange Online环境(本地Exchange服务器部分版本不支持)

验证方法

  1. 用Postman直接调用WCF接口,检查响应头是否包含CARD-UPDATE-IN-BODY: true,且响应体为有效Adaptive Card JSON。
  2. 打开Outlook网页版开发者工具(F12),查看控制台是否有404、CORS或JSON格式错误日志。
  3. 确认发送原始卡片与更新卡片的originatorID完全一致。

内容的提问来源于stack exchange,提问作者Max Cheung

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 06:20:54