Solved

pushing a json object to a restful service call in wcf

Posted on 2013-01-25
6
460 Views
Last Modified: 2013-01-25
I have the following json data object


[
    {
        "dob": "3/24/2012 12:00:00 AM",
        "first_name": "FirstName-8604     ",
        "id": 69,
        "last_name": "LastName-8604     ",
        "mrn": "0",
        "pat_seqno": 2121,
        "site_id": 12
    },
    {
        "dob": "1/6/2012 12:00:00 AM",
        "first_name": "FirstName-4     ",
        "id": 70,
        "last_name": "LastName-4     ",
        "mrn": "0",
        "pat_seqno": 2121,
        "site_id": 12
    },
    {
        "dob": "9/8/2012 12:00:00 AM",
        "first_name": "FirstName-840     ",
        "id": 71,
        "last_name": "LastName-840     ",
        "mrn": "0",
        "pat_seqno": 2123,
        "site_id": 12
    }]

Open in new window


And I to push it a wcf service that I am working and push it to a database table of some sort, this is how I have the method set up in the Ifile

[OperationContract]
        [WebInvoke(Method = "POST", BodyStyle=WebMessageBodyStyle.WrappedRequest, RequestFormat=WebMessageFormat.Json, ResponseFormat=WebMessageFormat.Json, UriTemplate="PutPatientData")]
        string SavePatientData(PatientRecords[] patrecs);

Open in new window


And right now I have some placeholder colder to make sure that the method is working for me.
        public string SavePatientData(PatientRecords[] patrecs)
        {
            string strReturn = "saved";

            return strReturn;
        }

Open in new window


how do I call this method with the above json object, so that I see it in the backend code and store it in the database.
0
Comment
Question by:JDEE8297
  • 3
  • 2
6 Comments
 
LVL 14

Expert Comment

by:binaryevo
ID: 38819356
Your going to have to up your points if anyone is going to respond... :=)  Just friendly advice...
0
 

Author Comment

by:JDEE8297
ID: 38819541
did that peek your interest @binaryevo :)
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 400 total points
ID: 38819618
Use :

var patient_records = [
    {
        "dob": "3/24/2012 12:00:00 AM",
        "first_name": "FirstName-8604     ",
        "id": 69,
        "last_name": "LastName-8604     ",
        "mrn": "0",
        "pat_seqno": 2121,
        "site_id": 12
    },
    {
        "dob": "1/6/2012 12:00:00 AM",
        "first_name": "FirstName-4     ",
        "id": 70,
        "last_name": "LastName-4     ",
        "mrn": "0",
        "pat_seqno": 2121,
        "site_id": 12
    },
    {
        "dob": "9/8/2012 12:00:00 AM",
        "first_name": "FirstName-840     ",
        "id": 71,
        "last_name": "LastName-840     ",
        "mrn": "0",
        "pat_seqno": 2123,
        "site_id": 12
    }];

        $.ajax({
            type: "POST",
            url: "yourpage.asmx/SavePatientData",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            data: JSON.stringify({ patrecs: patient_records }),
            success: function (msg) {
                alert("success : " + msg.d);
            },
            error: function (msg) {
                alert("failed :  " + msg.d);

            }
        });

Open in new window

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:JDEE8297
ID: 38819688
that worked for me, although I should have called this out in my original request, where I am  using a google chrome plugin Advanced Rest Client to do my testing on this and that is where I am having issues.
0
 
LVL 82

Expert Comment

by:leakim971
ID: 38819710
ok, so why don't we see that on your original question?
0
 

Author Comment

by:JDEE8297
ID: 38819774
As I forgot to call it out, my bad. Your solution worked for me and I will give you the points, but was just wondering if you had any idea on how I could use the plugin for chrome to do the testing with.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question