Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在ASP.NET核心中读取SOAP信封头/正文?_Asp.net_Wcf_Core - Fatal编程技术网

如何在ASP.NET核心中读取SOAP信封头/正文?

如何在ASP.NET核心中读取SOAP信封头/正文?,asp.net,wcf,core,Asp.net,Wcf,Core,我需要使用SoapCore读取ASP.NET WCF服务中的SOAP信封头 这是soap标头示例: <soapenv:Header> <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/ws

我需要使用SoapCore读取ASP.NET WCF服务中的SOAP信封头

这是soap标头示例:

<soapenv:Header>
    <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" 
                   xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
        <wsse:UsernameToken wsu:Id="UsernameToken-5351BA8068B753C930158868612679914">
            <wsse:Username>test user</wsse:Username>
            <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">CS++k5OEqKsJByVPPmUqcBkAeoQ=</wsse:Password>
            <wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">VK+Ilb/zy80lFbfHAAQupg==</wsse:Nonce>
            <wsu:Created>2020-05-05T13:42:06.798Z</wsu:Created>
        </wsse:UsernameToken>
    </wsse:Security>
</soapenv:Header>

测试用户
CS++k5OEqKsJByVPPmUqcBkAeoQ=
VK+Ilb/zy80lFbfHAAQupg==
2020-05-05T13:42:06.798Z
有人能帮我在.NETCore中解析这个
soapenv:Header
请求吗


提前感谢

SoapCore中有IMessageinspector接口:

     using System.ServiceModel.Channels;
     namespace SoapCore.Extensibility
     {
             public interface IMessageInspector
               {
                   object AfterReceiveRequest(ref Message message);
                   void BeforeSendReply(ref Message reply, object correlationState);
               }
      }
您可以实现IMessageinspector,然后在实现类中获取SOAP消息的头

        public class MessageLogger : IMessageInspector
{
    public object AfterReceiveRequest(ref Message message)
    {
        message.Headers.GetHeader<string>(0);
        return null;
    }

    public void BeforeSendReply(ref Message reply, object correlationState)
    {
        throw new NotImplementedException();
    }
}
公共类消息记录器:IMessageInspector
{
公共对象AfterReceiveRequest(参考消息消息)
{
message.Headers.GetHeader(0);
返回null;
}
SendReply之前的公共无效(参考消息回复,对象关联状态)
{
抛出新的NotImplementedException();
}
}
在我的代码中,它获取SOAP消息的第一个头,头的类型为string

有关MessageHeader的更多信息,请参阅以下链接:


这似乎是wsu:Created元素中的时间戳-的副本