Click here to Skip to main content
15,867,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i am beginner in JSON using c# website,



now i am doing for insertion, deletion and updation using WCF services for Employee when i am click button

how to give request in Json in WCF to the database and vice versa database to Json format and DB user id value request to display after data save in database.

I am trying this code some where reference anyone help me to get clear simply about JSON Concept,really critical for me as understood

C#
[OperationContract]
  
[WebInvoke(Method="POST",BodyStyle=WebMessageBodyStyle.WrappedRequest,RequestFormat=WebMessageFormat.Json,ResponseFormat=WebMessageFormat.Json,UriTemplate=
       "
{Userid}/{UserName}/{Password}/{FatherName}/{Address1}/{Address2}/{District}/{PermaenantAddress}/{ContactNo}/{EmailAddress}/{CreatedDateTime}")]
   string addemployee(Employeedetails emp);


i test single textbox & Button, my button event code is
C#
protected void Button1_Click(object sender, EventArgs e)
    {
        ServiceReference1.ServiceClient ser = new ServiceReference1.ServiceClient();
        Employeedetails emp = new Employeedetails();
        emp.userid = TextBox1.Text;
        emp.UserName = TextBox1.Text;
        emp.PassWord = TextBox1.Text;
        emp.Fathername = TextBox1.Text;
        emp.address1 = TextBox1.Text;
        emp.address2 = TextBox1.Text;
        emp.district = TextBox1.Text;
        emp.email = TextBox1.Text;
        emp.Permenantaddress = TextBox1.Text;
        emp.contact = TextBox1.Text;
        emp.createddatetime = TextBox1.Text;

        string url = TextBox1.Text;
        WebClient client = new WebClient();
        byte[] data = client.DownloadData(new Uri(url));
        Stream stream = new MemoryStream(data);
        StreamReader reader = new StreamReader(stream);
        DataContractSerializer dcs = new DataContractSerializer(typeof(string));
        DataContractJsonSerializer json = new DataContractJsonSerializer(typeof(ServiceReference1.ServiceClient));
        //string test = reader.ReadLine();


        ServiceReference1.ServiceClient serv=(ServiceReference1.ServiceClient) json.ReadObject(stream);

       string res = string.Format("Serializxe object", serv.addemployee(emp));
        stream.Position = 0;
        res = res + "strreader" + reader.ReadToEnd();
        Label1.Text=res;
        //string result = ser.addemployee(emp);
        //Label1.Text = result;



        ser.Close();

    }
    
}



=======> >( ! ! ! ! ! !HERE I AM GETTING ERROR AS FOLLOWS
(There was an error deserializing the object of type
ServiceReference1.ServiceClient. Encountered unexpected
character '<'.)
how to rectify this error )

Error comes as this code:
ServiceReference1.ServiceClient serv=(ServiceReference1.ServiceClient) json.ReadObject(stream);


rectify ASAP for this operation
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900