4

I want to call an external SOAP service which i want to generate proxy classes for. The .wsdl is not exposed online, but provided alongside a set .xsd files. I'm then using svcutil (also tried with dotnet-svcutil 1.0.4) to generate the classes. Consider the following XML:

<xs:complexType name = "ValidationReply" abstract="false">
  <xs:complexContent>
    <xs:extension base="common:Reply">
      <xs:sequence>
        <xs:element name="data" type="ns:ValidationReplyData" minOccurs="0" maxOccurs="1"/>
      </xs:sequence>
    </xs:extension>
  </xs:complexContent>
</xs:complexType>
<xs:complexType name="ValidationReplyData" abstract="false">
  <xs:sequence>
    <xs:element name="errors" type="ns:Error" minOccurs="0" maxOccurs="unbounded"/>
  </xs:sequence>
</xs:complexType>

Generates the following code:

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("dotnet-svcutil", "1.0.4")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="Namespace")]
public partial class ValidationReply: Reply
{

    private Error[] dataField;

    /// <remarks/>
    [System.Xml.Serialization.XmlArrayAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=0)]
    [System.Xml.Serialization.XmlArrayItemAttribute("errors", Form=System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable=false)]
    public Error[] data
    {
        get
        {
            return this.dataField;
        }
        set
        {
            this.dataField = value;
        }
    }
}

The issue is that the XML defines an inner type containing the list of errors, where Svcutil puts the list of errors directly as the data field, instead making the data field of type ValidationReplyData. The ValidationReplyData is not generated at all.

The code compiles without any issues and i am able to call the external service without errors. The data field is however always null as the response is on the format:

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
  <S:Body>
    <fl:ValidationReply xmlns:fw="Namespace" >
      <data>
        <errors>
          <code>236</code>
        </errors>
        <errors>
          <code>237</code>
        </errors>
      </data>
    </fl:ValidationReply>
  </S:Body>
</S:Envelope>

Which does not deserialize correctly to the generated class.

In short, does anyone know how to force Svcutil to generate all classes? Redundant or not.

I have simplified the xml snippets, so there may be some inconsistencies in the example, but the digest of the problem is the missing ValidationReplyData class-

  • The xml output file has the tag "errors" so it probably due to you not putting any errors into your class that you serialized. – jdweng Feb 21 '19 at 10:10
  • Hi. I am not implementing the external service myself. There will be data in the clause when the service is called. I omitted it here for simplicity. The output xml is not used for generating the classes. – Martin Pedersen Feb 21 '19 at 10:46
  • Well you are not getting any errors from the service so that is why it is blank. Xml Serialization automatically produces the tags from the classes even if they are empty. – jdweng Feb 21 '19 at 10:59
  • I've edited the response to reflect that i do get errors. The errors are not put into the ValidationReply.data list, as the errors are wrapped in a complex type ValidationReplyData (see first xml snippet). If a manually create a c# class called ValidationReplyData containing a list of errors, and make ValidationReply.data of type ValidationReplyData , the serialization works fine and the array in ValidationReplyData is populated. – Martin Pedersen Feb 21 '19 at 11:16
  • Check whether svc is odata or odatav4 version?. Also use ".csdl or .edmx" to generate the file – Ramselvaraj Feb 21 '19 at 11:19
  • ValidationReply and ValidationReplyData both inherit the class Reply. So when you have an inheritance yo uneed in the Xml the type and in the classes you need the attribute XmlInclude. Try serialzing some sample data with original classes to see what I mean. – jdweng Feb 21 '19 at 11:24
  • How come ValidationReplyData inherit Reply, only ValidationReply has the tag ?. The response xml is not something I've generated myself, it comes from the external service, the first xml is from an .xsd file which should allow me to deserialize the response xml. I do not have access to the original classes used to serialize the response xml. – Martin Pedersen Feb 21 '19 at 11:30

0 Answers0