locked
WS with XSD RRS feed

  • Question

  • User190138249 posted

    Hi Reader forgive me but I have posted about this before, I've been asked to create a web serrvice. I have been provided with a schema of what the response will consist of. I have a number of questions as I've been investigating and trying to understand some concepts regards web services but im gettting stuck.

    Initially I just created  a struct. of those elements of the schema. The struct was a couple of arrays which as I say represented the layout of the schema / XML that would be returned. I then populated the struct with the returned SQL stored procedure values and returned the struct as my return value of the web service. The people who requested the web service tell me that the web service does not represent the defined schema they provided.

    So Ive scrapped that and done thie following:-

    1.) I have run the schema through XSD.exe, It has created a file of classes. I have added that file to my VS 2005 (ASMX) project.

    2.) I have a SQL stored procedure wihich returns data mirroring the schema classes.

    I think what I need to do now is return the dataset from the function that calls the stored procedure and populate the schema class. Would you agree this is the correct way to create a WS as defined by the requirements of a schema that has been provided to me or am I missing something? I am now losing the will to live because I just keep going round in circles with my lack of knowledge.

    Assuming this is correct. How can I populate the instantied schema class with my databse data and pass back?

    here is my web method:-

        [WebMethod]

    public traceabilityResponse Traceability(string authenticationCode, string vPlusCode)

     

    I then have my class (created from the schema) This is the main part of the class which refers to other classes for the other structure to be returned:-

     

    My schema class has the following:-

     

      

    public partial class traceabilityResponse

        {

           

    private object[] itemsField;

           

    private ItemsChoiceType[] itemsElementNameField;

           

    /// <remarks/>

            [System.Xml.Serialization.

    XmlElementAttribute("lensData", typeof(LensData), Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]

            [System.Xml.Serialization.

    XmlElementAttribute("prescriptionLeft", typeof(Prescription), Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]

            [System.Xml.Serialization.

    XmlElementAttribute("prescriptionRight", typeof(Prescription), Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]

            [System.Xml.Serialization.

    XmlElementAttribute("traceabilityError", typeof(TraceabilityError), Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]

            [System.Xml.Serialization.

    XmlChoiceIdentifierAttribute("ItemsElementName")]

           

    public object[] Items

            {

               

    get

                {

                   

    return this.itemsField;

                }

               

    set

                {

                   

    this.itemsField = value;

                }

            }

           

    /// <remarks/>

            [System.Xml.Serialization.

    XmlElementAttribute("ItemsElementName")]

            [System.Xml.Serialization.

    XmlIgnoreAttribute()]

           

    public ItemsChoiceType[] ItemsElementName

            {

               

    get

                {

                   

    return this.itemsElementNameField;

                }

               

    set

                {

                   

    this.itemsElementNameField = value;

                }

            }

        }

     

    So how would I then instantiate and populate this class with my data and return back through the web service?

     

     

    Please pleasse any help much appreciated.

     

     

    Thursday, September 19, 2013 1:42 PM

All replies