- Home
- Products
- Integration
- Tutorial
- Barcode FAQ
- Purchase
- Company
code 39 c# class XML WEB SERVICE S in C#.NET
CHAPTER 9 XML WEB SERVICE S Painting USS Code 39 In C# Using Barcode printer for .NET framework Control to generate, create Code 39 image in .NET applications. www.OnBarcode.comDecode Code 3/9 In Visual C# Using Barcode decoder for VS .NET Control to read, scan read, scan image in .NET applications. www.OnBarcode.comFigure 9-10. The Add Web Reference dialog box A web reference is nothing but a proxy class that allows you to use classes and methods exposed by a web service in your client application. In this dialog box, enter the complete URL of the Service.asmx file and click the Go button. You will see the same help page as before. In the Web Reference Name text box, key in a name for the web reference or leave it unchanged. Whatever you supply in this text box becomes the namespace name for the proxy class being created. Click the Add Reference button. Your Solution Explorer should now look like Figure 9-11. Creating PDF-417 2d Barcode In Visual C#.NET Using Barcode printer for .NET framework Control to generate, create PDF-417 2d barcode image in .NET framework applications. www.OnBarcode.comUPCA Creation In C#.NET Using Barcode drawer for Visual Studio .NET Control to generate, create UPC Symbol image in VS .NET applications. www.OnBarcode.comFigure 9-11. Web References folder
Creating Barcode In Visual C# Using Barcode drawer for Visual Studio .NET Control to generate, create Barcode image in Visual Studio .NET applications. www.OnBarcode.com1D Printer In C# Using Barcode printer for .NET framework Control to generate, create Linear Barcode image in VS .NET applications. www.OnBarcode.comC H APTE R 9 XM L WEB S ERVI CES
Encode GS1-128 In C#.NET Using Barcode maker for VS .NET Control to generate, create EAN 128 image in .NET applications. www.OnBarcode.comEAN-8 Generator In C#.NET Using Barcode maker for .NET framework Control to generate, create GS1 - 8 image in .NET framework applications. www.OnBarcode.comNote how a new folder called Web References has been added with a subfolder called localhost. The localhost folder further contains a WSDL file. There will also be a file called Reference.cs. This file contains the source code of the web service proxy class. If you change the web service after adding the proxy, you need to update the web reference again. You can do so by right-clicking the web reference and selecting the Update Web Reference option. USS Code 39 Scanner In VB.NET Using Barcode scanner for .NET Control to read, scan read, scan image in .NET applications. www.OnBarcode.comCode 39 Generator In None Using Barcode generation for Microsoft Word Control to generate, create Code 3 of 9 image in Office Word applications. www.OnBarcode.comCreating a Form That Consumes a Web Method
Code-128 Creator In Java Using Barcode generator for Java Control to generate, create Code 128B image in Java applications. www.OnBarcode.comDecode ECC200 In Java Using Barcode decoder for Java Control to read, scan read, scan image in Java applications. www.OnBarcode.comTo demonstrate how to call web methods, you will need to create a form that will display the records from the Employees table. The form should look like Figure 9-12. UPC-A Supplement 2 Generation In Java Using Barcode creator for Android Control to generate, create UPC A image in Android applications. www.OnBarcode.comGS1 - 13 Maker In None Using Barcode creation for Font Control to generate, create EAN13 image in Font applications. www.OnBarcode.comFigure 9-12. Application that calls the GetEmployees() web method The application consists of a DataGridView control that displays all the records from the Employees table of the Northwind database. Import the localhost namespace in your project (recollect that we have specified the web reference name as localhost). In the Load event of the form, write the code shown in Listing 9-15. Listing 9-15. Calling a Web Method private void Form1_Load(object sender, EventArgs e) { Service proxy = new Service(); DataSet ds = proxy.GetEmployees(); dataGridView1.DataSource = ds.Tables["myemployees"].DefaultView; } The code creates an instance of the proxy class. Note that Service is the proxy class, not the web service class itself. We then call the GetEmployees() method of the proxy, which in turn will call the actual GetEmployees() web method of the web service. Remember that the return value of GetEmployees() is a DataSet populated with records from the Employees table. The code then binds the DataSet to the DataGridView. If you run the application, you should see the DataGridView populated with records from the Employees table. Denso QR Bar Code Reader In None Using Barcode scanner for Software Control to read, scan read, scan image in Software applications. www.OnBarcode.comDecoding PDF-417 2d Barcode In C#.NET Using Barcode reader for VS .NET Control to read, scan read, scan image in .NET framework applications. www.OnBarcode.comCHAPTER 9 XML WEB SERVICE S
Code 3 Of 9 Maker In .NET Using Barcode encoder for VS .NET Control to generate, create Code 39 Full ASCII image in Visual Studio .NET applications. www.OnBarcode.comEncode EAN / UCC - 13 In VS .NET Using Barcode maker for ASP.NET Control to generate, create GTIN - 13 image in ASP.NET applications. www.OnBarcode.comStoring Values in a Web Service Session
ECC200 Scanner In .NET Framework Using Barcode recognizer for .NET Control to read, scan read, scan image in VS .NET applications. www.OnBarcode.comPainting PDF-417 2d Barcode In None Using Barcode maker for Online Control to generate, create PDF 417 image in Online applications. www.OnBarcode.comRecollect that earlier we created two web methods PutNameInSession() and GetNameFromSession() that deal with session storage. Let s see how you can call these methods in the client application. To see how this works, you need to create an application like the one shown shown in Figure 9-13. Figure 9-13. Storing session values The application consists of a text box and two buttons. The text box accepts a name that is to be stored in a session variable. The Store Name in Session button calls the PutNameInSession() web method and stores the name in a session variable. The Retrieve Name from Session button calls the GetNameFromSession() web method and displays the returned name in a message box. Listing 9-16 shows the code that is responsible for storing the name in a session variable. Listing 9-16. Storing a Value in a Session Variable CookieContainer cookiecontainer = new CookieContainer(); private void button1_Click(object sender, EventArgs e) { Service proxy = new Service(); proxy.CookieContainer = cookiecontainer; proxy.PutNameInSession(textBox1.Text); } The code creates a form-level variable of type CookieContainer, which resides in the System.Net namespace and acts as storage for cookies. You might be wondering why we need this class. By default the session management of web services depends on a cookie, and the web service needs to identify each and every session with the help of a unique identifier. This identifier is passed to and fro with the help of a cookie. The code then creates an instance of the web service proxy class. It sets its CookieContainer property to the CookieContainer object we just created. The CookieContainer property of the proxy class specifies the storage for the cookies created during the web service communication. Finally, the code calls the PutNameInSession() method of the proxy by passing the name entered in the text box. The Click event handler of the Retrieve Name from Session button contains the code shown in Listing 9-17.
|
|