Click here to Skip to main content
15,179,830 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C#
[ServiceContract]
    public interface IService1
    {
       [OperationContract]
        FinalResult TotalMarks(List<result> lstQuestionsAndAnswers);

    }
public class FinalResult
   {
       [DataMember]
       public int Result { get; set; }
       [DataMember]

       public string MsgError { get; set; }
   }

 public FinalResult TotalMarks(List<result> lstQuestionsAndAnswers)
        {
            
            FinalResult objFinal = new FinalResult();
            
            try
            {
                
            
            }
            catch (Exception ex)
            {
             
            }
            finally { }
            return objFinal;
        }
    }

    public class Result
    {
        public string QuestionNo { get; set; }
        public string Answer { get; set; }
    }

//Client Side
  private void Form1_Load(object sender, EventArgs e)
        {
            ServiceReference1.Service1Client objService = new ServiceReference1.Service1Client();
            ServiceReference1.Result objResult = new ServiceReference1.Result();
        
            ServiceReference1.Result lst = new ServiceReference1.Result { };
            lst.QuestionNo = "Q1";
            lst.Answer = "B";

            objResult = null;
            objService.ChannelFactory.CreateChannel();
            //ServiceReference1.FinalResult=new ServiceReference1.FinalResult{}
            //objService.TotalMarks();
            
            //string Result = objService.TotalMarks();        
        }
Posted
v4
Comments
   
What is the problem with the current code ?
What problem are you facing ?
kedar001 9-Apr-13 12:43pm
   
objService.TotalMarks(list<result> lstQuestionsAndAnswers);

cannot able to pass list to the Method objService.TotalMarks()
   
What is the exception or error are you getting ?
kedar001 10-Apr-13 12:02pm
   
Argument 1: cannot convert from 'WindowsFormsApplication1.ServiceReference1.Result' to 'WindowsFormsApplication1.ServiceReference1.Result[]'
kedar001 10-Apr-13 12:07pm
   
Updated Code :

ServiceReference1.Service1Client objService = new ServiceReference1.Service1Client();
ServiceReference1.Result objResult = new ServiceReference1.Result();
objResult.QuestionNo = "Q1";
objResult.Answer = "B";
List<servicereference1.result> lst = new List<servicereference1.result>();
lst.Add(objResult);
objResult = null;
objService.ChannelFactory.CreateChannel();
string Result = objService.TotalMarks(lst);
   
Passing list to service is not a good practice. You can consider sending an array instead and convert that to an list if you want, later in the service function.

However, you can try configuring the service reference to allow generic List to pass.
Right click on service reference. There is one collection type dropdown. Select System.Collections.Generic.List from that dropdown and try once. I have not tried this, so I am not sure.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900