gpt4 book ai didi

jquery - 将数据数组从 Json 传递给 wcf 函数作为参数

转载 作者:行者123 更新时间:2023-12-01 00:15:55 24 4
gpt4 key购买 nike

大家好,我正在使用 json 在 wcf 服务中传递数据。下面是我的代码。我能够传递数据ProjectCollection

但我想像这样将数据作为数组传递

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
});
}

这是我的网络服务功能。所以我的要求是将所有数组数据从 json 获取到这个函数参数。

 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();


}

最佳答案

我找到了解决方案

  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();
}

只需在脚本中创建数组即可。像上面一样初始化它并作为 webservice 中的参数传递。

关于jquery - 将数据数组从 Json 传递给 wcf 函数作为参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8353130/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com