locked
XmlInclude / SoapInclude error when trying to use custom header

    Question

  • I’m trying to create a .NET web service that talks to a Java web service.  The Java web service requires two SOAP envelopes as input parameters and a custom header.

    I create a class called “qdoc” for the custom header, add a global variable “qdocHeader” (public qdoc qdocHeader = new qdoc();) and add the following attribute to my web method:

        [WebMethod, SoapHeader("qdocHeader", Direction = SoapHeaderDirection.In), System.Xml.Serialization.XmlInclude(typeof(qdoc))]

    Every time I make a call to my web method through a browser, I get the following error message:

    There was an error generating the XML document.    System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidOperationException: The type qdoc was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically.

       at System.Xml.Serialization.XmlSerializationWriter.WriteReferencedElement(String name, String ns, Object o, Type ambientType)

       at System.Xml.Serialization.XmlSerializationWriter.WriteReferencedElements()

       at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWritermyQdocWebService.Write8_processQdocMessage(Object[] p)

       at Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer.Serialize(Object objectToSerialize, XmlSerializationWriter writer)

       at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)

       --- End of inner exception stack trace ---

       at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)

       at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle)

       at System.Web.Services.Protocols.SoapHttpClientProtocol.Serialize(SoapClientMessage message)

       at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)

       at myQdocWebService.processQdocMessage(SOAPEnvelope in0, SOAPEnvelope in1)

       at Service.SendToQxtendWithHeaderDiffEnv(SOAPEnvelope qdocEnv)

     
    I’ve searched over the Internet and the consistent answer to this problem seems to be to add (as the error message says) XmlInclude or SoapInclude to the WebMethod attribute.  I’ve tried both XmlInclude and SoapInclude but I still get the same error message.

    Please, does anybody have any suggestions of what I should be doing to get this working?  I’m getting desperate.  TIA

    Thursday, August 31, 2006 9:20 PM