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);
}
It seems that
Actor
andRole
are the same field internally.Setting it to
actor
then setting it to null means that it'snull
.