使用JSONP将Dictioanry对象传递到WCF中 [英] Pass Dictioanry object into WCF using JSONP

查看:82
本文介绍了使用JSONP将Dictioanry对象传递到WCF中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用JSONP(用于跨域)调用WCF函数传递字典对象(键​​,值)作为参数并返回字符串值时遇到问题.

I have problem to call WCF function pass dictionary object (key, value ) as parameter using JSONP(for cross domain) and get back string value.

string PostCustomDataJSONP(Dictionary<string,> Fields);


请帮帮我,我在接口属性和jquery中使用什么代码?

界面...


Please help me, what code i use in interface attribute and in jquery?

interface......

[OperationContract]
       [WebGet(BodyStyle = WebMessageBodyStyle.Bare,
       RequestFormat = WebMessageFormat.Json,
       ResponseFormat = WebMessageFormat.Json,
       UriTemplate = "/PostCustomDataJSONP/")]
       string PostCustomDataJSONP(Dictionary<string,> Fields);



测试功能...



function for testing ...

public string PostCustomDataJSONP(Dictionary<String, Object> Fields)
       {

           foreach (var i in Fields)
           {
               var key = i.Key;
               var val = i.Value;
              // test the data here....


           }

           return "12345";
       }


jqury ......


jqury ......

$(document).ready(function () {
       var wcfServiceUrl = "http://localhost:13561/Service.svc/";
       // sets both dropdown lists empty

       alert(wcfServiceUrl);
       // JSONP CALL TO WCF SERVICE
       $.ajax({
           cache: false,
           url: wcfServiceUrl + "PostCustomDataJSONP",
           // data: "{}",
           data: "{'Fields': {'FirstName':'" + 'shabber' + "'," + "'LastName':'" + 'raza' + "'}}",

           jsonpCallback: "entity",
           contentType: "application/javascript",
           dataType: "jsonp",
           error: function () {
               alert("list failed!");
           },
           success: function (list) {
               alert('hi1');
               //  alert(list);
               });
           }
       });

推荐答案

(文档).ready(功能(){ var wcfServiceUrl = " ; // 将两个下拉列表都设置为空 alert(wcfServiceUrl); // JSONP调用WCF服务
(document).ready(function () { var wcfServiceUrl = "http://localhost:13561/Service.svc/"; // sets both dropdown lists empty alert(wcfServiceUrl); // JSONP CALL TO WCF SERVICE


.ajax({ 缓存: false , 网址:wcfServiceUrl + " // 数据:"{}", 数据:" + 强盗' + '," + 'LastName':'" + raza' + , jsonpCallback:" , contentType:" , dataType:" , 错误:功能(){ alert(" ); }, 成功:功能(列表){ alert(' hi1'); // alert(list); }); } });
.ajax({ cache: false, url: wcfServiceUrl + "PostCustomDataJSONP", // data: "{}", data: "{'Fields': {'FirstName':'" + 'shabber' + "'," + "'LastName':'" + 'raza' + "'}}", jsonpCallback: "entity", contentType: "application/javascript", dataType: "jsonp", error: function () { alert("list failed!"); }, success: function (list) { alert('hi1'); // alert(list); }); } });


这篇关于使用JSONP将Dictioanry对象传递到WCF中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆