IN-Sights INTO Web Services - Part 2

xiaoxiao2021-03-06  67

Introduction

In the

First

............................... ...CRIPLILE, TELEGEM. 汇 EDUCAM ,NIVIM.

Web Services IN .NET:

AS TOLD EARLIER, IN .NET A Web Service IS A ASP.NET Application With a file That Has <.asmx> EXTENSITION. The .asmx> File Is Like The Main Function In A C Program In Other Words It Is The Starting Point of the Web Service Application. Itself or code in a code-behind file <.asmx.cs or .asmx.vb> Which is the default style stocked in Visual Studio.net.

. The file has the "WebService" processing directive, which provides information as to which code-behind file and class implement the functionality of the web service This is implemented by the following attributes:

Using Syntax:

<% @ Webservice Language = "C #" codebehind = "service1.asmx.cs" class = "WebService1.service1"%>

The code-behind file . Defines the web service class, which inherits from "System.Web.Services.WebService" All the methods of the class are not accessible over the web Optionally the WebService attribute can. Be buy to specify Certain Properties for the Web Service.

The WebService attribute has four properties, which provide information about the web service. We now have a web service class but then what is the purpose of it when it does not expose its functionality over the web?

The WebMethod Attribute IS Used to Expose A Public Method of A Web Service Class Over the Web. The WebMethod Attribute Has Six Properties, Which Control The Way The Web Method Operates over the web.

WebService Attribute:

The Four Properties of The Webservice Attribute Are As Follows: Namespace Description Name TypeId

Each of the Above Properties IS Explained in detail below:

Namespace: in Order for An XML Web Service To Be distinguishable over the Web from Other Web Services, The Web Services Should Use a Unique Namespace. In vs.net the default namespace IS

http://tempuri.org

. This is fine during the development phase. But a unique namespace should be provided when the web service is published in the UDDI. The namespace does not have to be an existing URL. The main purpose of the namespace is only to uniquely identify the Webservice . The 'Namespace' Property of the Webservice Attribute Is Used to Specify A Namespace for the Web Service.

USAGE SYNTAX:

http://www.vadivel.com/

Name: = "VadiWebServiceFormathFunction"> _ _

Public Class Service1

Inherits System.Web.Services.Webservice

Description: This Property is buy for provoding a brief Description To a web service.

USAGE SYNTAX:

_ public class service1

Inherits System.Web.Services.Webservice

TYPEID: IT IS Used to Unique Identity The Type of The Attribute In WebMethod Attribute. But to my knowledge it is very rarely used.

WebMethod Attribute

The 6 Properties of The WebMethod Attribute Are As Follows:

Description MessageName Enablesession Cacheduration TransactionOption BufferResponse

Each of the Above Properties IS Explained in detail below:

Description: This Property Provides a brief Description to the WebMMETHOD.

USAGE SYNTAX:

Public Function Add2integer (Byval Num1 AS Integer, Byval Num2 AS Integer) AS IntegerReturn Num1 Num2

END FUNCTION

.

MessageName: this property is useful particularly when Web methods need to be overloaded.

Function Overloading IS Accomplished WHEN Functions Have The Same Name But Different IMPLEMENTATION.

USAGE SYNTAX:

Public function guyhello () AS STRING

Return "Hi Buddy ... happy new year"

END FUNCTION

Public Function Sayhello (Byval Sname As String) AS STRING

Return "Hi" & "& Sname

END FUNCTION

In The Above Example, The Sayhello Method Is Overloaded. One Method Takes Parameters and Other Does Not.

Enablesession:

HTTP is a stateless protocol. EnableSession property helps to maintain session state between server and the client. By default the EnableSession property is false. By setting this property to true the session between the first and subsequent requests can be maintained. If EnableSession is false, Session State Cannot Be Maintained at Any Point.

USAGE SYNTAX:

Cachedure:

CacheDuration property allows caching a web service result for a specified period of time (mentioned as milliseconds). Its nothing but a memory buffer which holds the result of a previously accessed method by a web services consumer. It increases the performance of the web service.

Let us say we have a webservice, which provides the list of trains starting from a particular location. When a user accesses this Web Service for the first time the result of this request is cached in memory. If during the next time some other user request the same service the result will be served from cache. This speeds up web service requests.But caching output blindly for all web services does not make sense. Let us consider a web service, which provides stock quotes. In this case, caching is NOT Worth Because stock quotes changing.

USAGE SYNTAX:

Public Function PrintTime () AS String

Return now (). TOSTRING

END FUNCTION

In The Above Example, The Cache Duration IS 60 Milliseconds. If The Same Method Is Invoked Within 60 MilliseConds, Both Requests Will Print The Same Time.

TransactionOption:

A Transaction IS A Set of Events That Are Committed or Rolled Back AS A Unit. Either All of the events happen or none of them do.

For Instance, Transferring RS. 1000 from your savings account and adding it to your checking account. To Achieve a Conscent Result, Either Both Operations Should succeed or fail.

The Transaction Options Supported by the TransactionOption Property Are Listed Below:

Transaction Options

Description

Disabled

Ignore Any Transaction in The Current Context

NotSupported

Creates The Component In a Context with no governing transaction

Required

Shares a transaction if one exists and creates a new transaction if Necessary.

Requiresnew

Creates The Component with a new Transaction Regardless of the State of the Current Context

Supported

Shars a Transaction if one exists

USAGE SYNTAX:

Public Function DOSMETRANS () AS STRING

...

Contextutil.setComplete

DOSMETRANS.TRANSACTIONAL = contextutil.transactionid.tostring ()

END FUNCTION

BufferResponse:

This property is used to determine if the Web Service Response will be buffered. When set to true (which is the default), ASP.NET buffers the entire response before sending it to the client. This type of buffering is very efficient and helps improve Performance by minimizing communication Between the worker process and the Iis process.

.

USAGE SYNTAX:

Conclusion

I Guess This Article Gave a Decent Introduction About The Various Attributes of Web Services and WebMethod. As i always say, Feel Free to Ping Me At

vmvadivel@gmail.com

To Discuss Further On this Or Catch ME AT

Http://vadivel.thinkingms.com

.

转载请注明原文地址:https://www.9cbs.com/read-120144.html

New Post(0)