[英]How to access the SOAP HEADER in C#
如何将SOAP标头访问到一个类中。 场景:SOAP请求从客户端发送到Web服务。
[SoapHeader("transactionInfo", Direction = SoapHeaderDirection.In)]
public byte[] method1(DocumentInfo templateInfo,System.Xml.XmlDocument xml,string Name)
{"code to get the tags in soap header"}
如果您的代码正常运行,您将发现在WebService
类中定义了一个名为transactionInfo
的字段。 该字段将包含反序列化形式的SOAP Header。
我从来没有做过,但是我怀疑如果transactionInfo
字段的类型为XmlElement
,那么您将能够以XML的形式访问它。 否则,您将能够作为C#对象访问它。
1-定义您的自定义SoapHeader
public class transactionInfo: System.Web.Services.Protocols.SoapHeader
{
public string Info;
}
2-在Web服务中定义标头
[WebService(Namespace = "http://..")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class MyWebService : System.Web.Services.WebService
{
public transactionInfo Header { get; set; }
...
3-在您的Web服务中定义使用此SoapHeader的方法
[SoapHeader("transactionInfo", Direction = SoapHeaderDirection.InOut)]
public void MyMethod()
{
}
[这是您问题的答案]
4-使用属性从方法MyMethod访问标头的值
if (Header.Info == "none")...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.