如何将安全标头发送到WCF服务

时间:2018-06-08 00:10:50

标签: wcf soap asp.net-core wsdl xelement

您好我一直在与WCF服务集成。我使用WSDL链接生成对WCF的调用。

我总是收到一条消息SOAP Header需要用户名/密码,但我不知道我做错了什么。

当我通过SOAPUI完成请求时,工作正常。

问题是该方法接收两个对象。第一个是普通有效载荷,第二个参数是这种类型:

public partial class SecurityHeaderType
{

    private System.Xml.Linq.XElement[] anyField;

    /// <remarks/>
    [System.Xml.Serialization.XmlAnyElementAttribute(Order=0)]
    public System.Xml.Linq.XElement[] Any
    {
        get
        {
            return this.anyField;
        }
        set
        {
            this.anyField = value;
        }
    }
}

我通过XElements创建信封:

XElement securityHeaderXml = new XElement(soapenv + "Envelope",
    new XAttribute(XNamespace.Xmlns + "soapenv", "http://schemas.xmlsoap.org/soap/envelope/"),
    new XAttribute(XNamespace.Xmlns + "oas", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"),
    new XAttribute(XNamespace.Xmlns + "ns", "http://www.opentravel.org/OTA/2003/05"),
    new XElement(soapenv + "Header",
    new XElement(oas + "Security",
      new XElement(oas + "UsernameToken",
        new XElement(oas + "Username", "someusername"),
        new XElement(oas + "Password", "somepassword",
          new XAttribute("Type",
            "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText"))
      ))), new XElement(soapenv + "Body",
      new XElement(ns + "OTA_HotelAvailNotifRQ",
        new XAttribute("EchoToken", "abc123"),
        new XAttribute("Version", "1.0"),
        new XAttribute("ResStatus", "Commit"),
        new XAttribute("TimeStamp", DateTime.Now),
        new XElement("AvailStatusMessages", new XAttribute("HotelCode", hotelCode)
          , new XElement("AvailStatusMessage", new XAttribute("BookingLimit", 10),
            new XElement("StatusApplicationControl", new XAttribute("Start", DateTime.Now),
              new XAttribute("End", DateTime.Now.AddDays(4)),
              new XAttribute("InvTypeCode", "A1K"), new
                XAttribute("RatePlanCode", "GLD")
            ))))));

如果有人可以帮助我,我会很感激!!

1 个答案:

答案 0 :(得分:0)

string[x]