namrata's profileNashaPhotosBlogListsMore ![]() | Help |
|
|
February 17 Interview Questions & AnswersIf you have any questions in mind please mail them to me at namratha1@gmail.com in the below format. E.g.
February 09 .NET Remoting ( Part - 5 -> Configuration File )Configuration files have always been a part of our applications. They generally hold data which is configurable, so instead of hard coding the parameters in the code we can read them form a config file. In .NET Remtoing we have some xml elements to configure our channel and remote objects. February 07 .NET Remoting ( Part - 4 --> LifeTime Management )Continuing our discussion with LifeTime Management :- Lifetime Management has been one of the biggest challenges in distributed applications. It is difficult to detect for client and server that whether the other is available or not.
February 04 .NET Remoting ( Part - 3 Formatters,ObjectActivation,Proxy & Msg Sinks)Continuing our yesterdays discussion letz start with formatters. February 03 .NET Remoting ( Part - 2 Channels )Channels : January 31 Article : .NET Remoting ( Part - 1 )Today we will be discuss .NET Remoting. Let us start of with its Introduction :- January 27 Article : Access Win Registry through .NETRegistry has been a central repository for a lot of Microsoft applications over the years. You can access a machine's registry using the regedit tool. . NET also provides us with classes named RegistryKey and Registry under Microsoft.Win32 namespace to access registry. Registry class exposes all the main key of the registry i.e. CurrentUser, CurrentConfig, LocalMachine, CurrentConfig, ClassesRoot and Users as Registry.CurrentUser, Registry.CurrentConfig, Registry.LocalMachine, Registry.CurrentConfig, Registry.ClassesRoot and Registry.Users. There are methods to get any sub key under any of the main keys (the ones mentioned above). You can retrieve reference to the main and then retrieve the list of sub keys under it. E.g. Here I am retrieving reference to the registry key CurrentUser and then retrieve the list of sub keys under it. RegistryKey rk = Registry.CurrentUser.OpenSubKey("Software"); string[] keys = rk.GetSubKeyNames(); // returns an array of sub key names. Note: In the above code retrieving a reference to the Current User Registry Key returns me an Registry Key object. To retrieve any detail of that registry key I need to call methods registry key object. You can retrieve the sub key count calling the SubKeyCount () method on registry key object.To create a sub key under any registry key retrieve the reference to that registry key and call CreateSubKey() method. E.g. Here I am creating a sub key named "Nasha" under the Root\CurrentUser\Software. RegistryKey rk = Registry.CurrentUser.OpenSubKey("Software",true);RegistryKey subkey = rk.CreateSubKey("Nasha"); Remember whenever you open a key to create keys under it pass the second value as true. Passing the second value as true will grant you a write access. CreateSubkey method returns reference to the new key. Thus you can use this reference to create nested keys. To create values under that key node call the Setvalue() method and pass the name and value parameters. rk.SetValue("abcd","abcd");To delete keys and values there are methods like DeleteSubKey(), DeleteSubKeyTree(), DeleteValue().There are a lot of other useful methods like GetValueNames() and GetSubKeyNames() and properties like rk.ValueCount and rk.SubKeyCount.After you are through with your manipulation dont forget to close the key with rk.Close(); January 24 Locking config setting using <location> tagHi Group, In ASP.NET is very easy to override configuration settings defined in the machine.config. All that you need to do is create a web.config file and specify the settings in it. Sometimes we want that certain configuration settings are not overridden by any application esp if it is your company server hosting many applications.In that case we need to lock these settings. There is a tag called <location> tag which can be added to machine.config file. This tag has two attributes named path which is the path of the application and allowOverride which takea a boolean value. If we set the value of allowOverride attribute as false then if the application mentioned in the path tries to override config settings will get an error. e.g. <configuration> <location path="DefaultwebsitePath/MyApp" allowOverride="true"> <system.web> | | Session state settings, trace settings etc | </system.web> </location> </configuration> Now if MyApp tries to overrider these settings it will get an error. -- Please post your queries and comments for my articles in the user group for the benefit of all. I hope this step from my end is helpful to all of us. You can find all articles written by me at my personal blog http://spaces.msn.com/members/nasha. January 20 Configuring machine.config to recycle aspnet_wpThere has been a lot of times when we feel that our application is slowing down or the ASP.Net worker process is not working as its best. Although ASP.NET does recycle its process after certain number of requests or memory Limit but there are times when you feel that you could control these parameters and explicitly restart the worker process. It is possible to restart the worker process explicitly after a certain number of requests. In Machine.config under <configuration> <system.web><procesmodel> we have an attribute called requestLimit. Set this request Limit to the number of requests after you want to recycle your worker process. It can be set to Infinite or any particular number. The default setting is 5000. Suppose if we set to it say 10 then you will notice that after every 10 requests aspnet_wp process will be recycled. You can note the process id's to feel the change. Second reason coz of which we may want our process to be recycled is because of high consumption of memory. In Machine.config under <configuration> <system.web><procesmodel> we have an attribute called memoryLimit. Set the threshold to the amount you want. The default is 60 i.e. 60%. The moment this threshold is reached aspnet_wp will be recycled. Before we make any changes to the machine.config we must remember that these changes are going to affect all the applications on that machine coz we are these changes at the core level. Hence after making these changes we should bench mark all our applications. January 19 Article : COM + Services Part 6 ( Security )Today we will implement Role based Security in COM+ Components Article : COM + Services Part 5 ( .NET Implementation Contd.)Today we will create a client app for our COM+ component the different types of COM+ applications and how to implement JIT and ObjectPooling in them. Article : COM + Services Part 4 ( .NET Implementation )For using COM+ Services from .NET Assemblies is possible with help of System.EnterprisesServices Namespace. //details by parsing through the arraylist to update the Employee Skills table January 16 COM+ Services Series ( Part - 3 )Today we will discuss ECC features of COM+. These features were not present in MTS and but are present in COM+ Services. Events: - This is a new service that has been added in COM+. This service one has to register an event interface with COM+ Services. Then you register classes that raise this event. These classes are called as publishers. After registering publishers you create classes that handle the raised events. These are called as subscribers. This model is also called as publisher-subscriber model. Hence when publisher raises an event COM+ will notify all its subscribers. Here COM+ acts as an intermediate layer between publisher class and subscriber classes so that they do not refer each other directly. Component Message Queuing: - In the past a lot of times there have been instances when we have faced problems of the component not being available or the component being offline. For these situations we had to provide some error handling logic. But COM+ now provides us with a new option for queuing requests for any offline component so that when the component comes online it can forward the request to the component. All these things happen behind the scene and the client is completely unaware of this. As soon as the component available the requests are executed and the results are sent to the client. But if we have looking forward for this option then we should have robust error handling coz it should not happen the client is waiting for prolonged period of time or even if the component is available the request raised an error or exception. Component Load Balancing: - This is one of the most important feature of COM+. Component load balancing is used to cater a large number of clients by balancing client requests between COM+ Components. When one feels that one server is not enough to provide a quick response to the clients and the client response time is increasing, you can have multiple servers hosting your components. Component Load balancing is used to balance the number requests across servers. It distributes client requests across component servers thus enabling a fast and better performance and reducing the response time. If we were to consider component load balancing we should keep in mind the fact the request may not go to the same server every time. Hence the architecture of all our objects should stateless. I had discussed this before also when we checked out JIT and object pooling. Object pooling is not available when Component Load balancing is done for obvious reasons coz you do not where the previous request was executed COM+ Services Series ( Part - 2 )Let us first discuss the JOTS features. These features were present in MTS and are present in COM+ Service also. Just-In-Time Activation: - Object creation by itself is a very expensive process hence before instantiating an object we need to consider a lot of parameters like the amount of memory it will take, how many objects will be created at any given point of time, after instantiating objects how will we deallocate its memory, etc. Just-in-time Activation allows the developer to create an object once and then use it wherever required without worrying about resources consumed by that object. This is because behind the scenes JIT deallocates the memory when the object is not used and then reallocates then when the client references the object or calls any method on them. Thus the client can hold references to as many objects required coz COM+ will provide objects whenever necessary and deallocate them when required. Since JIT deallocates memory it is quite possible that it may dellocate memory between two function calls, thus there is no guarantee that the same property values will be available between subsequent calls. Hence the COM+ objects should ideally be stateless (i.e. should not have properties). Object Pooling: - We just discussed JIT and saw how COM+ handles its memory allocation and deallocation coz object creation is an expensive process. Further on to that COM+ even allows you to create an object pool to reuse objects that are created. Whenever any COM+ client releases an object COM+ does not destroy the object if ObjectPooling is enabled but sends the object to the Pool to reuse the object when some other client asks for the same.By Nature object Pooling can share the object instance between several clients. Thus if you have properties in your class they will be shared across all the clients. Hence to avoid this it is a good practice to create class that are stateless. So that in between function calls there is no need to maintain the state. Note: - JIT and Object Pooling together make the heart of COM+. Object Pooling may have a pool of objects reusable across clients but its JIT that decides its allocation and deallocation. Thus making the objects stateless is a very good practice coz then we can use both the services effectively as our classes reduce to function libraries.Transaction Enforcement: - There are 5 transactions types that can be used with COM+. Whenever an object is registered with COM+ it has to abide either to these 5 transaction types. Disabled: - There is no transaction. COM+ does not provide transaction support for this component. Not Supported: - Component does not support transactions. Hence even if the calling component in the hierarchy is transaction enabled this component will not participate in the transaction. Supported : - Components with transaction type supported will be a part of the transaction if the calling component has an active transaction.If the calling component is not transaction enabled this component will not start a new transaction. Required: - Components with this attribute require a transaction i.e. either the calling should have a transaction in place else this component will start a new transaction. Required New: - Components enabled with this transaction type always require a new transaction. Components with required new transaction type instantiate a new transaction for themselves every time.Security : - This is another important aspect of COM+. This allows granting access rights to users at component level. COM+ allows you to create roles and add users to these roles. Hence when a user tries to instantiate an object COM+ checks the users role. You can define different roles and access rights for these roles. If the user is in role defined he/she will be granted rights as defined for that role.COM+ Services Series ( Part - 1 )Today we are going to discuss COM+ Services. Some of us know COM+ coz we have worked with MTS during our VB days. However COM+ can be used with .NET also. As a developer I have always inquisitive about a lot questions and I am sure that you must also be having these questions in mind. Let us discuss these: -
I remember them as JOTS features. New Features in COM+:
I remember them as ECC features. Overriding, Shadowing and Hiding in .NETMost of us I guess are familiar with overridering from C++ or Java. Overriding as the term says is to override the base class implementation or provide a new implementation in the derived class. We can override members in the base class in VB.Net using the keyword Overrides and in C# using the key word override. To override a base class member in VB.Net it should be marked as Overridable and in C# they should be marked with virtual. Method signature of the overiddden methods should be same as the base class methods. December 23 Article : WebServices Series Part - 5 ( Sync & Async Communication )Yesterday we saw how we can communicate with web services using callbacks. Today we will discuss the other two techniques Polling and Waithandles. Polling : When we made a call to our web service using callback we passed it reference to our fucntion and in return we get an IAsyncResult object back which acted as a token. WaitHandles : This method also uses one of the properties of IAsyncResult object called AsyncWaitHandle. Article : WebServices Series Part - 4 ( Sync & Async Communication )Today we will checkout how to consume our web service using SOAP in Synchronous and Asynchronous modes. WebServices Series Part - 3 (Accessing with HTTP POSTLOCALHOST, POST and GET)Today we will look how we can access web services with HTTP-GET and HTTP-POST protocols. .Net Framework 1.0 had all the three protocols i.e. HTTP-POST,HTTP-GET AND HTTP-SOAP enabled by default. But in version 1.1 only HTTP-SOAP is enabled by default. Hence if you want to access the web service my HTTP-POST or GET then you will have to enable it explicitly. Since HTTP-POST is not enabled by default in .Net framework 1.1 to test web service on the local machine there is a new protocol that has been added i.e. HTTPPOSTLOCALHOST. It is because of this protocol that while testing a web service you are able to view a test form on your local machine and not on a remote computer. Let us check out each of these protocols individually: - HTTPPOSTLOCALHOST: - This is enabled by default in .Net Framework version 1.1. Hence if you access your website as http://localhost you will get the test form but if you test the same web service with http://<name of your computer> from some other computer than the test form will not be displayed. e.g. Try and access our trigonometry web service from your machine and then access it from any other machine. You will notice that the test form will not be displayed. Before we look at HTTP-POST and HTTP-GET we need to checkout DefaultWsdlHelpGenerator.aspx. DefaultWsdlHelpGenerator.aspx is the default wsdl help file located at <drive>:\WINNT\Microsoft.NET\Framework\v1.1.4322\CONFIG. Open DefaultWsdlHelpGenerator.aspx and checkout showPost flag. bool showPost = true; // search for this Depending the value of showPost flag HTTP-GET or HTTP-POST protocol is used.Set its value to true if you want to see a POST test form and false to view a GET test form. Along with this you will have to include the appropriate protocols in the web services tag in Web.config. HTTP-POST: - To enable our web service with HTTP-POST we will have to make the following changes. 1. Open the web.config and add the <webServices> tag under <system.web> as follows to enable the HTTP-POST protocol. <webServices> 2. Open DefaultWsdlHelpGenerator.aspx and set the value of showPost to true. By default it is set to true. http://namrathas/Trigonometery/MyService.asmx/CoSine 5. Execute your web service from some other computer and you will be able to view HTTP-POST test form. HTTP-GET: - To enable our web service with HTTP-GET we will have to make the following changes. 1. Open the web.config and add <add name="HttpGet"/> to protocols tage s follows to enable our webservice with HTTP-GET protocol also. <webServices> 2. Open DefaultWsdlHelpGenerator.aspx and set the value of showPost to false. So now HTTP-POST form will be displayed. All the parameters will be passed as querystring. http://namratas/Trigo/MyService.asmx/CoSine?angel=5 3. Run the web service and checkout the HTTP-GET form. Its looks the same as HTTP-POST form. You will notice the difference on execution. HTTP-SOAP: - Whenever our webservice is accessed from any application HTTP-SOAP protocol is used. HTTP-SOAP is enabled by default. We will look in to more details of HTTP-SOAP when we look into consuming webservices. Hence if want our webservice to be enabled for all the four protocols we need to add them in the <protocols> tag. <webServices> WebServices Series Part - 2 (WebMethod and WebService Properties)After creating our basic web service yesterday we will look into the web method properties and supported data types. Well Whenever we create a web service all those methods of the web service which we want to be web-callable have to be marked with the web method attribute and should have a public access modifier. Web Method Attribute is basically used to make a method web callable. WebMethod attribute has the following properties like :-
Description :- It is used for commenting the web method. The description that is added here is included in WSDL. Add the webmethod description property above any method as shown below. When you call the webservice from a browser you view the web service.
e.g. [WebMethod(Description = "My WebMethod Description comes here")]
Enable Session :- WebServices are a type of ASP.NET applications hence you can access your ASP.NET application Session from your webservice. By default the session is disabled i.e. set to false. You can enable it by setting its value to true.
e.g. [WebMethod(EnableSession ="true")]
Message Name :- Message Name property is used give an alias to a method name. This is esp. useful when you are using overloaded methods.
e.g. Yesterday we created 3 method in our webservice for cos,sin and tan which took double as an input parameter. Today we will create their overloads that will take int as an input parameter
[WebMethod]
If you compile this code it will compile successfully. It is on execution that you we view the below error message
Error Message: Both Double Tan(Int32) and Double Tan(Double) use the message name 'Tan'. Use the MessageName property of the WebMethod custom attribute to specify unique message names for the methods.
Web service needs to identify each method uniquely hence we will give alias to the methods by setting the MessageName property.
e.g. [WebMethod(MessageName = "SinInt")]
TransactionOption : - If our web service is a part if any COM/MTS transaction application then we can enable the Transaction Option of the webservice thus making it a part of the 2 phase commit protocol of MTS.
e.g. [WebMethod(TransactionOption = "Supported")]
The dafault is same as COM/MTS transactions i.e. Required.
CacheDuration :- Like any other ASP.NET applications WebServices also support output caching. Output caching gives a performance boost coz the same request is not executed repeatedly instead the result is return from the cache itself. This feature is esp. useful when you are retrieving chunks of data from the database for listing and other purposes. But caching should preferably used with only those methods where we know that the data will not change frequently.
e.g. [WebMethod(CacheDuration = "180")]
BuffferResponse :- We all are familiar with the buffering property rite from our ASP days where used Response.Buffer = true so that the response is only sent when the Response for the request is completely generated or when the buffer is full. WebServices also use the same logic. If we want our response to be sent across only after its complete processing is done we need to buffer our response by setting its property to true.
e.g. [WebMethod(BufferResponse = "true")]
By default it is set to true.
These properties were webmethod properties. We also have some web service properties like
Description :- This is same as web method property. It is used to comment web service and give it a description that is included in WSDL.
e.g. [WebService(Description = "My WebService Description comes here")] {
e.g. [WebService(Name = "MyNewName")]
NameSpace :- The default name space is http://tempuri.org. You can change this to http://localhost/MyWebServices. You should set namespace to any unique value.
e.g. [WebService(Namespace = "http://localhost/MyWebServices")] |
|
|