Why does this extension method not initialize the returned object?

110 views Asked by At

I wrote a generic Extension helper method to initialize some parameters of a SoapHeader, however it is not updating the returned object.

What am I missing?

using System.Web.Services.Protocols;

    public class Header: SoapHeader {}

    public class WS {
      public Header securityHeader {
        get;
        set;
      }

    }
    public static class SecurityHeaderExtensions {

      public static T GetSecurityHeader < T > (this T header, string actor, string role) where T: SoapHeader, new() {

        T result = new T() {
          Actor = actor, Role = role
        };

        Console.WriteLine("Actor: " + actor); //prints actor
        Console.WriteLine("Actor: " + result.Actor); //prints blank
        return result;

      }
    }

    void Main() {
      var ws = new WS();
      ws.securityHeader = ws.securityHeader.GetSecurityHeader("actor", null);

    }
1

There are 1 answers

1
nvoigt On BEST ANSWER

It seems that Actor and Role are the same field internally.

Setting it to actor then setting it to null means that it's null.

The recipient of that data, known as the SOAP Role in version 1.2 of the SOAP specification and the SOAP Actor in version 1.1