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);
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;
}
return "12345";
}
jqury ......
$(document).ready(function () {
var wcfServiceUrl = "http://localhost:13561/Service.svc/";
alert(wcfServiceUrl);
$.ajax({
cache: false,
url: wcfServiceUrl + "PostCustomDataJSONP",
data: "{'Fields': {'FirstName':'" + 'shabber' + "'," + "'LastName':'" + 'raza' + "'}}",
jsonpCallback: "entity",
contentType: "application/javascript",
dataType: "jsonp",
error: function () {
alert("list failed!");
},
success: function (list) {
alert('hi1');
});
}
});