Download
web services ii returning data in json format n.
Skip this Video
Loading SlideShow in 5 Seconds..
Web Services II: Returning Data in JSON Format PowerPoint Presentation
Download Presentation
Web Services II: Returning Data in JSON Format

Web Services II: Returning Data in JSON Format

129 Vues Download Presentation
Télécharger la présentation

Web Services II: Returning Data in JSON Format

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Web Services II: Returning Data in JSON Format

  2. JSON vs XML • JSON is a data format that is easier for client-side programmers to work with • It takes just one small change to an existing Web Service method to have it data in JSON format rather than their default XML format

  3. WS_MusicCategories: JSON version [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] // To allow this Web Service to be called from script, using ASP.NET //AJAX, uncomment the following line. // [System.Web.Script.Services.ScriptService] public classWebService : System.Web.Services.WebService { publicWS_MusicCategories () { //Uncomment the following line if using designed components //InitializeComponent(); } [WebMethod][ScriptMethod(ResponseFormat = ResponseFormat.Json)] public List<TO_MusicCategory>GetCategories() { DA_MusicCategoriescategoriesObject = new DA_MusicCategories(); returncategoriesObject.GetCategories()"; } }

  4. To have a Web Service Method return JSON data instead of XML: • Add the following line of code: [ScriptMethod(ResponseFormat = ResponseFormat.Json)] This line must be added immediately before the web method declaration (see example code on last slide.