passing Data array from Json to wcf function as argument

Hi all i am using json to pass data in wcf service. Below is my code. I am able to pass data ProjectCollection

But i want to pass 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();


    }

Answers


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 array in your script. Initialize it and pass as an argument in webservice like above.


Need Your Help

Inline style won't overwrite

html css wordpress overflow inline

Pretty new to this coding stuff so forgive the ignorance :)

Nothing's in $_POST. Is there something wrong with my code?

php javascript jquery json

I am fairly new to JavaScript and PHP, and it's the first time to encounter and use JSON. I think my AJAX request is fine, but even so, the $_POST array is empty.