Dot Net

Can you show a simple code showing file dependency in cache ?

Partial Class Default_aspx

Public Sub displayAnnouncement() Dim announcement As String

If Cache(“announcement”) Is Nothing Then Dim file As New _

System.IO.StreamReader _

(Server.MapPath(“announcement.txt”)) announcement = file.ReadToEnd file.Close()

Dim depends As New _

System.Web.Caching.CacheDependency _ (Server.MapPath(“announcement.txt”))

Cache.Insert(“announcement”, announcement, depends)

End If

Response.Write(CType(Cache(“announcement”), String)) End Sub

Private Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init

displayAnnouncement()

End Sub

End Class

Note :- Above source code can be obtained from CD in “CacheSample”

folder.”Announcement.txt” is in the same folder which you can play around to see the results.

Above given method displayAnnouncement() displays banner text from Announcement.txt file which is lying in application path of the web directory. Above method first checks whether the Cache object More >

What is an application object ?

Application object ca be n used in situation where we want data to be shared across users globally.

Do webservice have state ?

Twist :- How can we maintain State in Webservices ?

Webservices as such do not have any mechanism by which they can maintain state. Webservices can access ASP.NET intrinsic objects like Session, application and so on if they inherit from “WebService” base class.

<%@ Webservice %> Imports System.Web.Services

Public class TestWebServiceClass Inherits WebService

<WebMethod> Public Sub SetSession(value As String) session(“Val”) = Value

End Sub

end class

Above is a sample code which sets as session object called as “val”. TestWebserviceClass is inheriting from WebService to access the session and application objects.

What are the steps to create a webservice and consume it ?

Note :- For this question this book will make a attempt by creating a simple webservice and explaining steps to acheive it. A simple webservice will be created which takes two number and gives addition result of the two number. In CD sample webservice project with folder name “MathsWebService” is provided and same will be explained below. Definitely the interviewer will not expect such a detail answer but this book will explain you in detail so that you are on right track during interview.

This webservice will add two numbers and give to the calling client.All the below steps are according to More >

What is file extension of Webservices ?

.ASMX is extension for Webservices.

Note :- After this we are going to deal with a sample of webservice. In VS2005 webproject is created from the menu itself as compared to 2003 where it was present in the explorer.

Which attribute is used in order that the method can be used as WebService ?

WebMethod attribute has to be specified in order that the method and property can be treated as WebService

What the different phase/steps of acquiring a proxy object in Webservice ?

Following are the different steps needed to get a proxy object of a webservice at the client side :-

?   Client communicates to UDI node for WebService either through browser or UDDI’s public web service.

?   UDII responds with a list of webservice.

?   Every service listed by webservice has a URI pointing to DISCO or WSDL document.

?   After parsing the DISCO document, we follow the URI for the WSDL document related to the webservice which we need.

?   Client then parses the WSDL document and builds a proxy object which can communicate with Webservice.

What is WSDL?

Web Service Description Language (WSDL)is a W3C specification which defines XML grammar for describing Web Services.XML grammar describes details such as:-

?   Where we can find the Web Service (its URI)?

?   What are the methods and properties that service supports? ?   Data type support.

?   Supported protocols

In short its a bible of what the webservice can do.Clients can consume this WSDL and build proxy objects that clients use to communicate with the Web Services. Full WSDL specification is available at http://www.w3.org/TR/wsdl.

What is DISCO ?

DISCO is the abbreviated form of Discovery. It is basically used to club or group common services together on a server and provides links to the schema documents of the services it describes may require.

What is UDDI ?

Full form of UDDI is Universal Description, Discovery and Integration. It is a directory that can be used to publish and discover public Web Services. If you want to see more details you can visit the http://www.UDDI.org .