tags:

views:

10

answers:

1

Hi,

We try to generate web service proxy class using ServiceContractGenerator.
We get problem at using web services that returns DataTable.

Generated code for DataTable below

public partial class MethodResultOfDataTableymujubN2Result
{

    private System.Xml.XmlElement[] anyField;

    private System.Xml.XmlElement any1Field;

    /// <remarks/>
    [System.Xml.Serialization.XmlAnyElementAttribute(Namespace="http://www.w3.org/2001/XMLSchema", Order=0)]
    public System.Xml.XmlElement[] Any
    {
        get
        {
            return this.anyField;
        }
        set
        {
            this.anyField = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlAnyElementAttribute(Namespace="urn:schemas-microsoft-com:xml-diffgram-v1", Order=1)]
    public System.Xml.XmlElement Any1
    {
        get
        {
            return this.any1Field;
        }
        set
        {
            this.any1Field = value;
        }
    }
}

References.cs class can handle DataTable, and return DataTable object

[System.Runtime.Serialization.DataMemberAttribute()]
public System.Data.DataTable Result { ...

How can we handle DataTable for generating web service proxy class?

A: 

below method solve the problem

WsdlImporter wsdlImporter = CreateWsdlImporter(address);
AddStateForDataContractSerializerImport(wsdlImporter);

...

private void AddStateForDataContractSerializerImport(WsdlImporter importer)
{
    XsdDataContractImporter xsdDataContractImporter = new XsdDataContractImporter();
    xsdDataContractImporter.Options = new ImportOptions();

    xsdDataContractImporter.Options.ImportXmlType = true;
    xsdDataContractImporter.Options.GenerateSerializable = true;
    xsdDataContractImporter.Options.ReferencedTypes.Add(typeof(DataTable));

    importer.State.Add(typeof(XsdDataContractImporter), xsdDataContractImporter);
}
pirimoglu