首页 > 解决方案 > OperationContext.Current 在 .net 核心中为空

问题描述

我通过SoapCore在我的 .net 核心项目中提供 WCF 服务。在其中一种方法中,我想访问 SOAP 信封头信息。为了测试这一点,我添加了以下代码:

[ServiceContract]
public interface IDataService {
    [OperationContract]
    string TransmitObject(XElement node);
}

// -------------------------------------------------------------------------

public string TransmitObject(XElement node) {
    foreach(var header in OperationContext.Current.IncomingMessageHeaders) {
        Console.WriteLine(header.ToString());
    }

    return JsonConvert.SerializeXNode(node, Formatting.None);
}

但是,在这种情况下, OperationContext.Current 属性始终为null。为了使这项工作有效,我需要进行哪些更改?

标签: c#wcfsoap.net-coreoperationcontext

解决方案


推荐阅读