Passing an array of data from Json to the wcf function as an argument

Hello everyone. I am using json to transfer data in a wcf service. Below is my code. I can pass ProjectCollection data

But I want to transfer data as an array like this

var ProjectCollection = ['new', 'test', 'etc'];

var ProjectCollection = "Test"; function GetEmployee() { Type = "GET"; Url = "http://localhost:52136/Service1.svc/GetTimesheetEntries"; DataType = "jsonp"; Data = {vb: ProjectCollection,vb1: '1'}; ProcessData = false; method = "GetTimesheetEntries"; CallService(); } function CallService() { $.ajax({ type: Type, //GET or POST or PUT or DELETE verb url: Url, // Location of the service data: Data, //Data sent to server contentType: ContentType, // content type sent to server dataType: DataType, //Expected data format from server processdata: ProcessData, //True or False success: function (msg) {//On Successfull service call ServiceSucceeded(msg); }, error: ServiceFailed// When Service call fails }); } 

This is my webservice function. So my requirement is to get all array data from json to this function argument.

  public List<WcfService1.Customer> GetTimesheetEntries(string[] vb , string vb1) { DataClasses1DataContext i = new DataClasses1DataContext(); //var b = from vb in i.TimeSheetMasters select vb; //return b.ToList(); var list = from time in i.TimeSheetMasters join activity in i.ProjectMasters on time.ProjectId equals activity.ProjectId join res in i.ResourceMasters on time.ResourceId equals res.ResourceId where time.TaskDetails == vb && time.BookHours == vb1 select new WcfService1.Customer { RName = res.ResourceName, PName = activity.ProjectTitle }; return list.ToList(); } 
+4
source share
1 answer

I found my solution

  function GetTimeSheet() { //webserviceurl[2] Type = "GET"; Url = "http://gtsp12:3030/Service1.svc/GetTimesheetEntries"; DataType = "jsonp"; Data = { Projects: JSON.stringify(projectlist), Resources: JSON.stringify(Resourcelist) }; method = "GetTimesheetEntries"; CallService1(); } 

Just create an array in a script. Initialize it and pass it as an argument to the webservice, as shown above.

+4
source

Source: https://habr.com/ru/post/1384265/


All Articles