banner



How Can One Access A Class As A Web Service?

Introduction

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

WebService Grade

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

Creating a Simple Web Service

Use the post-obit steps to create a web service.

  • Go to Visual Studio 2010 and create a New Project.

img1.gif

  • Select .Cyberspace Framework three.v.
  • Create an ASP.NET Spider web Service Awarding.
  • Requite it a name and click the ok button.

img2.gif

We volition see the following lawmaking.

  1. public class  Service1 : System.Web.Services.WebService
  2. {
  3.         [WebMethod]
  4. public string  HelloWorld()
  5.         {
  6. return "Hullo World" ;
  7.         }
  8. }

Inheriting from the WebService course is mainly convenient.

  • It does non add any functionality to our Web Service.
  • The convenience is that the WebService class provides straight access to the Web.HTTPContext object of the current request.
  • By inheriting from the WebService class we tin can access the Awarding object directly.
  • The .NET Framework only supports single inheritance; inheriting from WebService means that our form cannot inherit from other classes. This is actually the merely reason not to inherit from WebService.
  • An interesting indicate with inheriting from WebService is that WebService is derived from the System.MarshalByRefObject course. This class is the base grade for .NET Remoting.

The WebService course has the following properties:

  • Awarding- 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 procedure Spider web requests.
  • Server- The HTTPServerUtility object of the current asking. This is similar to the Server object institute in ASP. It contains, for instance, the CreateObject() part.
  • Session- The Session object holding the session state of the Web Service.
  • User- The User object is used to get access to security data such every bit whether the user is authenticated and the name of the authenticated user.

WebService Directive

When we create an XML Web service in ASP. Internet, we place the required @ WebService directive at the meridian of a text file with a .asmx file name extension. The presence of the .asmx file and the @ WebService directive correlates the URL address of the XML Spider web service with its implementation.

The @ WebService directive tells the ASP.Cyberspace runtime that the .asmx file contains an XML Web service and provides information about the implementation of the Web service. Hither is the instance of an @ WebService directive:

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

The directive is required for ASP.NET Web Services. If the form for the Spider web Service is in a lawmaking-backside file, this line volition be the only line in the .asmx file.

The directive may use the post-obit attributes.

  • Language
  • Codebehind
  • Class
  • Debug

Linguistic communication

The Language attribute is optional. Information technology specifies the language to use to compile the Spider web Service. Any .NET compiler installed on the system may exist specified. By default, the installed compilers are C#, VB.Cyberspace, and JScript.Net. These are specified using the values VB, C#, or JS.

  1. <%@ WebService Linguistic communication= "C#"  %>

The default language is VB.NET as specified in the car.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 detect the code-backside file for the .asmx file and then that when you lot click on the .asmx file it can open the code-behind file. The attribute is just used in Visual Studio .Internet; it has no upshot when the Spider web Service is executing.

  1. <%@ 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 post-obit case. In this example, the namespace is MyVSDemo and the class is on Akshay.

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

 If the class is not inside a namespace, we specify the class straight:

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

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

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

If the associates 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 Spider web service should be compiled with debug symbols; otherwise, faux.

  1. <%@ WebService Linguistic communication= "C#"  CodeBehind= "Akshay.asmx.cs"  Class= "Akshay"   debug= "truthful" %>

Resources

  • Microsoft Cognition Base of operations Spider web Service Consumer
  • An Introduction to Windows Advice Foundation (WCF)
  • ASP.NET Web Service Basics
  • Building ASP.Internet Web Services

Source: https://www.c-sharpcorner.com/UploadFile/1d42da/web-service-class-and-directive-in-Asp-Net/

Posted by: williamswifigh75.blogspot.com

0 Response to "How Can One Access A Class As A Web Service?"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel