Vyoms OneStopTesting.com - Testing EBooks, Tutorials, Articles, Jobs, Training Institutes etc.
OneStopGate.com - Gate EBooks, Tutorials, Articles, FAQs, Jobs, Training Institutes etc.
OneStopMBA.com - MBA EBooks, Tutorials, Articles, FAQs, Jobs, Training Institutes etc.
OneStopIAS.com - IAS EBooks, Tutorials, Articles, FAQs, Jobs, Training Institutes etc.
OneStopSAP.com - SAP EBooks, Tutorials, Articles, FAQs, Jobs, Training Institutes etc.
OneStopGRE.com - of GRE EBooks, Tutorials, Articles, FAQs, Jobs, Training Institutes etc.
Bookmark and Share Rss Feeds

Web Service Class and Directive in ASP.NET | Articles | Recent Articles | News Article | Interesting Articles | Technology Articles | Articles On Education | Articles On Corporate | Company Articles | College Articles | Articles on Recession
Sponsored Ads
Hot Jobs
Fresher Jobs
Experienced Jobs
Government Jobs
Walkin Jobs
Placement Section
Company Profiles
Interview Questions
Placement Papers
Resources @ VYOMS
Companies In India
Consultants In India
Colleges In India
Exams In India
Latest Results
Notifications In India
Call Centers In India
Training Institutes In India
Job Communities In India
Courses In India
Jobs by Keyskills
Jobs by Functional Areas
Learn @ VYOMS
GATE Preparation
GRE Preparation
GMAT Preparation
IAS Preparation
SAP Preparation
Testing Preparation
MBA Preparation
News @ VYOMS
Freshers News
Job Articles
Latest News
India News Network
Interview Ebook
Get 30,000+ Interview Questions & Answers in an eBook.
Interview Success Kit - Get Success in Job Interviews
  • 30,000+ Interview Questions
  • Most Questions Answered
  • 5 FREE Bonuses
  • Free Upgrades

VYOMS TOP EMPLOYERS

Wipro Technologies
Tata Consultancy Services
Accenture
IBM
Satyam
Genpact
Cognizant Technologies

Home » Articles » Web Service Class and Directive in ASP.NET

Web Service Class and Directive in ASP.NET








Article Posted On Date : Wednesday, March 21, 2012


Web Service Class and Directive in ASP.NET
Advertisements

Introduction

In this article, I am going to look beyond just VS.NET, at the options we have for configuring a Web Service using the Web Service class and directives that are available with ASP.NET.

WebService Class

A Web Service class may inherit from a class in the System.Web.Services namespace, the WebService class. The code emitted by Visual Studio .NET inherits from this class. see here

Creating a Simple Web Service:

Use the following steps to create a web service.

    Go to Visual Studio 2010 and create a New Project.

img1.gif

    Select .NET Framework 3.5.
    Create an ASP.NET Web Service Application.
    Give it a name and click ok button.

img2.gif

We will see the following code.

public class Service1 : System.Web.Services.WebService
    {
        [WebMethod]
        public string HelloWorld()
        {
           return "Hello World";
        }
    }

Inheriting from the WebService class is mainly a convenience.

    It does not add any functionality to our Web Service.
    The convenience is that the WebService class provides direct access to the Web.HTTPContext object of the current request.
    By inheriting from the WebService class we can access the Application object directly.
    The .NET Framework only supports single inheritance; inheriting from WebService means that our class cannot inherit from other classes. This is really the only reason not to inherit from WebService.
    An interesting point with inheriting from WebService is that WebService is derived from the System.MarshalByRefObject class. This class is the base class for .NET Remoting.

The WebService class has the following properties:

    Application- The Application object holding the application state of the Web Service.
    Context- Gets the ASP.NET HttpContext for the current request, which encapsulates all HTTP-specific context used by the HTTP server to process Web requests.
    Server- The HTTPServerUtility object of the current request. This is similar to the Server object found in ASP. It contains, for instance, the CreateObject() function.
    Session- The Session object holding the session state of the Web Service.
    User- The User object is used to get access to security information such as whether
    the user is authenticated and the name of the authenticated user.

WebService Directive
When we create an XML Web service in ASP. NET, we place the required @ WebService directive at the top of a text file with an .asmx file name extension. The presence of the .asmx file and the @ WebService directive correlates the URL address of the XML Web service with its implementation.
 The @ WebService directive tells the ASP.NET runtime that the .asmx file contains a XML Web service and provides information about the implementation of the Web service. Here is the example of an @ WebService directive:

<%@ WebService Language="C#" CodeBehind="Akshay.asmx.cs" Class="Akshay" %>

The directive is required for ASP.NET Web Services. If the class for the Web Service is in a codebehind
file, this line will be the only line in the .asmx file.

The directive may use the following attributes.

    Language
    Codebehind
    Class
    Debug

Language

The Language attribute is optional. It specifies the language to use to compile the Web Service. Any
.NET compiler installed on the system may be specified. By default the installed compilers are C#,
VB.NET and JScript.NET. These are specified using the values VB, C#, or JS.

<%@ WebService Language="C#" %>

The default language is VB.NET as specified in the machine.config file, unless it is overridden in the
web.config file.

Codebehind

The Codebehind attribute is optional. It is used by Visual Studio .NET to find the code-behind file for
the .asmx file so that when you click on the .asmx file it can open the code-behind file. The attribute is
only used in Visual Studio .NET; it has no effect when the Web Service is executing.

<%@ WebService Language="C#" CodeBehind="Akshay.asmx.cs" Class="Akshay" %>

Class

The Class attribute specifies the class to expose as a Web Service. If the class is within a namespace,
the namespace is specified, as in the following example. In this example, the namespace is MyVSDemo and
the class is Akshay.

<%@ WebService class="MyVSDemo.Akshay"%>

 If the class is not within a namespace, we specify the class directly:

<%@ WebService class="Akshay"%>

 The class attribute may optionally also specify the assembly where the class exists:

<%@ WebService class="MyVSDemo.Akshay, MyVSDemo"%>

 If the assembly is not specified, ASP.NET searches all assemblies in the bin directory for the Akshay class.

Debug

Indicates whether the XML Web service should be compiled with debug symbols; true if the XML Web service should be compiled with debug symbols; otherwise, false.

<%@ WebService Language="C#" CodeBehind="Akshay.asmx.cs" Class="Akshay"  debug="true"%> 






Sponsored Ads



Interview Questions
HR Interview Questions
Testing Interview Questions
SAP Interview Questions
Business Intelligence Interview Questions
Call Center Interview Questions

Databases

Clipper Interview Questions
DBA Interview Questions
Firebird Interview Questions
Hierarchical Interview Questions
Informix Interview Questions
Microsoft Access Interview Questions
MS SqlServer Interview Questions
MYSQL Interview Questions
Network Interview Questions
Object Relational Interview Questions
PL/SQL Interview Questions
PostgreSQL Interview Questions
Progress Interview Questions
Relational Interview Questions
SQL Interview Questions
SQL Server Interview Questions
Stored Procedures Interview Questions
Sybase Interview Questions
Teradata Interview Questions

Microsof Technologies

.Net Database Interview Questions
.Net Deployement Interview Questions
ADO.NET Interview Questions
ADO.NET 2.0 Interview Questions
Architecture Interview Questions
ASP Interview Questions
ASP.NET Interview Questions
ASP.NET 2.0 Interview Questions
C# Interview Questions
Csharp Interview Questions
DataGrid Interview Questions
DotNet Interview Questions
Microsoft Basics Interview Questions
Microsoft.NET Interview Questions
Microsoft.NET 2.0 Interview Questions
Share Point Interview Questions
Silverlight Interview Questions
VB.NET Interview Questions
VC++ Interview Questions
Visual Basic Interview Questions

Java / J2EE

Applet Interview Questions
Core Java Interview Questions
Eclipse Interview Questions
EJB Interview Questions
Hibernate Interview Questions
J2ME Interview Questions
J2SE Interview Questions
Java Interview Questions
Java Beans Interview Questions
Java Patterns Interview Questions
Java Security Interview Questions
Java Swing Interview Questions
JBOSS Interview Questions
JDBC Interview Questions
JMS Interview Questions
JSF Interview Questions
JSP Interview Questions
RMI Interview Questions
Servlet Interview Questions
Socket Programming Interview Questions
Springs Interview Questions
Struts Interview Questions
Web Sphere Interview Questions

Programming Languages

C Interview Questions
C++ Interview Questions
CGI Interview Questions
Delphi Interview Questions
Fortran Interview Questions
ILU Interview Questions
LISP Interview Questions
Pascal Interview Questions
Perl Interview Questions
PHP Interview Questions
Ruby Interview Questions
Signature Interview Questions
UML Interview Questions
VBA Interview Questions
Windows Interview Questions
Mainframe Interview Questions


Copyright © 2001-2025 Vyoms.com. All Rights Reserved. Home | About Us | Advertise With Vyoms.com | Jobs | Contact Us | Feedback | Link to Us | Privacy Policy | Terms & Conditions
Placement Papers | Get Your Free Website | IAS Preparation | C++ Interview Questions | C Interview Questions | Report a Bug | Romantic Shayari | CAT 2025

Fresher Jobs | Experienced Jobs | Government Jobs | Walkin Jobs | Company Profiles | Interview Questions | Placement Papers | Companies In India | Consultants In India | Colleges In India | Exams In India | Latest Results | Notifications In India | Call Centers In India | Training Institutes In India | Job Communities In India | Courses In India | Jobs by Keyskills | Jobs by Functional Areas

Testing Articles | Testing Books | Testing Certifications | Testing FAQs | Testing Downloads | Testing Interview Questions | Testing Jobs | Testing Training Institutes

Gate Articles | Gate Books | Gate Colleges | Gate Downloads | Gate Faqs | Gate Jobs | Gate News | Gate Sample Papers | Gate Training Institutes

MBA Articles | MBA Books | MBA Case Studies | MBA Business Schools | MBA Current Affairs | MBA Downloads | MBA Events | MBA Notifications | MBA FAQs | MBA Jobs
MBA Job Consultants | MBA News | MBA Results | MBA Courses | MBA Sample Papers | MBA Interview Questions | MBA Training Institutes

GRE Articles | GRE Books | GRE Colleges | GRE Downloads | GRE Events | GRE FAQs | GRE News | GRE Training Institutes | GRE Sample Papers

IAS Articles | IAS Books | IAS Current Affairs | IAS Downloads | IAS Events | IAS FAQs | IAS News | IAS Notifications | IAS UPSC Jobs | IAS Previous Question Papers
IAS Results | IAS Sample Papers | IAS Interview Questions | IAS Training Institutes | IAS Toppers Interview

SAP Articles | SAP Books | SAP Certifications | SAP Companies | SAP Study Materials | SAP Events | SAP FAQs | SAP Jobs | SAP Job Consultants
SAP Links | SAP News | SAP Sample Papers | SAP Interview Questions | SAP Training Institutes |


Copyright ©2001-2025 Vyoms.com, All Rights Reserved.
Disclaimer: VYOMS.com has taken all reasonable steps to ensure that information on this site is authentic. Applicants are advised to research bonafides of advertisers independently. VYOMS.com shall not have any responsibility in this regard.