Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

pushing a json object to a restful service call in wcf

Posted on 2013-01-25
6
456 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Json Schema 8 32
VB.NET Textbox input validation 4 37
message Alert on an empty search 10 16
JS Event Does not Trigger From File 2 23
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 …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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…

790 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