code 39 c# class Setting a Description for a Web Method in C#.NET

Print ANSI/AIM Code 39 in C#.NET Setting a Description for a Web Method

Setting a Description for a Web Method
Code39 Generation In Visual C#
Using Barcode generation for VS .NET Control to generate, create Code 3/9 image in Visual Studio .NET applications.
www.OnBarcode.com
Recognize USS Code 39 In C#.NET
Using Barcode decoder for Visual Studio .NET Control to read, scan read, scan image in VS .NET applications.
www.OnBarcode.com
You can set a description for a web method by using the Description property of the WebMethod attribute. This description will be displayed on the help page. The code in Listing 9-11 illustrates its use.
Printing PDF 417 In Visual C#.NET
Using Barcode creation for VS .NET Control to generate, create PDF 417 image in Visual Studio .NET applications.
www.OnBarcode.com
Code 128 Code Set C Encoder In C#
Using Barcode drawer for Visual Studio .NET Control to generate, create Code 128B image in .NET applications.
www.OnBarcode.com
CHAPTER 9 XML WEB SERVICE S
Creating Barcode In C#.NET
Using Barcode encoder for VS .NET Control to generate, create Barcode image in Visual Studio .NET applications.
www.OnBarcode.com
Matrix Barcode Encoder In C#.NET
Using Barcode maker for VS .NET Control to generate, create 2D image in VS .NET applications.
www.OnBarcode.com
Listing 9-11. Using the Description Property [WebMethod(Description = "This is description for web method")] public string DescribeMe() { return "Hello World"; }
Generating Data Matrix 2d Barcode In C#
Using Barcode printer for VS .NET Control to generate, create ECC200 image in Visual Studio .NET applications.
www.OnBarcode.com
Print EAN - 14 In Visual C#.NET
Using Barcode printer for .NET Control to generate, create UPC Shipping Container Symbol ITF-14 image in VS .NET applications.
www.OnBarcode.com
Returning a DataSet from a Web Method
USS Code 39 Encoder In Java
Using Barcode generator for Android Control to generate, create USS Code 39 image in Android applications.
www.OnBarcode.com
Recognizing Code 39 In .NET Framework
Using Barcode decoder for .NET Control to read, scan read, scan image in VS .NET applications.
www.OnBarcode.com
Up until now, we have simply returned strings from our web methods. You can also return complex data types such as a DataSet from your web methods. The code in Listing 9-12 illustrates how to return a DataSet from a web method. Listing 9-12. Returning a DataSet from a Web Method [WebMethod] public DataSet GetEmployees() { DataSet ds = new DataSet(); SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM employees", "data source=.\\sqlexpress;initial catalog=northwind;Integrated Security=True"); da.Fill(ds, "myemployees"); return ds; } The code creates an instance of DataSet and SqlDataAdapter. The code then calls the Fill() method of SqlDataAdapter, which accepts two parameters: the DataSet to fill and the name of the DataTable to be created. The code then returns the DataSet to the caller. If you run this web method by using the help page, you should see something similar to Figure 9-8.
Create ECC200 In .NET
Using Barcode maker for ASP.NET Control to generate, create Data Matrix image in ASP.NET applications.
www.OnBarcode.com
Create Linear In VB.NET
Using Barcode creation for .NET framework Control to generate, create Linear 1D Barcode image in VS .NET applications.
www.OnBarcode.com
Figure 9-8. Web method returning a DataSet
Read Barcode In Java
Using Barcode decoder for Java Control to read, scan read, scan image in Java applications.
www.OnBarcode.com
Print Barcode In Objective-C
Using Barcode generator for iPhone Control to generate, create Barcode image in iPhone applications.
www.OnBarcode.com
C H APTE R 9 XM L WEB S ERVI CES
Scan Barcode In C#.NET
Using Barcode Control SDK for .NET framework Control to generate, create, read, scan barcode image in VS .NET applications.
www.OnBarcode.com
Drawing UPC - 13 In Visual Studio .NET
Using Barcode maker for .NET Control to generate, create European Article Number 13 image in Visual Studio .NET applications.
www.OnBarcode.com
As you can see, the entire DataSet is serialized as XML data.
Generating QR In None
Using Barcode drawer for Online Control to generate, create QR Code ISO/IEC18004 image in Online applications.
www.OnBarcode.com
PDF 417 Drawer In Java
Using Barcode printer for BIRT reports Control to generate, create PDF 417 image in BIRT applications.
www.OnBarcode.com
Returning Custom Objects from a Web Method
Encode GS1 DataBar Expanded In Java
Using Barcode encoder for Java Control to generate, create GS1 DataBar Stacked image in Java applications.
www.OnBarcode.com
USS Code 39 Printer In None
Using Barcode generator for Office Excel Control to generate, create Code 39 Extended image in Excel applications.
www.OnBarcode.com
In the previous examples, you saw how to return primitive data types such as a string and builtin class types such as DataSet. In this example, you will see how to return custom objects from a web method. First, you need to create a new class inside the web service project. To do so, right-click the App_Code folder and choose Add New Item. From the dialog box that opens, select Class and call it Employee. Add the property definitions shown in Listing 9-13 to the Employee class. Listing 9-13. Creating the Employee Class public class Employee { private int intID; private string strFName; private string strLName; private string strHPhone; private string strNotes; public int EmployeeID { get { return intID; } set { intID = value; } } public string FirstName { get { return strFName; } set { strFName = value; } }
CHAPTER 9 XML WEB SERVICE S
public string LastName { get { return strLName; } set { strLName = value; } } public string HomePhone { get { return strHPhone; } set { strHPhone = value; } } public string Notes { get { return strNotes; } set { strNotes = value; } } } The code creates a class named Employee with five public properties: EmployeeID, FirstName, LastName, HomePhone, and Notes. Note that when an instance of any class is serialized as a return value of a web method, only the public members are serialized. Next, we will create a web method called GetEmployee() that creates an instance of the Employee class, sets its properties, and returns it back to the client. Listing 9-14 shows the GetEmployee() method.
C H APTE R 9 XM L WEB S ERVI CES
Listing 9-14. Returning an Object from a Web Method [WebMethod] public Employee GetEmployee() { Employee emp = new Employee(); emp.EmployeeID = 1; emp.FirstName = "Nancy"; emp.LastName = "Davolio"; emp.HomePhone = "(206) 555-9857"; emp.Notes = "Notes go here"; return emp; } If you invoke the web method via the help page, you should see something similar to Figure 9-9.
Figure 9-9. Returning a custom object from web methods You will find that the output is very similar to the one generated during XML serialization in 8.
Creating a Proxy for a Web Service
To create a proxy for the web service by using Visual Studio, you must first create the client application because the proxy always resides there. Though any type of application can act as a client to the web service, as an example we will create a Windows application that consumes the web service. Create a new Windows application in Visual Studio. Right-click the project in Solution Explorer and choose Add Web Reference. The Add Web Reference dialog box shown in Figure 9-10 will be displayed.
Copyright © OnBarcode.com . All rights reserved.