130 likes | 286 Views
XML Web Services. Alejandro Simon asc0_cate@hotmail.com Course Site: http://asc0.dynup.net/dotnet/ 03/07/03 3:00pm. Client. Web Server Web Service. What are Web Services?. A mean for applications that have network access to consume services provided by a network machine. XML. Network.
E N D
XML Web Services Alejandro Simon asc0_cate@hotmail.com Course Site: http://asc0.dynup.net/dotnet/ 03/07/03 3:00pm
Client Web Server Web Service What are Web Services? • A mean for applications that have network access to consume services provided by a network machine. XML Network
Versatility of Web Services • Web Services can be consumed in all types of .NET applications, from ASP.NET web pages to Windows Applications. • Can be consumed in .NET, JAVA, ??? • Can be originated in .NET, JAVA, ??? • Use XML for communication, hence developing language is secondary.
Web Service Mentality • The Web Service Provider is a black box which provides a simple / complicated service through a very simple to use interface. Example: Kinko’s is releasing a Web Service along with an Office client, that will allow you to print from Office and have the results be physically generated, bound, and delivered through Kinko’s
Creating a Web Service Project • File->New->Project • Select Visual C# Project on the left, ASP.NET Web Service on the right. • Modify the last part of the location of the Web Service, the name will change. • Click Ok • A new solution with the Web Service project will be created for you. • Default name of Web Service is Service1.asmx. (Trivia: asmx stands for Active Server Methods) • In the solution explorer, change it to a name of your liking. (right click->rename)
Customizing your Web Service • Choose “View Code” option either from design view, or right click on the .asmx file • Select the HelloWorld web method and use the Comment/Uncomment Buttons to enable it. • Build Project • Visit Web Service page at http://webserver/projectname/webservice.asmx
Web Output of Web Service Class name: Service1 (modify the class name in asmx file to fix this) List of WebMethods (only HelloWorld) Error about default namespace Tags to add to fix it
Consuming a Web Service • Step 1: Build a proxy class • The proxy class will simulate that the web service is a class that is local to your application. • The proxy class takes care of all the communication and parameter passing issues.
How do you build a proxy class? • WSDL.EXE can automatically generate one for you. Start a Visual Studio.NET Command Prompt from Visual Studio.NET Tools Change directories (cd) to your application directory Execute: wsdl /o:WSDemo1p.cs http://asc0.dynup.net/WSDemo1/WSDemo1.asmx • To get help, just execute wsdl.exe without parameters.
What to do with the proxy class? • In the Solution Explorer, click the Show All Files button • Right click on the proxy class, then select “Include in project” • Now you can click on the proxy class to see and modify the code (only if you want to) • From now on, you can use the proxy class in the application. • If you build at this point, you will get compilation errors in: using System.Web.Services.Protocols;
The importance of Project References • Before the proxy class even compiles, one must add a web reference to the project. • This lets Visual Studio know that we will be using Web Services. • On the project, right click on References, select Add Web Reference. • In the address box, type the web path to the asmx file that contains web service. • Once Add Reference button is available, click it and you are good to go!
Consuming Web Services in Windows Forms. • Same steps as in ASP.NET • Use proxy class previously build or build one. • Add Web Reference (MOST IMPORTANT!)
Contact Information • Alejandro Simon asc0_cate@hotmail.com http://asc0.dynup.net/dotnet/