ASP.NET

1. ASP.NET Introduction 2. Comp of .Net Framework 3.5 3. Sys.Req for VS 2008 4. ASP.NET Envrmnt Setup 5. VS2010 Ultimate Sys.Req 6. Installing VS 2010 7. VS 2012 Sys.Req 8. Installing VS Exp 2012 9. Start the VS 2008 10. Application Life Cycle 11. Page Life Cycle 12. Page Life Cycle Events 13. ASP.NET Example 14. Event Handling 15. Default Events 16. Server Side 17. Request Object 18. Response Object 19. Server Controls 20. Server Controls Properties 21. Server Controls Methods 22. HTML Server Controls 23. Client Side 24. ASP.NET Basic Controls 25. TextBox Control 26. CheckBox Controls 27. RadioButton Controls 28. ListBox Control 29. HyperLink Control 30. Image Control 31. BulletedList Control 32. ASP.NET Directives 33. Implements Directive 34. Master Type Directive 35. Page Directive 36. PreviousPage Type 37. Managing State 38. Control State 39. Cookies 40. Query Strings 41. Server-Side State 42. Session State 43. Validation Controls 44. Required FieldValidator 45. Range Validator 46. Compare Validator 47. RegularExpressionValidator 48. Custom Validator 49. Validation Summary 50. Data Source Control 51. AdRotator Control 52. Calendar Control 53. Calendar Control Example 54. Panel Control 55. Panel Control Example 56. Multi Views Control 57. MultiView & View controls 58. MultiView Control Example 59. FileUpload Control 60. FileUpload Control Eg 61. AJAX Control 62. UpdatePanel control 63. UpdateProgress Control 64. Custom Controls 65. Custom Control Eg 66. Personalization 67. Create Simple Profile 68. ADO.NET 69. ADO.NET Objects 70. DataTable 71. DataRow 72. DataColumn 73. Object Example 74. Error Handling 75. Tracing Errors 76. Debugger 77. Security 78. Authentication 79. Authorization 80. LINQ 81. LINQ Query Operators 82. LINQ Example 83. Caching 84. Data Caching 85. Output Caching 86. Object Caching 87. Web Services 88. Create Web Services Eg 89. Web & Machine.config 90. Settings Schema 91. ASP.NET Deployment 92. XCopy Deployment 93. Web Setup Project 94. ASP Interview Part 1 95. ASP Interview Part 2 96. ASP Interview Part 3 97. ASP Interview Part 4 98. ASP Interview Part 5 99. ASP Interview Part 6
Pr.Pg Next Pg

Creating Web Services in .Net tutorials

The following steps shows the how to create a web services in .Net.

  • Step 1: Create the ASP.NET Web Service Source File:

Open Visual Studio 2008 or 2010 and create a new web site.->Select .Net Framework 3.5. ->Select ASP.NET Web Service page -> then, specify the name of your service “DemoWebServicesExmp". Then Click the ok Button.

A screen-shot of this activity is given below.

 

asp.net web services example

 

  • Step 2: Now click on the "ok" button; you will see the following window.

 

asp.net web services example

  • Here (in the above figure), you will note that there is predefined method "HelloWorld" which returns the string "Hello World". You can use your own method and can perform various operations. Here I made a simple method which returns the multiplication of two numbers using the code.The Code file Service1.asmx.cs is shown below.

 

 

The Code file Service1.asmx.cs

Sam Sir

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.Services;

 

namespace DemoWebServicesExmp

{

/// <summary>

/// Summary description for Service1

/// </summary>

[WebService(Namespace = "http://tempuri.org/")]

[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

[System.ComponentModel.ToolboxItem(false)]

// 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 Service1 : System.Web.Services.WebService

{

[WebMethod]

public int Multiplication(int a, int b, int c)

{

return (a * b * c);

}

}

}

 

 

 

 

From the above code the important term are:

using System.Web.Services;

This directive allows you to refer to objects in the System.Web.Services namespace without having to fully qualify the request. This statement is optional, but if it is not included, every reference to an object in this namespace must be fully qualified. An example is the next line, which is our class declaration. With the using statement, it looks as follows in C#:

The  [WebMethod] attribute:

The Service1 class exposes a single method, the public method Multiplication, which takes three integer arguments and returns the multiplication of three number as integer. To expose a method as a part of a web service, you must decorate it with the WebMethod attribute, which tells the compiler to treat it as such. Any method marked with the WebMethod attribute must be defined as public.

  • The Solution Explorer will look like that:

 

asp.net solution Explorer

 

  • The Service1.asmx : Which contains the following code:

<%@ WebService Language="C#" CodeBehind="~/App_Code/Service1.asmx.cs" Class="Service1" >%>

The page directive WebService is required and the class is the name of the .NET Class to expose the Web Service, each method exposes as Web Service Class Method need to have a declarative attribute statement.

  • Step 3- Build Web Service and Run the Web Service for testing by pressing F5 function key.

 

asp.net web services page

 

  • Step-4: Copy the url of this web service for further use.

Click on the Multiplication button to test the web service.

 

asp.net web services example

Enter the value of a, b and c:

asp.net web services example

 

Now Press the “Invoke” button a XML file is generated.

 

asp.net xml file

 

Now our web service is ready to use, now we will create a new web site to consume the web service.

  • Step 5 : Create a new web site”Test” by Fileà Newà Web Siteà Asp.net Web Site the screen shot is shown below.

 

asp.net web services pages

  • Step 6: Right-click on the Web Form “WebServicePage” and choose “Add Web Reference”.

 

asp.net add web reference page

 

  • Step 7: Paste the url of the web service and click on “Go” button and then Click on “Add Reference”.

 

 asp.net add reference page

  • Step 8: Now your web service is ready to use in the Solution Explorer you can see.

 

asp.net solution explorer page

 

  • Discovery or .Disco Files: Discovery files are used to group common services together on a web server. Discovery files .Disco and .VsDisco are XML based files that contains link in the form of URLs to resources that provides discovery information for a web service. Disco File contains URL for the WSDL, URL for the documentation and URL to which SOAP messages should be sent.

  •  

  • WSDL: WSDL stands for Web Service Description Language, a standard by which a web service can tell clients what messages it accepts and which results it will return. WSDL contains every detail regarding using web service and Method and Properties provided by web service and URLs from which those methods can be accessed and Data Types used.

  • Step 9: Now go to the design of the MywebserviceExmpl.aspx page, Drag and drop three textboxes , a button , and the level for displaying the result, the design of the MywebserviceExmpl.aspx page is below.

 

asp.net web pages

 

  • Step 10: Now go to the MywebserviceExmpl.aspx.cs page and on the button click event use the following code.

protected void Button1_Click(object sender, EventArgs e)
{
localhost.Service1
mywebser = new localhost.Service1(); // Create the object of the web service
int a = Convert.ToInt32(txtfirstno.Text);
int b = Convert.ToInt32(txtsecondno.Text);
int c = Convert.ToInt32(txtthirdno.Text);
int d = mywebser.Multiplication(a, b,c);
Label1.Text = d.ToString();
}

  • Step 11: After pressing the F5 function key, run the website of MywebserviceExmpl.aspx pages. And enter the number in to the Textboxes.which is shown in the below.

 

asp.net web pages

 

  • Step 12: Now Press the Calculate button.

 

asp.net web page

Pr.Pg border                                              Next Pg