Saturday, 14 September 2013

Web Services and Windows Services Interview Questions

WebServices And Windows Services

Can you give an example of when it would be appropriate to use a web service as opposed to non-serviced .NET component
Web service is one of main component in Service Oriented Architecture. You could use web services when your clients and servers are running on different networks and also different platforms. This provides a loosely coupled system. And also if the client is behind the firewall it would be easy to use web service since it runs on port 80 (by default) instead of having some thing else in Service Oriented Architecture applications.
What is the standard you use to wrap up a call to a Web service
"SOAP.

"
What is the transport protocol you use to call a Web service SOAP HTTP with SOAP
What does WSDL stand for? "WSDL stands for Web Services Dsescription Langauge. There is WSDL.exe that creates a .wsdl Files which defines how an XML Web service behaves and instructs clients as to how to interact with the service.
eg: wsdl http://LocalHost/WebServiceName.asmx"

Where on the Internet would you look for Web Services?www.uddi.org

What does WSDL stand for? Web Services Description Language

True or False: To test a Web service you must create a windows application or Web application to consume this service? False.

What are the various ways of accessing a web service ?
1.Asynchronous Call
  Application can make a call to the Webservice and then continue todo watever oit  wants to do.When the service is ready it will notify the application.Application  can use BEGIN and END method to make asynchronous call to the webmethod.We can use  either a WaitHandle or a Delegate object when making asynchronous call.
The WaitHandle class share resources between several objects. It provides several  methods which will wait for the resources to become available
The easiest and most powerful way to to implement an asynchronous call is using a  delegate object. A delegate object wraps up a callback function. The idea is to  pass a method in the invocation of the web method. When the webmethod has finished  it will call this callback function to process the result

2.Synchronous Call
Application has to wait until execution has completed.
 Note: Few of the references are taken from other sites/sources

What are VSDISCO files?VSDISCO files are DISCO files that support dynamic discovery of Web services. If you place the following VSDISCO file in a directory on your Web server, for example, it returns   references to all ASMX and DISCO files in the host directory and any subdirectories not noted in <EXCLUDE>elements:
                <DYNAMICDISCOVERY
                  xmlns="urn:schemas-dynamicdiscovery:disco.2000-03-17">
                  <EXCLUDE path="_vti_cnf" />
                  <EXCLUDE path="_vti_pvt" />
                  <EXCLUDE path="_vti_log" />
                  <EXCLUDE path="_vti_script" />
                  <EXCLUDE path="_vti_txt" />
                </DYNAMICDISCOVERY>

How does dynamic discovery work?ASP.NET maps the file name extension VSDISCO to an HTTP handler that scans the host  directory and subdirectories for ASMX and DISCO files and returns a dynamically generated DISCO document. A client who requests a VSDISCO file gets back what appears to be a static DISCO document.

Note that VSDISCO files are disabled in the release version of ASP.NET. You can reenable them by uncommenting the line   in the <HTTPHANDLERS>section of Machine.config that maps *.vsdisco to System.Web.Services.Discovery.DiscoveryRequestHandler and granting the ASPNET  user account permission to read the IIS metabase. However, Microsoft is actively discouraging the use of VSDISCO files because they could represent a threat to Web server security.

Is it possible to prevent a browser from caching an ASPX page?
Just call SetNoStore on the HttpCachePolicy object exposed through the Response object's Cache property, as demonstrated here:
        <%@ Page Language="C#" %>
       
         
            <%
              Response.Cache.SetNoStore ();
              Response.Write (DateTime.Now.ToLongTimeString ());
            %>
SetNoStore works by returning a Cache-Control: private, no-store header in the HTTP response. In this example, it prevents caching of a Web page that shows the current time.
What does AspCompat="true" mean and when should I use it?
AspCompat is an aid in migrating ASP pages to ASPX pages. It defaults to false but should be set to true in any ASPX file that creates apartment-threaded COM objects--that is, COM objects registered ThreadingModel=Apartment. That includes all COM objects written with  Visual Basic 6.0. AspCompat should also be set to true (regardless of threading  model)  if the page creates COM objects that access intrinsic ASP objects such as Request and Response. The following directive sets AspCompat to true:
 <%@ Page AspCompat="true" %>  
Setting AspCompat to true does two things. First, it makes intrinsic ASP objects available      to the COM components by placing unmanaged wrappers around the equivalent ASP.NET objects. Second, it improves the performance of calls that the page places to apartment- threaded COM objects by ensuring that the page (actually, the thread that processes the  request for the page) and the COM objects it creates share an apartment. AspCompat="true" forces ASP.NET request threads into single-threaded apartments (STAs). If those threads create COM objects marked ThreadingModel=Apartment, then the objects are created in the same STAs as the threads that created them. Without AspCompat="true," request threads run in a multithreaded apartment (MTA) and each call to an STA-based COM object incurs a performance hit when it's  marshaled across apartment boundaries.
Do not set AspCompat to true if your page uses no COM objects or if it uses COM objects that don't access ASP intrinsic objects and that are registered ThreadingModel=Free or  ThreadingModel=Both.

Can two different programming languages be mixed in a single ASMX file?
No. 

What namespaces are imported by default in ASMX files?
The following namespaces are imported by default. Other namespaces must be imported manually.· System, System.Collections,System.ComponentModel,System.Data, System.Diagnostics,System.Web,System.Web.Services 
How do I provide information to the Web Service when the information is required as a SOAP Header?
The key here is the Web Service proxy you created using wsdl.exe or through Visual Studio .NET's Add Web Reference menu option. If you happen to download a WSDL file for a Web Service that requires a SOAP header, .NET will create a SoapHeader class in the proxy source file. Using the previous example:
      public class Service1 : System.Web.Services.Protocols.SoapHttpClientProtocol
        {   
            public AuthToken AuthTokenValue;       
       
        [System.Xml.Serialization.XmlRootAttribute(Namespace="http://tempuri.org/", IsNullable=false)]       
            public class AuthToken : SoapHeader {        public string Token;    }}
In this case, when you create an instance of the proxy in your main application file, you'll also create an instance of the AuthToken class and assign the string:
     Service1 objSvc = new Service1();
     processingobjSvc.AuthTokenValue = new AuthToken();
     objSvc.AuthTokenValue.Token = <ACTUAL token value>;
     Web Servicestring strResult = objSvc.MyBillableWebMethod();

What is WSDL?
WSDL is the Web Service Description Language, and it is implemented as a specific XML vocabulary. While it's very much more complex than what can be described here, there are two important aspects to WSDL with which you should be aware. First, WSDL provides instructions to consumers of Web Services to describe the layout and contents of the SOAP packets  the Web Service intends to issue. It's an interface description document, of sorts. And second, it isn't intended that you  read and interpret the WSDL. Rather, WSDL should be processed by machine, typically to generate proxy source code (.NET) or create dynamic proxies on the fly (the SOAP Toolkit or Web Service Behavior). 

What is a Windows Service and how does its lifecycle differ from a "standard" EXE?
Windows service is a application that runs in the background. It is equivalent to a NT service.
The executable created is not a Windows application, and hence you can't just click and run it . it needs to be installed as a service, VB.Net has a facility where we can add an installer to our program and then use a utility to install the service. Where as this is not the case with standard exe

How can a win service developed in .NET be installed or used in Win98?
Windows service cannot be installed on Win9x machines even though the .NET framework runs on machine.

Can you debug a Windows Service? How ? 
Yes we can debug a Windows Service.
Attach the WinDbg debugger to a service after the service starts
This method is similar to the method that you can use to attach a debugger to a process and then debug a process.
Use the process ID of the process that hosts the service that you want to debug   
  1. To determine the process ID (PID) of the process that hosts the service that you want to debug, use one of the following methods.
    • Method 1: Use the Task Manager 
      1. Right-click the taskbar, and then click Task Manager. The Windows Task Manager dialog box appears.
      2. Click the Processes tab of the Windows Task Manager dialog box.
      3. Under Image Name, click the image name of the process that hosts the service that you want to debug. Note the process ID of this process as specified by the value of the corresponding PID field.
    • Method 2: Use the Task List Utility (tlist.exe)
      1. Click Start, and then click Run. The Run dialog box appears.
      2. In the Open box, type cmd, and then click OK.
      3. At the command prompt, change the directory path to reflect the location of the tlist.exe file on your computer.Note The tlist.exe file is typically located in the following directory: C:\Program Files\Debugging Tools for Windows
      4. At the command prompt, type tlist to list the image names and the process IDs of all processes that are currently running on your computer.
    Note Make a note of the process ID of the process that hosts the service that you want to debug.
  2. At a command prompt, change the directory path to reflect the location of the windbg.exe file on your computer.Note If a command prompt is not open, follow steps a and b of Method 1. The windbg.exe file is typically located in the following directory: C:\Program Files\Debugging Tools for Windows.
  3. At the command prompt, type windbg –p ProcessID to attach the WinDbg debugger to the process that hosts the service that you want to debug.
Note ProcessID is a placeholder for the process ID of the process that hosts the service that you want to debug.
Use the image name of the process that hosts the service that you want to debug

You can use this method only if there is exactly one running instance of the process that hosts the service that you want to run. To do this, follow these steps:   
  1. Click Start, and then click Run. The Run dialog box appears.  
  2. In the Open box, type cmd, and then click OK to open a command prompt.
  3. At the command prompt, change the directory path to reflect the location of the windbg.exe file on your computer.Note The windbg.exe file is typically located in the following directory: C:\Program Files\Debugging Tools for Windows.
  4. At the command prompt, type windbg –pn ImageName to attach the WinDbg debugger to the process that hosts the service that you want to debug.
NoteImageName is a placeholder for the image name of the process that hosts the service that you want to debug. The "-pn" command-line option specifies that the ImageName command-line argument is the image name of a process. back to the top
Start the WinDbg debugger and attach to the process that hosts the service that you want to debug
  1. Start Windows Explorer.  
  2. Locate the windbg.exe file on your computer.Note The windbg.exe file is typically located in the following directory: C:\Program Files\Debugging Tools for Windows
  3. Run the windbg.exe file to start the WinDbg debugger.
  4. On the File menu, click Attach to a Process to display the Attach to Process dialog box.
  5. Click to select the node that corresponds to the process that hosts the service that you want to debug, and then click OK.
  6. In the dialog box that appears, click Yes to save base workspace information. Notice that you can now debug the disassembled code of your service.
Configure a service to start with the WinDbg debugger attached
You can use this method to debug services if you want to troubleshoot service-startup-related problems.   
1 Configure the "Image File Execution" options. To do this, use one of the following methods:  
  • Method 1: Use the Global Flags Editor (gflags.exe)
    1. Start Windows Explorer.
    2. Locate the gflags.exe file on your computer.Note The gflags.exe file is typically located in the following directory: C:\Program Files\Debugging Tools for Windows.
    3. Run the gflags.exe file to start the Global Flags Editor.
    4. In the Image File Name text box, type the image name of the process that hosts the service that you want to debug. For example, if you want to debug a service that is hosted by a process that has MyService.exe as the image name, type MyService.exe.
    5. Under Destination, click to select the Image File Options option.
    6. Under Image Debugger Options, click to select the Debugger check box.
    7. In the Debugger text box, type the full path of the debugger that you want to use. For example, if you want to use the WinDbg debugger to debug a service, you can type a full path that is similar to the following: C:\Program Files\Debugging Tools for Windows\windbg.exe
        h. Click Apply, and then click OK to quit the Global Flags Editor.
  • Method 2: Use Registry Editor
    1. Click Start, and then click Run. The Run dialog box appears.
    2. In the Open box, type regedit, and then click OK to start Registry Editor.
    3. Warning If you use Registry Editor incorrectly, you may cause serious problems that may require you to reinstall your operating system. Microsoft cannot guarantee that you can solve problems that result from using Registry Editor incorrectly. Use Registry Editor at your own risk.In Registry Editor, locate, and then right-click the following registry subkey:
      HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options
    4. Point to New, and then click Key. In the left pane of Registry Editor, notice that New Key #1 (the name of a new registry subkey) is selected for editing.
    5. Type ImageName to replace New Key #1, and then press ENTER.Note ImageName is a placeholder for the image name of the process that hosts the service that you want to debug. For example, if you want to debug a service that is hosted by a process that has MyService.exe as the image name, type MyService.exe.
    6. Right-click the registry subkey that you created in step e.
    7. Point to New, and then click String Value. In the right pane of Registry Editor, notice that New Value #1, the name of a new registry entry, is selected for editing.
    8. Replace New Value #1 with Debugger, and then press ENTER.
    9. Right-click the Debugger registry entry that you created in step h, and then click Modify. The Edit String dialog box appears.
    10. In the Value data text box, type DebuggerPath, and then click OK.
    Note DebuggerPath is a placeholder for the full path of the debugger that you want to use. For example, if you want to use the WinDbg debugger to debug a service, you can type a full path that is similar to the following: C:\Program Files\Debugging Tools for Windows\windbg.exe
2 For the debugger window to appear on your desktop, and to interact with the debugger, make your service interactive. If you do not make your service interactive, the debugger will start but you cannot see it and you cannot issue commands. To make your service interactive, use one of the following methods:  
  • Method 1: Use the Services console
    1. Click Start, and then point to Programs.
    2. On the Programs menu, point to Administrative Tools, and then click Services. The Services console appears.
    3. In the right pane of the Services console, right-click ServiceName, and then click Properties.Note ServiceName is a placeholder for the name of the service that you want to debug.
    4. On the Log On tab, click to select the Allow service to interact with desktop check box under Local System account, and then click OK.
  • Method 2: Use Registry Editor
    1. In Registry Editor, locate, and then click the following registry subkey:HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\ServiceName
      Note Replace ServiceName with the name of the service that you want to debug. For example, if you want to debug a service named MyService, locate and then click the following registry key:
      HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MyService
    2. Under the Name field in the right pane of Registry Editor, right-click Type, and then click Modify. The Edit DWORD Value dialog box appears.
    3. Change the text in the Value data text box to the result of the binary OR operation with the binary value of the current text and the binary value, 0x00000100, as the two operands. The binary value, 0x00000100, corresponds to the SERVICE_INTERACTIVE_PROCESS constant that is defined in the WinNT.h header file on your computer. This constant specifies that a service is interactive in nature.
3 When a service starts, the service communicates to the Service Control Manager how long the service must have to start (the time-out period for the service). If the Service Control Manager does not receive a "service started" notice from the service within this time-out period, the Service Control Manager terminates the process that hosts the service. This time-out period is typically less than 30 seconds. If you do not adjust this time-out period, the Service Control Manager ends the process and the attached debugger while you are trying to debug. To adjust this time-out period, follow these steps:
  1. In Registry Editor, locate, and then right-click the following registry subkey: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control 
  2. Point to New, and then click DWORD Value. In the right pane of Registry Editor, notice that New Value #1 (the name of a new registry entry) is selected for editing.
  3. Type ServicesPipeTimeout to replace New Value #1, and then press ENTER.
  4. Right-click the ServicesPipeTimeout registry entry that you created in step c, and then click Modify. The Edit DWORD Value dialog box appears.
  5. In the Value data text box, type TimeoutPeriod, and then click OKNote TimeoutPeriod is a placeholder for the value of the time-out period (in milliseconds) that you want to set for the service. For example, if you want to set the time-out period to 24 hours (86400000 milliseconds), type 86400000.
  6. Restart the computer. You must restart the computer for Service Control Manager to apply this change.
4 Start your Windows service. To do this, follow these steps:
  1. Click Start, and then point to Programs.
  2. On the Programs menu, point to Administrative Tools, and then click Services. The Services console appears.
  3. In the right pane of the Services console, right-click ServiceName, and then click Start.
Note ServiceName is a placeholder for the name of the service that you want to debug. 
 Note: Few of the references are taken from other sites/sources
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=3631&lngWId=10

Share/Bookmark