s ASP.NET WEB SERVICES in Visual Basic .NET

Creating Denso QR Bar Code in Visual Basic .NET s ASP.NET WEB SERVICES

CHAPTER 5 s ASP.NET WEB SERVICES
Draw Quick Response Code In VB.NET
Using Barcode creator for VS .NET Control to generate, create QR image in Visual Studio .NET applications.
www.OnBarcode.com
Scan QR-Code In VB.NET
Using Barcode reader for .NET Control to read, scan read, scan image in VS .NET applications.
www.OnBarcode.com
parameter called ZIP in the SQL statement. Later, when you write your code for the query, you ll see how to use this parameter. Your SQL can be viewed and tested at the bottom of the screen. You re now ready to hook this query up to your code and use it to expose the data from the database through the web service. Click OK on the Query Builder and click Finish to exit the wizard. You now have a typed DataSet in your project, tied to the Person.Address table, that can be seen in the Designer (see Figure 5-10).
QR Maker In VB.NET
Using Barcode printer for .NET framework Control to generate, create QR Code JIS X 0510 image in .NET applications.
www.OnBarcode.com
Drawing Barcode In VB.NET
Using Barcode encoder for .NET framework Control to generate, create Barcode image in .NET framework applications.
www.OnBarcode.com
Figure 5-10. Viewing the DataSet in the Designer
Make PDF417 In Visual Basic .NET
Using Barcode encoder for Visual Studio .NET Control to generate, create PDF-417 2d barcode image in VS .NET applications.
www.OnBarcode.com
Make 2D Barcode In Visual Basic .NET
Using Barcode creator for .NET framework Control to generate, create Matrix Barcode image in .NET framework applications.
www.OnBarcode.com
The Designer shows you the fields that are available once you run the query, as well as the methods (Fill and GetData) that are available to the programmer to write to and read from the database, respectively.
Encoding Code39 In VB.NET
Using Barcode maker for .NET framework Control to generate, create Code39 image in .NET applications.
www.OnBarcode.com
Make Code11 In VB.NET
Using Barcode encoder for .NET framework Control to generate, create USD - 8 image in Visual Studio .NET applications.
www.OnBarcode.com
Using the DataSet in a Web Method
Reading QR Code In None
Using Barcode scanner for Software Control to read, scan read, scan image in Software applications.
www.OnBarcode.com
Generating QR Code ISO/IEC18004 In Visual Basic .NET
Using Barcode maker for .NET framework Control to generate, create QR Code image in VS .NET applications.
www.OnBarcode.com
To retrieve the data in a strongly typed DataSet, you use the corresponding data adapter. So, by creating a strongly typed DataSet, such as AddressData, you ll have a reference to the AddressDataTableAdapters collection. From this collection, you create an instance of an AddressTableAdapter, like this:
Creating Data Matrix ECC200 In Objective-C
Using Barcode encoder for iPad Control to generate, create Data Matrix image in iPad applications.
www.OnBarcode.com
Generating Barcode In VS .NET
Using Barcode generation for Visual Studio .NET Control to generate, create Barcode image in .NET framework applications.
www.OnBarcode.com
AddressDataTableAdapters.AddressTableAdapter da = new AddressDataTableAdapters.AddressTableAdapter();
Encoding PDF 417 In None
Using Barcode encoder for Online Control to generate, create PDF417 image in Online applications.
www.OnBarcode.com
Recognize Barcode In Visual Studio .NET
Using Barcode recognizer for Visual Studio .NET Control to read, scan read, scan image in Visual Studio .NET applications.
www.OnBarcode.com
This table adapter implements the Fill and GetData methods that enable you to write and read data from the table, respectively. Because we specified a parameter (@ZIP), the postal code value is passed as a parameter to the GetData method named strZIP.
QR Recognizer In Java
Using Barcode scanner for Java Control to read, scan read, scan image in Java applications.
www.OnBarcode.com
Make Barcode In Java
Using Barcode printer for Android Control to generate, create Barcode image in Android applications.
www.OnBarcode.com
CHAPTER 5 s ASP.NET WEB SERVICES
Decode QR Code ISO/IEC18004 In C#
Using Barcode recognizer for .NET framework Control to read, scan read, scan image in VS .NET applications.
www.OnBarcode.com
Print PDF 417 In None
Using Barcode creator for Font Control to generate, create PDF417 image in Font applications.
www.OnBarcode.com
This returns an AddressDataTable object, so you can instantiate a new object like this:
UPC A Encoder In Java
Using Barcode creator for Java Control to generate, create UPC-A image in Java applications.
www.OnBarcode.com
Code 3 Of 9 Generator In VS .NET
Using Barcode printer for ASP.NET Control to generate, create Code 39 Full ASCII image in ASP.NET applications.
www.OnBarcode.com
AddressData.AddressDataTable dt = da.GetData(strZIP);
You now have a data table containing the returned results from your query. However, you may not want to return this from your web method, because you may have clients written on J2EE, PHP, or other web technologies that will not be able to parse the AddressDataTable object (it is bound to ADO.NET and therefore .NET). A better approach is to use well-formed XML to return your data. In this case, you are returning addresses to the client, so you can set up a class to store a specific address, and another to contain a list of addresses. Here s the code:
public class Address { public string AddressLine1 = String.Empty; public string City = String.Empty; public string PostalCode = String.Empty; public int AddressID = -1; } public class Addresses : List<Address> { }
Now your web method can build this list of addresses with the data that was returned from the database query. You can see the code that implements this here:
[WebMethod] public Addresses GetAddress(string strZIP) { AddressDataSetTableAdapters.AddressTableAdapter da = new AddressDataSetTableAdapters.AddressTableAdapter(); AddressDataSet.AddressDataTable dt = da.GetData(strZIP); Addresses addrs = new Addresses(); foreach (AddressDataSet.AddressRow row in dt.Rows) { // Create a new Address object Address addr = new Address(); // Assign the new address information addr.AddressID = row.AddressID; addr.AddressLine1 = row.AddressLine1;
CHAPTER 5 s ASP.NET WEB SERVICES
addr.City = row.City; addr.PostalCode = row.PostalCode; // Add to the list addrs.Add(addr); } // foreach return addrs; }
This cycles through each row in the data table and creates an instance of the Address class with the data from that row. It then adds this instance to the list of addresses. Once the loop is complete (i.e., when you ve iterated through each row), the list is returned to the caller. Figure 5-11 shows the results of running this web method in its test page.
Figure 5-11. Running the GetAddresses web method in the test page
CHAPTER 5 s ASP.NET WEB SERVICES
You can type a postal code into the field on this form and click Invoke. You ll get the results of the query, formatted as XML, returned to you (see Figure 5-12). Web service clients can now consume this XML and render it as they please.
Figure 5-12. The XML returned from the web service
Creating a Web Service Client
Visual Studio offers you a convenient way to create clients for web services via a facility called web references. When adding a web reference, you point the IDE s Add Web Reference dialog box at the WSDL document for the web service, and Visual Studio will create a proxy class that talks to the service on your behalf (you saw this process in 2).
Copyright © OnBarcode.com . All rights reserved.