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
[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
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));
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;
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