Solved

pushing a json object to a restful service call in wcf

Posted on 2013-01-25
6
453 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
Comment Utility
Your going to have to up your points if anyone is going to respond... :=)  Just friendly advice...
0
 

Author Comment

by:JDEE8297
Comment Utility
did that peek your interest @binaryevo :)
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 400 total points
Comment Utility
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:JDEE8297
Comment Utility
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
Comment Utility
ok, so why don't we see that on your original question?
0
 

Author Comment

by:JDEE8297
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

763 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now