Sharad Gupta

Sharad Gupta

  • 121
  • 19.7k
  • 7.9m

Calling Web Service Method in c#

Aug 11 2015 12:56 AM
Hi 
 
I am calling a web service method  void type
 
[WebMethod(enableSession: true)]
public void BRANCHES(String desc)
{
DataTableToJSON(ds.Tables[0]);
return; 
 
public void DataTableToJSON(DataTable table)
{
List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
foreach (DataRow row in table.Rows)
{
Dictionary<string, object> dict = new Dictionary<string, object>();
foreach (DataColumn col in table.Columns)
{
dict[col.ColumnName] = row[col];
}
list.Add(dict);
}
System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
String abcd = serializer.Serialize(list).Replace("[", "").Replace("]", "");
HttpContext.Current.Response.BinaryWrite(encoding.GetBytes(abcd));
 
}
but  when i calling this we service method in my page it gives a error "Response is not well-formed XML"
 
how can i solve it .
 
 
basically this method firstly  serializer  
 
"System.Web.Script.Serialization.JavaScriptSerializer serializer"  in format.
 
 
 

Answers (11)