Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Web Services I: Returning Data in XML Format. 2 Service-Oriented Architecture (SOA) Old Model for Applications Executables running on individual computers.

Similar presentations


Presentation on theme: "1 Web Services I: Returning Data in XML Format. 2 Service-Oriented Architecture (SOA) Old Model for Applications Executables running on individual computers."— Presentation transcript:

1 1 Web Services I: Returning Data in XML Format

2 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 3 RIA Architecture

4 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 5 I. Creating a "Hello World" Web Service with VS 2010 1. Within a Visual Studio 2010 Website 2. 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 3. Browse.asxm file to test the Web Service

6 6 "Hello World" part 2 Here is the code in the WebService.asmx file This is the file that is browsed, It is essentially just a front-end to the.cs file behind it.

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

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

9 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 class WebService : System.Web.Services.WebService { public WS_MusicCategories () { public WS_MusicCategories () { //Uncomment the following line if using designed components //Uncomment the following line if using designed components //InitializeComponent(); //InitializeComponent(); } [WebMethod] [WebMethod] public List GetCategories() { public List GetCategories() { DA_MusicCategories categoriesObject = new DA_MusicCategories(); return categoriesObject.GetCategories()"; }} [ 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 class WebService : System.Web.Services.WebService { public WS_MusicCategories () { public WS_MusicCategories () { //Uncomment the following line if using designed components //Uncomment the following line if using designed components //InitializeComponent(); //InitializeComponent(); } [WebMethod] [WebMethod] public List GetCategories() { public List GetCategories() { DA_MusicCategories categoriesObject = new DA_MusicCategories(); return categoriesObject.GetCategories()"; }}

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


Download ppt "1 Web Services I: Returning Data in XML Format. 2 Service-Oriented Architecture (SOA) Old Model for Applications Executables running on individual computers."

Similar presentations


Ads by Google