我编写了一个通用扩展帮助器方法来初始化 SoapHeader 的一些参数,但它不会更新返回的对象。
我错过了什么?
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);
}
最佳答案
看起来Actor
和Role
在内部是同一个字段。
将其设置为 actor
,然后将其设置为 null 意味着它是 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
关于c# - 为什么这个扩展方法没有初始化返回的对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30897632/