Custom SOAP Headers: WCF and ASMX

First the good news, WCF clients should just work with ASMX services that use custom SOAP headers.

Now the not so good news, ASMX clients will work with WCF services that use headers, but the object model is pretty funky.  Say you want to do something really crazy like have a header of type string.  The ASMX client will represent that header with a class that looks like this:

[System.Xml.Serialization.XmlTypeAttribute(Namespace="https://www.w3.org/2001/XMLSchema")]
[System.Xml.Serialization.XmlRootAttribute("StringHeader", Namespace="https://xwsinterop/soapwsdl/headers", IsNullable=true)]
public partial class @string : System.Web.Services.Protocols.SoapHeader {
   
    private string[] textField;
   
    /// <remarks/>
    [System.Xml.Serialization.XmlTextAttribute()]
    public string[] Text {
        get {
            return this.textField;
        }
        set {
            this.textField = value;
        }
    }
}

To use this class, assign a new string array of length 1 to Text and then assign the value of the header to that element and it will work as expected.  These sorts of classes will be generated by ASMX for any simple type, the workaround is to use wrapper classes around the headers on the WCF side.  This will result in a somewhat clunky OM, but it will make sense.