Posts

Showing posts with the label WebService

Cannot Serialize The Data Table - Web Service

System.InvalidOperationException: There was an error generating the XML document. --->  System.InvalidOperationException: Cannot serialize the DataTable. DataTable name is not set. The error will occur when you create a method in web service (.asmx file) with return type " DataTable ". For Example like below:     [WebMethod]     public DataTable test1()     {         DataTable testTable = new DataTable();         return testTable;     } The Example above will lead to the Error " Cannot Serialize The Data Table " This error because the method in WebService tries to return the result of DataTable to the client, but the DataTable does not have their own name. So the quick solution for this error has put the name for DataTable like example : The Solutions      [WebMethod]      public DataTable test1()     {           DataTable testTable = new DataTable(" Table1 ");           return testTable;      } With this simple solution will solved the issue mentioned

How to add items list in dropdown list using jquery - Cascading drop down

If you want to create 2 dropdown lists in which the second dropdown value will depend on the selected value from the first dropdown, you need to Implement JSON + Webservice+ JQuery. In my solution, I will use Jquery Ajax to request data from web service and add value to the second dropdown. Scenario Let say the first dropdown will list all Country, and the second dropdown will list all state from the selected country. Solution Create JSON Webservice, you can refer to this link Create custom JQuery function to handle onChange event on dropdown list country. Use return value from web services to the second dropdown items list. Full Code Example Note: The web service will use from the post here <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head>     <title></title>     <script type="text/javascript&quo

How to create JSON webservice in ASP.NET

This example will show how to create Webservice using asp.net and the result will return in format JSON ( JavaScript Object Notation ). Below is the step by step to create webservice: Open Visual studio. Create New Project Add New File in the solution and choose Web Service file( .asmx) Copy paste code below to create your own JSON webservice The Web Service Code /// <summary>     /// Summary description for KenticoJSONTest     /// </summary>     [WebService(Namespace = "http://tempuri.org/")]     [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]     [System.ComponentModel.ToolboxItem(false)]     // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.     [System.Web.Script.Services.ScriptService]     public class AjaxWebService : System.Web.Services.WebService     {         [WebMethod]         public string HelloWorld()         {             return "Hello World";         }         [WebMethod]