开发者

Passing Complex JavaScript Object to WCF using JQuery

I have a FireFox browser plugin that is devloped in C++, that connects to a Scanner and retrievs data

When a user clicks on a button on a Web Page (Developed in ASP.net AJAX 3.5) it retrieves data from the scanner by JavaScript and sends to the WCF service (RESTful WCF and accepts JSON message format)

Question is C++ Object that passed backto the browser using JQuery (when button is clicked) object is complex and does not match remove WCF service (which only accepts a custom objec开发者_JAVA技巧t as input; one parameter only)

Question

Do I need to reconstruct (tore it apart in JQuery and match its structure to remote WCF service and use JSON.Stringfy() with JQuery AJAX in order to pass) object that was passed from C++ browser plugin to the WCF?

Can object be passed between JQuery and remote WCF if both have different properties?


You can't pass the object if it has different properties. You have to transform it (in javascript) to match the format WCF expects. If it's an array or property names must be changed, jquery's $.map could help you.

But, you don't need JSON.stringify, cause jquery's $.ajax encodes objects for you. For example in:

$.ajax({
  url: "url_of_wcf_service",
  data: your_object
});

your object will be automatically encoded. The only case you'd use JSON.stringify is if your WCF explicitly receives a json string (but i don't think it's the case), so you'd do:

$.ajax({
  url: "url_of_wcf_service",
  data: JSON.stringify(your_object)
});

Hope this helps. Cheers

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜