How To Pass Soap Header When WSDL Doesn't Define It?

后端 未结 4 1681
走了就别回头了
走了就别回头了 2020-12-19 19:09

I have a web service that I am calling and their published WSDL doesn\'t actually define much of the service, 3/4 of it you have to manually build afterwards.

The pr

4条回答
  •  粉色の甜心
    2020-12-19 19:44

    If you need fine grain control over how the soap header xml gets rendered (happens when interfacing with a webservice written with java), you can always override all rendering by implementing IXmlSerializable

    [XmlRoot("customHeader", Namespace = "http://somecompany.com/webservices/security/2012/topSecret")]
    public class customHeader: SoapHeader, IXmlSerializable
    {
        public customHeader()
        {
            Actor = "http://schemas.xmlsoap.org/soap/actor/next";
            MustUnderstand = false;
        }
    
        public System.Xml.Schema.XmlSchema GetSchema()
        {
            return null;
            //throw new NotImplementedException();
        }
    
        public void ReadXml(XmlReader reader)
        {
            //throw new NotImplementedException();
        }
    
        public void WriteXml(XmlWriter writer)
        {
            writer.WriteAttributeString("soap:actor", Actor);
            writer.WriteAttributeString("soap:mustUnderstand", MustUnderstand ? "1" : "0");
            writer.WriteRaw("some encrypted data");
            //get it exactly the way you want it in here without mucking with Xml* property attributes for hours on end
            //writer.WriteElement(...);
        }
    }
    

提交回复
热议问题