locked
Consume web service and get data --MessageValue[] RRS feed

  • Question

  • User-236691393 posted

    Hello friends,

    I am new to wcf & web services. I am consuming a web service through web application. I have 5 fields ( 4 are regular string values) 5th is array of keyvaluepairs.

    I am trying to get all 5 fields info into Datatable.

                DataTable dt = new DataTable();     
               
    
                foreach (var item in arr)
                {
                    MessageData msg = new MessageData();
                    msg.CustAcctKey = item.CustAcctKey;
                    msg.CustKey = item.CustKey;
                    msg.MessageSubType = item.MessageSubType;
                    msg.MessageType = item.MessageType;
                    msg.MessageElementArray = new Dictionary<string, string>();
                    foreach (myService.MessageValue message in item.MessageElementArray)
                    {
                        msg.MessageElementArray.Add(message.key, message.value);
                    }
                   // msg.MessageElementArray = item.MessageElementArray;
                   dt.Rows.Add(msg);
    
                  
                }
    I get ArgumentUnhandled exception. 

     

     


     

                   

     

     

    Tuesday, November 26, 2013 7:27 PM

Answers

  • User-1623675128 posted

    you have to define columns in the data table first then add the obj into it.

    like

     sample obj = new sample();
                DataTable dt = new DataTable();
                DataColumn dc = new DataColumn("Name");
                dt.Columns.Add(dc);
                obj.name = "Ram";
                dt.Rows.Add(obj);

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, November 27, 2013 10:01 AM

All replies

  • User-1623675128 posted

    you have to define columns in the data table first then add the obj into it.

    like

     sample obj = new sample();
                DataTable dt = new DataTable();
                DataColumn dc = new DataColumn("Name");
                dt.Columns.Add(dc);
                obj.name = "Ram";
                dt.Rows.Add(obj);

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, November 27, 2013 10:01 AM
  • User-488622176 posted

    On what line do you get the error?

    Thursday, November 28, 2013 6:07 AM