如何在ASP.NET Core中读取SOAP信封头体?[重复]

问题描述 投票:-1回答:1

我需要在ASP.NET WCF服务中使用SoapCore读取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>

谁能帮我解析一下 soapenv:Header 在.NET Core中请求?

先谢谢你

asp.net wcf core
1个回答
0
投票

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();
    }
}

在我的代码中,它得到了SOAP消息的第一个头,而且头的类型是字符串。

关于MessageHeaders的更多信息,请参考以下链接。

https:/docs.microsoft.comen-usdotnetapisystem.servicemodel.channels.messageheaders.getheader?view=dotnet-plat-ext-3.1&viewFallbackFrom=netcore-3.0。

© www.soinside.com 2019 - 2024. All rights reserved.