Reputation: 10422
I have a method like this in wcf service
public string PostAllSurveList(List<Survey> surveyList)
{
var surveyDbList = ConstructDbServeyList(surveyList);
foreach (var survey in surveyDbList)
{
_db.surveys.Add(survey);
}
_db.SaveChanges();
return "Successfully Saved";
}
Now my question is How can I call this method from the client code. That means firstly I have to construct the Survey List. How can I construct this list.
string reply = client.PostAllSurveList(How can I construct this List?);
For your kind information, I am writing client code in C#.
Thanks in Advance.
Upvotes: 2
Views: 207
Reputation: 5987
Creare List like this and supply :
var list = new List<Survey>();
string reply = client.PostAllSurveList(list);
Edit : Update Service Reference To ObservableCollection
Upvotes: 1
Reputation: 77285
var list = new List<Survey>();
string reply = client.PostAllSurveList(list);
And you really need to make sure you know how to spell Survey, because you have 3 different spellings in 6 lines of code. Code is written language, it doesn't work if it's somewhat similar if spoken aloud.
Edit: Make sure that when you generate the client, you chose "List" as the option for any collections. It seems you chose array, which means your function now takes an array on the client side:
var list = new List<Survey>();
string reply = client.PostAllSurveList(list.ToArray());
Upvotes: 3
Reputation: 11063
Create survery items and add them to a list, pass the list as parameter:
Survey survey1 = new Survey();
survey1.property1= value;
survey1.property2= value;
Survey survey2 = new Survey();
survey2.property1= value;
survey2.property2= value;
List<Survey> listSurvey = new List<Survey>();
listSurvey.add(survey1);
listSurvey.add(survey2);
string reply = client.PostAllSurveList(listSurvey);
Upvotes: 1
Reputation: 70718
Try:
var list = new List<Survey>();
string reply = client.PostAllSurveList(list);
Or using an Collection Initializer
:
string reply = client.PostAllSurveList(new List<Survey> { });
Although list
should be populated elsewhere in your business logic, unless ConstructDbServeyList
manipulates the variable in the method directly.
You can add to the list using the .Add()
method. For instance:
list.Add(new Survey() { Property = "Property"; });
Upvotes: 0