Click here to Skip to main content
15,891,777 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi

I am calling a web service method void type

[WebMethod(enableSession: true)]
C#
public void BRANCHES(String desc)
{
    DataTableToJSON(ds.Tables[0]);
    return; 
} 
 
public void DataTableToJSON(DataTable table)
{
    List<dictionary><string,>> list = new List<dictionary><string,>>();
    foreach (DataRow row in table.Rows)
    {
        Dictionary<string,> dict = new Dictionary<string,>();
        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.
Posted
Updated 10-Aug-15 19:31pm
v2
Comments
Sinisa Hajnal 11-Aug-15 2:28am    
Put the string into some file and check the output. Maybe the response is not well-formed XML :)

Imagine for example that the output contains CDATA[] element...and you're replacing [] with empty strings...
sgupta89 11-Aug-15 2:33am    
i check the response online it is well formatted but it is not access in my c# code
SundararamanS 11-Aug-15 2:58am    
only way is to examine your string from start to end before writing it in the response!!
Sinisa Hajnal 11-Aug-15 6:03am    
Consider changing the method to return string and then from the calling code insert the string as you need it.
sreeyush sudhakaran 11-Aug-15 6:14am    
suggest you to use Newtonsoft.Json it is good in serialization and de-serialization

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