1 / 10

Web Services I: Returning Data in XML Format

Web Services I: Returning Data in XML Format. Service-Oriented Architecture (SOA). Old Model for Applications Executables running on individual computers Limited or no ability to communicate between applications Very dependent on platform, OS and/or programming language SOA

twila
Download Presentation

Web Services I: Returning Data in XML Format

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Web Services I: Returning Data in XML Format

  2. Service-Oriented Architecture (SOA) • Old Model for Applications • Executables running on individual computers • Limited or no ability to communicate between applications • Very dependent on platform, OS and/or programming language • SOA • Loosely coupled “Services” • Currently – Web Services • Can be called from multiple platforms, OS’s and languages

  3. RIA Architecture

  4. Web Service • A class with methods that can be accessed (via the Internet): • From different platforms (Hardware and OS) • By different programming languages • Information is returned from the Web Service in an XML format or JSON format

  5. I. Creating a "Hello World" Web Service with VS 2010 • Within a Visual Studio 2010 Website • Website, Add New Item, Web Service • This will create a class with all of the unique web service stuff already in it – including a “Hello World” test method. • The web service by default will have two files (just like our web pages): • .asmx file (WebService.asmx) • This is what you point the users of the service at • It contains a link to the .cs file (below) • .cs class file (WebService.cs) • Lives in the App_Code folder • Browse .asxm file to test the Web Service

  6. "Hello World" part 2 • Here is the code in the WebService.asmx file <%@ WebServiceLanguage="C#"CodeBehind="~/App_Code/WebService.cs"Class="WebService" %> This is the file that is browsed, It is essentially just a front-end to the .cs file behind it.

  7. "Hello World" part 3 [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 { public WebService () { //Uncomment the following line if using designed components //InitializeComponent(); } [WebMethod] public stringHelloWorld() { return "Hello World"; } } • Here is the code in the WebService.cs file

  8. I. Providing a Web Service cont: Adding Methods • Adding a method to a Web Service is identical to what you’re used to, except: • [WebMethod] attribute must be immediately before the public keyword in the method declaration [WebMethod]public decimal CalculateYearlyBonus(decimal parYearlySales){ … }

  9. WS_MusicCategories [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] public List<TO_MusicCategory>GetCategories() { DA_MusicCategoriescategoriesObject = new DA_MusicCategories(); returncategoriesObject.GetCategories()"; } }

  10. WS_MusicCategories cont. • From the preceding slide, note the following: • The [ScriptService] line is uncommented • All the GetCategories web service method does is: • Create an instance of your DA_MusicCategories class • Calls the DA class method GetCategories • Returns the result of that call • The Web Service is just a wrapper around your original DA class that allows it to be used as a web service.

More Related