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

Why Does SoapEnveloper.Header<T> Require The element name? #24

Open
MerrittMelker opened this issue Sep 1, 2016 · 2 comments
Open

Why Does SoapEnveloper.Header<T> Require The element name? #24

MerrittMelker opened this issue Sep 1, 2016 · 2 comments
Assignees
Milestone

Comments

@MerrittMelker
Copy link

Why not just use the attributes attached to the class? It seems redundant.

[XmlRoot("MeowHeader", Namespace= "http://meow.com/")]
public class MeowResponseHeader : SimpleSOAPClient.Models.SoapHeader
{
  public string Status { get; set; }
  public string Message { get; set; }
}

var header = responseEnvelope
  .Header<MeowResponseHeader >("{http://meow.com/}MeowHeader");

I kept looking for:

var header = responseEnvelope.Header<MeowResponseHeader >();

but had to write it myself...

@MerrittMelker
Copy link
Author

(using .net core - was getting weirdness with just GetType())

    public static class SoapEnvelopeExtensions
    {
        public static T Header<T>(this SoapEnvelope envelope) where T : SoapHeader
        {
            var typeInfo = envelope.GetType().GetTypeInfo();
            var attribute = typeInfo.GetCustomAttribute<XmlRootAttribute>();
            var name = $"{attribute.Namespace}{attribute.ElementName}";
            return envelope.Header<T>(name);
        }
    }

@gravity00
Copy link
Owner

Great suggestion! You are completely right, never thought about that. I'll include it in the next release.

Note: yes, they made some changes in .NET Core about reflection (https://blogs.msdn.microsoft.com/dotnet/2016/02/10/porting-to-net-core/). I'll have to use different code by framework compilation.

@gravity00 gravity00 added this to the Version 2.0.0 milestone Sep 1, 2016
@gravity00 gravity00 self-assigned this Sep 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants