Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(meta-wsdl): add support for soap:header #1063

Merged
merged 1 commit into from
Aug 19, 2024

Conversation

Yozer
Copy link
Contributor

@Yozer Yozer commented May 31, 2024

This implements the soap:header for MetaWritter.
https://learn.microsoft.com/pl-pl/dotnet/api/system.web.services.protocols.soapheader?view=netframework-4.8.1
I created new SoapHeader attribute that mimics the the SoapHeader from net framework.
Users can derive from it and decorate methods on the service.

@andersjonsson what is the recommended way to get the header and inject it into the service?
In my soap service I simply extended the IServiceOperationTuner so it also has Message.
Then I could do that to deserialize my header and inject it:

public class SoapHeaderOperationTuner : IServiceOperationTuner
{
    public void Tune(HttpContext httpContext, object serviceInstance, SoapCore.ServiceModel.OperationDescription operation, Message message)
    {
        if (operation.HeaderType is null)
            return;

        var service = (serviceInstance as MyService)!;

        var headerName = operation.HeaderType.Name;
        var contractNamespace = operation.Contract.Namespace;

        var headerIndex = message.Headers.FindHeader(headerName, contractNamespace);
        if (headerIndex < 0) 
            return;

        var header = message.Headers[headerIndex].ToString();
        if (string.IsNullOrEmpty(header))
            return;

        var xml = new XmlDocument();
        xml.LoadXml(header);
        if(xml.DocumentElement == null)
            return;

        using var nodeReader = new XmlNodeReader(xml.DocumentElement);
        var serializer = CachedXmlSerializer.GetXmlSerializer(operation.HeaderType, headerName, contractNamespace);

        var deserializedHeader = serializer.Deserialize(nodeReader);
        if (deserializedHeader is AuthenticationContext authHeader)
            service.AuthenticationContextHeader = authHeader;
    }
}

@Yozer Yozer changed the title feat(meta): add support for soap:header feat(meta-wsdl): add support for soap:header May 31, 2024
@andersjonsson
Copy link
Collaborator

@andersjonsson what is the recommended way to get the header and inject it into the service? In my soap service I simply extended the IServiceOperationTuner so it also has Message. Then I could do that to deserialize my header and inject it:

You could use an ISoapMessageProcessor to parse the header from the Message and then add the header to httpContext.Items

@Yozer
Copy link
Contributor Author

Yozer commented Jul 10, 2024

@andersjonsson bump :)

@andersjonsson andersjonsson merged commit a2bcb47 into DigDes:develop Aug 19, 2024
3 checks passed
@andersjonsson
Copy link
Collaborator

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants