I'm trying to pass JavaScript object to C# WCF service as Dictionary and I don't know how to do it...

我正在尝试将JavaScript对象作为字典传递给C#WCF服务,我不知道该怎么做...

I have a WCF service:

我有一个WCF服务:

[OperationContract]
[WebInvoke]
public List<psy_trance_fm_genre> select(SortedDictionary<string, object> parameters)
{
    ...
}

And I have some JavaScript / JQuery code:

我有一些JavaScript / JQuery代码:

$.ajax({
    contentType: 'application/json; charset=utf-8',
    data: JSON.stringify({ '@genre': '', '@start_row_index': 0, '@maximum_rows': 100 }),
    error: function (jqXHR, textStatus, errorThrown) {
        ...
    },
    success: function (data, textStatus, jqXHR) {
        ...
    },
    type: 'POST',
    url: 'svc/psy_trance_fm_genres.svc/select'
});

Please help me to make them work together! Thanks in advance!

请帮助我让他们一起工作!提前致谢!

2 个解决方案

#1


1

Maybe this will help you or put you in the right direction:

也许这会帮助你或让你朝着正确的方向前进:

An example of an Ajax call I'm using:

我正在使用的Ajax调用示例:

    var data2Send = {
        "CategoryID": CatID, "AccountID": AccID, "RegionID": RegID, "PersonID": PerID, "BudgetID": BudID,
        "AccountDetailTypeID": AdtID
    }
//data2Send could also contain i.e. an array of arrays, list of lists, etc


    $.ajax({
        type: "GET",
        url: '../../Service/myservice.svc/GetAccountDetails',
        dataType: "json",
        data: data2Send,
        contentType: "application/json; charset=utf-8",
        success: function (data) { var accountDetails = JSON.parse(data.d); },
        error: function (jqXHR, textStatus, errorThrown) { alert(errorThrown); }
    });

The WCF contract:

WCF合同:

    [WebInvoke(Method = "GET")]
    [OperationContract]
    string GetAccountDetails(int AccountID = 0, int RegionID = 0, int PersonID = 0, int CategoryID = 0, int BudgetID = 0, string AccountDetailTypeID = "");

Note that the the contract returns a string. I do this using:

请注意,合同返回一个字符串。我这样做使用:

        var accountDetailList = db.AccountDetails
            .Select(ad => new
            {
                AccountDetailTypeID = ad.AccountDetailTypeID,
                Reference = ad.Reference,
                Description = ad.Description,
        AccountDetailID = ad.AccountDetailID,
            })
            .ToList();

return JsonConvert.SerializeObject(accountDetailList);

I hope this helps.

我希望这有帮助。

更多相关文章

  1. day049--jQuery文档操作示例
  2. HTML+jQuery图片上传示例
  3. 经典炫酷的HTML5/jQuery动画应用示例及源码
  4. PHP实现WebSocket示例
  5. PHP基础示例:商品信息管理系统v1.1[转]
  6. 040-PHP使用闭包函数来进行父实例的变量自增,正确示例
  7. mysql锁机制之示例讲解
  8. MySQL 示例数据库sakila
  9. MySQL官网示例数据库emploees分析使用

随机推荐

  1. 为什么这个简单的连接查询使用子查询明显
  2. jdbc与mysql之"can't get hostname four
  3. mysql使用kill无法杀死进程
  4. Qt中使用mysql连接远程服务器
  5. SQL 函数如何设置参数默认值
  6. SQL Server更新一行阻止
  7. mysqd实例服务hang住的检测思路及方案
  8. 第73课内幕资料详细版 Spark SQL Thrift
  9. 使用SQL Server 2008提供的表分区向导
  10. SqlMapClient operation; uncategorized