SoapCore icon indicating copy to clipboard operation
SoapCore copied to clipboard

The SOAP request header (message) is not filled in ISoapMessageProcessor (Suspected message encoding problem UTF-16)

Open ComradeSwarog opened this issue 1 year ago • 1 comments

The SOAP request header (message) is not filled in ISoapMessageProcessor (Suspected message encoding problem UTF-16)

Package version SoapCore 1.1.0.41 Asp Net Core 6

This is how I initialize SOAP the service

var builder = WebApplication.CreateBuilder(args);

var settings = new Settings();
builder.Configuration.Bind(settings);
builder.Services.AddSingleton<ISettings>(settings);

builder.Services.AddSoapCore();
builder.Services.AddScoped<emdrClientCallbackPort, EmdrCallbackService>();
builder.Services.AddSoapMessageProcessor<SingSoapMessageProcessor>();

var app = builder.Build();

app.UseRouting();

app.UseEndpoints(endpoints =>
{
    endpoints.UseSoapEndpoint<emdrClientCallbackPort>(options =>
    {
        options.Path = "/Service.wsdl";
        options.EncoderOptions = new []
        {
            new SoapEncoderOptions
            {
                MessageVersion = MessageVersion.Soap12WSAddressingAugust2004,
                WriteEncoding = Encoding.UTF8,
                OverwriteResponseContentType = true
            }
        };
        options.SoapSerializer = SoapSerializer.XmlSerializer;
        options.OmitXmlDeclaration = true;
        options.AdditionalEnvelopeXmlnsAttributes = new Dictionary<string, string>
        {
            {
                "oas", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
            },
            {
                "wsa", "http://www.w3.org/2005/08/addressing"
            },
            {
                "wsse", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
            }
        };
    });
});

This is how I implement the interface ISoapMessageProcessor

public class SingSoapMessageProcessor :ISoapMessageProcessor
{
    private readonly ISettings _settings;

    public SingSoapMessageProcessor(ISettings settings)
    {
        _settings = settings;
    }

    public async Task<Message> ProcessMessage(Message message, HttpContext context, Func<Message, Task<Message>> next)
    {
        var action = message.Headers.Action; // this value is null
        var to = message.Headers.To; // this value is null
        var messageId = message.Headers.MessageId; // // this value is null

        var responce = await next(message);

        var action2 = message.Headers.Action; // this value is null after the call next
        var to2 = message.Headers.To; // this value is null after the call next
        var messageId2 = message.Headers.MessageId; // // this value is null after the call next

But the message header is filled with parameters, but when debugging it is clear that they are encoded in UTF-16, but should be in UTF-8, since the content type of the request is HTTP = text/xml; charset=utf-8

изображение

Help me solve this problem or indicate the version of the package where this problem does not occur, thanks.

ComradeSwarog avatar Feb 01 '24 19:02 ComradeSwarog

That seems odd. I don't really have the time to dive into this at the moment but I've done an overview. I don't think there is a version of the package where this doesn't occur

If you want to fix this your first stop should probably be https://github.com/DigDes/SoapCore/blob/af7107b5fc4802bcbef2999bbd33e8eeb9a5de23/src/SoapCore/MessageEncoder/SoapMessageEncoder.cs#L132-L165 This is where the message gets parsed out. There is a method in SoapMethodEncoderDefaults for parsing encoding from the content. That might be where things go wrong. https://github.com/DigDes/SoapCore/blob/af7107b5fc4802bcbef2999bbd33e8eeb9a5de23/src/SoapCore/MessageEncoder/SoapMessageEncoderDefaults.cs#L46-L64

andersjonsson avatar Feb 05 '24 10:02 andersjonsson

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar Mar 07 '24 01:03 github-actions[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale.

github-actions[bot] avatar Mar 21 '24 02:03 github-actions[bot]