none
Why a derived DataSet class (return value) is not properly serialized by an XML Web Method? RRS feed

  • Question

  • An object derived from DataSet and returned by an XML WebMethod is not properly recreated on the client side by the VS2008SP1 client proxy generator.

    The method on the web server side:
    [WebMethod(Description = "Returns all the Inventory data records with DrugCode in Longname with given status filter")]

    public MedicationInventoryData GetAllMedicationInventoryData2b(string sFilter, bool bIncludeImages)

     

    The method on the client side in Reference.cs:
            [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/GetAllMedicationInventoryData2b", ReplyAction="*")]

            [System.ServiceModel.XmlSerializerFormatAttribute()]

            PCAS.M2.Server.CentralWSProxy.CentralWebServices.NewDataSet GetAllMedicationInventoryData2b(string sFilter, bool bIncludeImages);

     

    Enviroment: OS – Win 7, VS2008S1, Service Reference is generated as WCF reference ( default) even though the service is XML Web Service.

     

    Questions:

    1. What is wrong with this class?
    2. Can XML Web Services serialize a custom object derived from a DataSet. If yes, what are the coding requirements (constructors, attributes etc.)
      [I know WCF – Programming WCF services by Juval Lowy, p. 132 - claims it supports serialization of type-safe VS2008SP1generated DataSets, but doesn’t specify if these must be generated by VS2008. Does it really? What about custom derived DataSet? What are the requirements to the custom one? ]
    3. Will I have to implement IXmlSerializable?

     

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    The derived dataset code

    using System;

    using System.Data;

    using System.Runtime.Serialization;

    using System.Collections;

     

    namespace PCAS.M2.Common.Data

    {

          /// <summary>

          ///     A custom serializable dataset containing data information

          /// </summary>

          ///

          [System.ComponentModel.DesignerCategory("Code")]

          [SerializableAttribute]

          public class MedicationData : DataSet

          {

                //

                //Constants

                //

                public const string TABLE                             = "Medication";

     

                public const string MEDICATIONID_FIELD      = "MedicationId";

            public const string DRUGCODE_FIELD          = "DrugCode";

            public const string DRUGCODETYPE_FIELD      = "DrugCodeType";

            public const string NAME_FIELD              = "Name";

            public const string COMPANYID_FIELD         = "CompanyId";

            public const string COMPANYNAME_FIELD       = "CompanyName";

            public const string DOSAGE_FIELD            = "Dosage";

            public const string UNITID_FIELD            = "UnitId";

            public const string UNITCOST_FIELD          = "UnitCost";

            public const string ISGENERIC_FIELD         = "IsGeneric";

            public const string LONGNAME_FIELD          = "LongName";

            public const string CLINICALFORMULATIONID_FIELD          = "ClinicalFormulationID";

            public const string CLINICALFORMULATIONNAME_FIELD = "ClinicalFormulationName";

            public const string REGULATORYCODE_FIELD    = "RegulatoryCode";

            public const string REFERENCEIMAGE_FIELD    = "ReferenceImage";

            public const string MEDICATION_ENVIRONMENTID_FIELD = "MedicationEnvironmentID";

     

            public const string THERAPEUTICCLASSID_FIELD = "TherapeuticClassID";

     

     

     

                /// <summary>

                ///     Constructor to support serialization.

                ///     <remarks>Constructor that supports serialization.</remarks>

                ///     <param name="info">The SerializationInfo object to read from.</param>

                ///     <param name="context">Information on who is calling this method.</param>

                /// </summary>

                public MedicationData(SerializationInfo info, StreamingContext context) : base(info, context)

                {          

                }          

           

                /// <summary>

                ///     Constructor. 

                /// </summary>

                public MedicationData()

    <span style="font-family: "Courier New"; font-size: 10pt; mso-bidi-language: AR-SA%

    Monday, February 1, 2010 2:13 AM

All replies

  • Aside: Usually it's not a good practice to use DataSets with WebServices (/WebMethods). WebService should be a generic interface. With DataSets you will hard code your clients to be Microsoft clients... e.g. Java clients (AXIS2) will have serious problems with DataSets.

     

    Monday, July 12, 2010 10:33 AM