我需要在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中请求?
先谢谢你
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的更多信息,请参考以下链接。