C# - How to send and read Post array of JSON data to WCF RESTful Service
<p>My concerns:</p>

<ol>
<li><p>Is my below code correct? for the input being sent.</p></li>
<li><p>I am try to debug locally with SOAPUI and POST MAN , my function is being hit but the input is null - So I want to know - how to send a http post request with JSON data?</p></li>
</ol>

<p>URL I am trying:
<a href="http://localhost:49240/TranslationService.svc/DVRDatalist" rel="nofollow">http://localhost:49240/TranslationService.svc/DVRDatalist</a></p>

<p>Type: JSON(application/json)
Raw data: </p>

<pre><code>{"DVRMigration":"[{“ProgramID”:”1111”,”ServiceID”:”1111”,”ChannelNo”:”11”,”TimeSlot”:”1111”},{“ProgramID”:”2222”,”ServiceID”:”2222”,”ChannelNo”:”22”,”TimeSlot”:”2222”},{“ProgramID”:”3333”,”ServiceID”:”3333”,”ChannelNo”:”33”,”TimeSlot”:”3333”},{“ProgramID”:”4444”,”ServiceID”:”4444”,”ChannelNo”:”44”,”TimeSlot”:”4444”}]"}
</code></pre>

<ol start="3">
<li><p>I need sample code for the below input where that input is saved, and split so that I can perform my DB operations, for ex on:</p>

<p><code>{“ProgramID”:”1111”,”ServiceID”:”1111”,”ChannelNo”:”11”,”TimeSlot”:”1111”}</code></p>

<p>and form a final list and return the response in json</p></li>
</ol>

<p>====================</p>

<p>Below is the Sample input that will be sent to the Web Service:</p>

<p>[INPUT] => JSON Data</p>

<pre><code>{“DVR Migration”:[{“ProgramID”:”1111”,”ServiceID”:”1111”,”ChannelNo”:”11”,”TimeSlot”:”1111”},{“ProgramID”:”2222”,”ServiceID”:”2222”,”ChannelNo”:”22”,”TimeSlot”:”2222”},{“ProgramID”:”3333”,”ServiceID”:”3333”,”ChannelNo”:”33”,”TimeSlot”:”3333”},{“ProgramID”:”4444”,”ServiceID”:”4444”,”ChannelNo”:”44”,”TimeSlot”:”4444”}]}
</code></pre>

<p>Below is the sample output I should receive back from Web Service:</p>

<p>[OUTPUT] => JSON Data</p>

<pre><code>{"DVR Migration”:[{"ChannelNo”:"11","GuideStart":"00","ProgramID”:"1111","PvrID":"111","SeriesID":"1001","ServiceID":"1234","TableID":"11","Title":"ABCD","UpdateFlag":"False”},{"ChannelNo”:"22","GuideStart":"00","ProgramID”:"2222","PvrID":"111","SeriesID":"1001","ServiceID":"1234","TableID":"11","Title":"ABCD","UpdateFlag":"False”},{"ChannelNo”:"33","GuideStart":"00","ProgramID”:"3333","PvrID":"111","SeriesID":"1001","ServiceID":"1234","TableID":"11","Title":"ABCD","UpdateFlag":"False”},{"ChannelNo”:"44","GuideStart":"00","ProgramID”:"4444","PvrID":"111","SeriesID":"1001","ServiceID":"1234","TableID":"11","Title":"ABCD","UpdateFlag":"False”}]}
</code></pre>

<p>File name: ITranslationService.cs</p>

<pre><code>[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "DVRDatalist", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
[return: MessageParameter(Name = "DVR Data List Migration")]
List&lt;DataList&gt; DVRDatalist(Migration migration);
</code></pre>

<p>File name: TranslationService.cs</p>

<pre><code>public List&lt;DataList&gt; DVRDatalist(Migration migration)
{
    List&lt;DataList&gt; response = new List&lt;DataList&gt;();
    var list = JsonConvert.DeserializeObject&lt;List&lt;Migration&gt;&gt;(Convert.ToString(migration));
    foreach (var row in list)
    {
        var datalist = new DataList();
        string pgrmId = row.ProgramID;
        string svcid = row.ServiceID;
        string cn = row.ChannelNo;
        string ts = row.TimeSlot;
        string pvrid = row.PvrID;
        string tid = row.TableID;
        DataSet dsdvrdata = dvr.Getdvrdata(pgrmId, svcid, cn, ts, pvrid, tid);
        datalist.ServiceID = dsdvrdata.Tables[0].Rows[0]["ServiceID"].ToString();
        datalist.ProgramID = dsdvrdata.Tables[0].Rows[0]["ProgramID"].ToString();
        datalist.ChannelNo = dsdvrdata.Tables[0].Rows[0]["ChannelNo"].ToString();
        datalist.UpdateFlag = dsdvrdata.Tables[0].Rows[0]["UpdateFlag"].ToString();
        datalist.Title = dsdvrdata.Tables[0].Rows[0]["Title"].ToString();
        datalist.GuideStart = dsdvrdata.Tables[0].Rows[0]["GuideStart"].ToString();
        datalist.SeriesID = dsdvrdata.Tables[0].Rows[0]["SeriesID"].ToString();
        datalist.PvrID = pvrid;
        datalist.TableID = tid;

        response.Add(datalist);
    }
    return response;
}
</code></pre>

<p>Data Members:</p>

<pre><code>public class Migration
{
    //string topstring = string.Empty;
    //List&lt;string&gt;=new List&lt;&gt;;

    public List&lt;DVRMigration&gt; DVRMigration { get; set; }
    public string ChannelNo { get; set; }
    public string ProgramID { get; set; }
    public string PvrID { get; set; }
    public string ServiceID { get; set; }
    public string TableID { get; set; }
    public string TimeSlot { get; set; }
}

public class DVRMigration
{
    public string ServiceID { get; set; }
    public string ProgramID { get; set; }
    public string ChannelNo { get; set; }
    public string TimeSlot { get; set; }
    public string PvrID { get; set; }
    public string TableID { get; set; }
}

public class DataList
{
    #region Properties
    [DataMember(Order = 1)]
    public string ServiceID { get; set; }

    [DataMember(Order = 2)]
    public string ProgramID { get; set; }

    [DataMember(Order = 3)]
    public string ChannelNo { get; set; }

    [DataMember(Order = 4)]
    public string UpdateFlag { get; set; }

    [DataMember(Order = 5)]
    public string Title { get; set; }

    [DataMember(Order = 6)]
    public string GuideStart { get; set; }

    [DataMember(Order = 7)]
    public string SeriesID { get; set; }

    [DataMember(Order = 8)]
    public string PvrID { get; set; }

    [DataMember(Order = 9)]
    public string TableID { get; set; }

    #endregion
}
</code></pre>