Display data from data base using stored procedure in wcf? RRS feed

  • Question

  • I did the wcf Service to display data from database using stored procedure,

    I am getting data also

    I am getting output like this,

    The above output getting schema definition,I don't want that schema definition.

    I want to the below output,

    <?xml version="1.0" encoding="UTF-8"?> <TranscomXML xmlns="ShipperLoadStatus.xsd" created="201405281117" batchref="LS-56273-260449.xml"> <ShipperLoadStatus diffgr:id="ShipperLoadStatus1" msdata:rowOrder="0"> <LoadId>1</LoadId> <TrailerNum>12345</TrailerNum> <DriverName>Sampath</DriverName> <VehicleNumber>A1234</VehicleNumber> </ShipperLoadStatus> </TranscomXML>

    How can i get the above out put

    Getting data from database i am using below code

    [WebGet(ResponseFormat = WebMessageFormat.Xml)]
             DataSet AllLoadstatus();
    Class implementation:
    public DataSet AllLoadstatus()
                SqlConnection con = new SqlConnection(@"Data Source=ASHDEVBTS-1;Initial Catalog=Sampath;Integrated Security=True");
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = con;
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "SelectLoad1";
                //cmd.Parameters.AddWithValue("@LoadId", LoadId);
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataSet ds = new DataSet();
                da.Fill(ds, "ShipperLoadStatus");
                return ds;

    anyone give me solution


    • Edited by anil33 Wednesday, October 1, 2014 8:06 AM
    Wednesday, October 1, 2014 8:06 AM


  • Hi anil33,

    It seesm that you want to reture a List<> in your WCF Service method as following:

    public class ShipperLoadStatus
        public string LoadId { get; set; }
        public string TrailerNum { get; set; }
        public string DriverName { get; set;}
        public string VehicleNumber { get; set;}


    [WebGet(ResponseFormat = WebMessageFormat.Xml)] [OperationContract] List<ShipperLoadStatus> AllLoadstatus();

    Then in order to implement the return of the List<ShipperLoadStatus>, please try to covert the DataSet to a List, for more information, please try to refer to:
    #Conversion Between DataTable and List in C#: .

    Best Regards,
    Amy Peng

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, October 2, 2014 5:54 AM