Reusing code in OnLoad and OnChange event handlers

Somtimes we need to execute the same set of twice once in OnLoad and in OnChange which calls for maintaining two set of codes or copying the same code for other. Again if there is some change in the first one we need to change the second one also.

Here is a simple implementation to avoid it. We will make use of the HTML DOM and include a function it, this function lives until the window is open accessable form all over the form.



var Hello = Function(){
alert("Say hello");
};


// now you can use somthng like this
window.Greet = Hello;

//or

window.Greet = function(){ alert("say hello"); };


To use it you can call this function from any location, like

// calling the function
window.Greet();

Entity PrimaryKey using Metadata Service

Sometimes we need to get the Entity ID for the any custom entity, by default the entityid equals to +"id". So we can get the id for any dynamic entity as

Entity.Properties["entitylogicalname"+"id"];
But this is a snippet for achieving the same using metadata service.


// Get the Primary key from CRM Entity
public string GetEntityPrimaryKey(String EntityName)
{
// Metadata Service
Func myMetaService = () =>
{
// Create an authentication token.
CrmAuthenticationToken token = new CrmAuthenticationToken();
token.OrganizationName = "OrgName";
token.AuthenticationType = 0;

// Create the metadata Web service;
MetadataService metadataService = new MetadataService();
metadataService.Url = "http://:/MSCRMServices/2007/MetadataService.asmx";
metadataService.CrmAuthenticationTokenValue = token;
metadataService.Credentials = System.Net.CredentialCache.DefaultCredentials;
metadataService.PreAuthenticate = true;
return metadataService;
};

// Create the request
RetrieveEntityRequest entityRequest = new RetrieveEntityRequest();
entityRequest.RetrieveAsIfPublished = false;
entityRequest.LogicalName = EntityName;
entityRequest.EntityItems = EntityItems.EntityOnly;

// Execute the request
RetrieveEntityResponse entityResponse = (RetrieveEntityResponse)myMetaService().Execute(entityRequest);

// Access the retrieved entity
EntityMetadata retrievedEntityMetadata = entityResponse.EntityMetadata;
return retrievedEntityMetadata.PrimaryKey;
}

.Net Framework Interview Questions

1. What is mean by .Net Framework?

The .NET framework is a collection of all the tools and utilities required to execute the .NET managed applications on a particular platform.

 

2. What is mean by CLR?

Common Language Runtime is the core component of .Net framework. It is similar to the Java Virtual Machine or JVM in Java, which handles the execution of code and provides useful services for the implementation of the program. It provides a number of services, including the following

  • management (loading and execution)
  • Application memory isolation
  • Verification of type safety
  • Conversion of IL to native code
  • Access to metadata (enhanced type information)
  • Managing memory for managed objects
  • Enforcement of code access security
  • Exception handling, including cross-language exceptions
  • Interoperation between managed code, COM objects, and pre-existing DLLs (unmanaged code and data)
  • Automation of object layout
  • Support for developer services (profiling, debugging, and so on)

 

3. What is difference between managed and unmanaged code?

The managed code is always executed by a managed runtime execution environment like CLR for .Net. Metadata information of the code will be exchanged with runtime, so runtime environment can guarantee what the code is going to do and provide the necessary security checks before executing any piece of code

Code that is directly executed by the Operating System is known as un-managed code. Example applications written in VB 6.0, C++, C, etc are unmanaged code that typically targets the processor architecture and is always dependent on the computer architecture. In unmanaged code the memory allocation, type safety, security, etc needs to be taken care of by the developer.

 

4. What is mean by MSIL?

MSIL or IL stands for Microsoft Intermediate Language; if you compile managed code, the compiler translates your source code into Microsoft intermediate language. MSIL is platform independent language which can be converted to native code while installing software or at runtime by using Just-in compiler.

 

5. What is mean by CTS?

Common type system defines how types are declared, used, and managed in the runtime, and is also an important part of the runtime's support for cross-language integration. CTS is responsible for defining types that can be used across the .Net Languages. CTS Provides the data types, values, object types. This helps developers to develop applications in different languages.

For example, an integer variable in C# is written as int, whereas in VB.Net it is written as integer. Therefore in .Net Framework you have single class called System.Int32 to interpret these variables.

 

6. What is mean by CLS?

Common Language Specification is the subset of CTS; it is specification that defines the set rules and guidelines that all supporting language should follow. It integrate in such a way that programs written in any language can interoperate with one another.

 

7. What is mean by JIT?

Just In Time(JIT) compilers which compile the IL code to native executable code (.exe or .dll) for the specific machine and OS. JIT are slightly different from traditional compilers as they compile the IL to native code only when desired e.g., when a function is called, IL of function's body is converted to native code; just in time of need. If same function is called next time, the CLR uses the same copy of native code without re-compiling. As JIT are aware of processor and OS exactly at runtime, they can optimize the code extremely efficiently resulting in very robust applications.

 

8. What are different types of JIT?

Pre-JIT - Pre-JIT compiles complete source code into native code in a single compilation cycle. This is done at the time of deployment of the application.

Econo-JIT - Econo-JIT compiles only those functions that are called at runtime. However, these compiled functions are removed when they are not required.

Normal-JIT - Normal-JIT compiles only those functions that are called at runtime and they are stored in cache. If same function is called next time, the CLR uses the same copy of compiled code without re-compiling.

 

9. What is mean by Assembly?

  • Assemblies are self-describing installation units, consisting of one or more files.
  • Assemblies are the deployment units of .Net applications. .Net application consists of one or more assemblies.
  • An assembly may also contain references to other assemblies and it include metadata that describes all the types that are defined in the assembly with information about it members-methods, properties, events and fields.
  • One assembly could be a single Dll or exe that includes metadata, or it can be made of different files e.g resource files, modules and an exe.
  • Assembly manifests is a part of the metadata, it describes the assembly with all the information that's needed to reference it and lists all its dependencies.

 

10. What are the features of Assembly?

  • Assemblies are self-describing, it includes metadata that describes the assembly. It does not required to register key as like COM component.
  • Version dependencies are recorded inside an assembly manifest. The version of the referenced assembly that will be used can be configured by the developer and the system administrator.
  • Two different version of same assembly can be used inside single process.

 

11. What are different type's assemblies?

Private assembly- Private assembly is used within your application and it is installed at the same time as the application itself. It will be located in the same directory as the application or subdirectories thereof.

Shared assembly- Shared assemblies are used by several application. Shared assembly must have version number and unique name and it is usually installed in GAC (Global assembly catch). It reduces the need for disk space and memory space.

 

12. What are parts of assembly manifests?

  • Identity - Name, version, culture and public key
  • A list of files - Files belonging to the assembly, it can have one or more files.
  • Lists of referenced assemblies - all assemblies referenced by the assembly are documented inside the manifest.
  • Set of permission requests- these are the permission needed to run the assembly.
  • Exported types - It describes the structures, class with properties, method and events. It is used to create instance of the class.

 

13. What is mean by Namespace?

Namespace Logically group classes, it avoids name clashes between classes.

Example : most of the general purpose .net base classes are in a namespace called System. The base class Array is in this namespace is accessed with full name System.Array.

14. What is difference between Assembly and Namespace?
  • Assembly is physical grouping of classes. Namespace logically groups classes.
  • Single assembly can have different namespaces
  • Sample namespace can be used in different assembly. E.g the assembly mscorlib and system contain the namespace System.Threading

 

15. What is the difference between an executable assembly and a class library?

An executable assembly exists as the .exe file while a class library exists as the .dll file. Executable assembly represent executable applications having some entry (e.g., Main() method in C#). A class library, on the other hand, contains components and libraries to be used inside various applications. A Class library cannot be executed and thus it does not have any entry point.

 

16. What is ILDASM?

ILDASM(Intermediate Language DisAssembler ), this is inbuild tool to view content and manifest of the assembly. We can run the ILDASM by running following exe "C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools\ildasm.exe"

 

17. What is mean by Manifest?

Manifest is used to describe the information about the assembly, it contains following information.

  • Assembly name - Aids in versioning and visibility scope.
  • Version information - The version number is integrated into the assembly's identity.
  • Types - Boundaries and scopes of methods, classes, properties, events and attributes.
  • Locale - Information describing language/culture.
  • Reference - provides information for type references in an assembly and other referenced assemblies.
  • Cryptographic Hash - Public key encoded hash acting as version/security check.
  • Security Permissions - The permissions within the assembly determine the permissions that can be granted for all aspects of the assembly contents.

 

18. How will you created shared assembly?

Shared assembly can be created by signing the assembly. Sets to created shared assembly

  • Create new class library project using visual studio
  • Navigate to the property page of the class library
  • Select "Signing" tab
  • Select "Sign the assembly" check-box
  • Now select < New >... from "Choose a strong name key file" dropdown
  • Enter new Signing key file name and click Ok
  • Next the build the project. Now the shared assembly is ready to use in different project.

 

19. What is the use of Shared Assembly?

If you want to use the same assembly in different projects, we can create a shared assembly and placed inside the GAC(Global assembly Catch). So that assembly is access by all the application. Private assembly also be used in different projects, but we need to copy the private assembly files to different application folder. But if we are using Shared assembly, the assembly file remains in single location.

Shared assembly is highly secured, only administrator can uninstall the shared assembly.

20. What is GAC?

GAC(Global assembly catch) is used to store .Net assembly. It is located in "C:\Windows\assembly"

  • Assembly located in GAC is shared by multiple applications
  • Adding an Assembly to GAC

    "gacutil -i (assembly_name)", where (assembly_name) is the DLL name of the project.

 

21. What is mean by Delay signing?

During development process, usually private key will not be exposed to the developer due to security reason. In this kind of scenario, we will go with delay signing.Delay signing allows you to place a shared assembly in the GAC by signing the assembly with just the public key. This allows the assembly to be signed with the private key at a later stage, when the development process is complete and the component or assembly is ready to be deployed. This process enables developers to work with shared assemblies as if they were strongly named, and it secures the private key of the signature from being accessed at different stages of development.

E.g

VB.Net(Assemblyinfo.vb)

< Assembly: AssemblyKeyFileAttribute("myKey.snk") > 

< Assembly: AssemblyDelaySignAttribute(True) >

C#(Assemblyinfo.cs)

[assembly: AssemblyKeyFileAttribute("myKey.snk")]
[assembly: AssemblyDelaySignAttribute(true)]
 



      22. What is mean by Satellite assembly?


      When we write a multilingual or multi-cultural application in .NET, and want to distribute the core application separately from the localized modules, the localized assemblies that modify the core application are called satellite assemblies.

       

      23. What is portable executable (PE)?


      The file format defining the structure that all executable files (EXE) and Dynamic Link Libraries (DLL) must use to allow them to be loaded and executed by Windows. PE is derived from the Microsoft Common Object File Format (COFF). The EXE and DLL files created using the .NET Framework obey the PE/COFF formats and also add additional header and data sections to the files that are only used by the CLR.

       

      24. What is mean by Garbage collection?


      Garbage collection is a CLR features used to automatically manages memory. CLR automatically release the objects which are not longer used or referenced. Developer who forget to release the dispose the objects will be cleared by GC. But it is not known when GC will be called by CLR to clean the memory. So better we can dispose the objects once it is used.

       

      25. What are the different levels of GC is available?


      Generation 0 , Generation 1, Generation 2

       

      26. How Garbage collector will get memory from OS?


      When execution engine starts, GC will initialize segment of memory for its operation. GC reserves memory in segment, each segment is 16MB. When we run out of segments we reserve a new segment. If a segment of memory is not in use, it will be deleted.

       

      27. What is mean by LOH?


      LOH-(Large Object Heap). If size of the object are very high(>64KB) then it will be stored in different segment of memory called as LOH. GC will treat the large objects differently from small objects.

       

      28. What are situations GC will be called?



      1. If user forcefully calls System.GC.Collect
      2. System is in low memory situation
      3. Memory allocation exceeds the Generation0 threshold

       


      29. What is mean by value type and Reference type?


      Value type- Value type stores their value directly to memory address. Value type's values are allocated on the stack memory.

      Reference type - Reference type stores the reference to the value's memory address. Reference type values are allocated on head memory.

       

      30. What is mean by Boxing and Unboxing?


      Boxing - Converting value type variable to reference type is called as boxing

      UnBoxing - Converting reference type variable to value type is called as unboxing

                  int vType = 35;
      object rType;
      //Boxing process
      rType = vType;
      //Unboxing process
      vType =(int) rType;


      31. How will you decide when to use value type and reference type?


      All depends upon need.

       

      32. What is difference between System exception and Application exception?


      All exceptions are derived from the Exception base class. Where Exception class is derived from the Object class. Both System and Application exception are derived from exception class but it has difference between them. System exceptions are thrown by the CLR where as Application exceptions are thrown by Application.

      System Exception
      Application Exception

      System exceptions are thrown by CLR
      Application exceptions are thrown by Application

      E.g OutOfMemoryException, NullReferenceException,etc
      E.g User defined exception are created to throw application's exception and user defined exceptions are derived from ApplicationException


       


      33. What is Reflection?


      .Net compilers store metadata information(types defined) about the assemblies inside the assembly itself. Using this metadata we can load an assembly dynamically (at runtime), get information about its containing types, instantiate these types and call methods.

      "Reflection" is a mechanism using which we can load an assembly dynamically and call its method. The System.Reflection is the root namespace that contains classes to implement the reflection. The Assembly class is the one which is used to represent the assembly in .Net environment.

      Example:

      static void Main(string[] args)
      {
      // Load an assembly from file
      Assembly myAssembly = Assembly.LoadFrom("MyService.dll");
      // Get the types contained in the assembly and print their names
      Type[] types = myAssembly.GetTypes();
      foreach (Type type in types)
      {
      Console.WriteLine(type.FullName);
      //Get the members(methods) present inside each type
      foreach (MemberInfo member in type.GetMembers())
      {
      Console.WriteLine(" "+member.Name);
      }
      }
      Console.ReadLine();
      }

      OutPut:


       


      34. How will you decompile your assembly?


      Any assembly can be disassembled using ILDASM(Intermediate Language Disassembler), it is ships with the .Net framework SDK. Using third party tools like Reflector or Anakrino can also be easily decompile the assemblies.

       

      35. What is mean by Obfuscation?


      Obfuscation is a technique used to mangle symbols and rearrange code blocks to foil decompiling. Dotfuscator, is a popular obfuscation package ships with Visual Studio.

       

      36. If we have two different version of same assembly in GAC how do we make a choice?


      Let us consider the scenario where one of the applications uses the dll which is available in GAC. Now we are creating the second version of the same dll and placed inside the GAC. So GAC contains both version of the assembly, since application referring the dll from GAC, definitely it will take latest version of the dll. But we need old version of the assembly to be executed. How to achieve this requirement?

      Answer: using < bindingRedirect > tag in App.config file

      Example:

      Step 1: Create sample library class with MyVersion() method. This method will return current version of the assembly.

      namespace AssemblyVersionExample
      {
      public class Class1
      {

      public string MyVersion()
      {
      return "The old version: 1.0.0.10";
      }
      }
      }

      Step 2:Modify the "AssemblyVersion" attribute with the old version say ‘"1.0.0.10"

      // You can specify all the values or you can default the Build and Revision Numbers 
      // by using the '*' as shown below:
      // [assembly: AssemblyVersion("1.0.*")]
      [assembly: AssemblyVersion("1.0.0.10")]
      [assembly: AssemblyFileVersion("1.0.0.10")]

      Step 3:Compile the dll and register to assembly using "gacutil"

      Step 4:Create a public token key using following command [ sn -T "filepath"]. Now the public key for the assembly is created.


      Step 5:Repeat the step 2,3 with different version for same assembly

      	
      public string MyVersion()
      {
      return "The new version: 1.0.0.20";
      }

      // by using the '*' as shown below:
      // [assembly: AssemblyVersion("1.0.*")]
      [assembly: AssemblyVersion("1.0.0.20")]


      Step6: Now let's start creating the application, which refer the AssemblyVersionExample.dll Create a instance of the class and invoke the method. Output of the assembly will be new version.

      static void Main(string[] args)
      {
      AssemblyVersionExample.Class1 objClass = new AssemblyVersionExample.Class1();
      Console.WriteLine(objClass.MyVersion());
      Console.ReadLine();
      }

      Step 7: Since we need to use the old version of the assembly from GAC, we should make use of "bindingRedirect" tag in the application. In the below sample, you can find that new attribute is set with old version value (newVersion="1.0.0.10") and attribute is set with new version value (oldVersion="1.0.0.20"). When we execute the application, resultant output will be from old version of the dll.

      <configuration>

      <runtime>

      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

      <dependentAssembly>

      <assemblyIdentity name="AssemblyVersionExample"

      publicKeyToken="7c779e284ebe2e8c"

      culture="neutral" />

      <bindingRedirect oldVersion="1.0.0.20"

      newVersion="1.0.0.10"/>

      </dependentAssembly>

      </assemblyBinding>

      </runtime>

      </configuration>

      Output:


       

      37. What is mean by Dll Hell?


      DLL hell means deploying the same DLL in your application multiple times. In windows application dlls are shared across multiple application. Suppose when App1 is using MyAssembly.dll and it is working fine. Suppose I am installing new application App2 which also having assembly MyAssembly.dll, while installing App2 it will override the old assembly with new MyAssembly.dll. Now only App2 will function properly where as App1 which depends on MyAssembly.dll will fail. This is called as Dll hell. It can be solved by assembly versioning.

       

      38. How's the DLL Hell problem solved in .NET?


      Assembly versioning allows the application to specify not only the library it needs to run (which was available under Win32), but also the version of the assembly.

       

      39. What's the difference between the System.Array.CopyTo() and System.Array.Clone()?



      • System.Array.CopyTo() - Performs a deep copy of the array
      • System.Array.Clone()- Performs a shallow copy of the array

       


      40. What is difference between application running in Debug and Release mode?


      In a debug build mode the complete symbolic debug information is added to complile assembly to help while debugging applications and also the code optimization is not taken into account. While in release build the symbolic debug infrmation is not added to the compiled assembly and the code execution is optimized. Since debuging information is not added in a release build, the size of the final executable is lesser than a debug executable.

       

      41. What is the difference between traditional development and .NET development?


      In traditional programming languages, the source code of a program is compiled to a specific platform's assembly language and then machine language code. Later the library code required by the program is linked to it. Finally the operating system executes the program when desired by the user

      In the presence of dot net framework, a program is not compiled to the native machine executable code; rather it gets compiled to an intermediate language code called Microsoft Intermediate Language (MSIL) or Common Intermediate Language (CIL). The Dot Net Common Language Runtime (CLR) then converts this intermediate code at runtime to the machine executable code. The optimization is carried out at runtime

       

      41. How true it is that .NET and Java programs are quite in-efficient when compared to C++?


      In .Net and Java programming, initial execution of the program will be little bit slower than the C++ programming. Because .Net and Java involves the hosting of CLR into managed applcaiotn process in .Net and starting the JVM in a new process in case of Java. Since, the CLR and JVM optimizes the code more efficiently than the static C++ compilers, the execution speed of the program may actually be faster after sometime of the program startup when most of the code is translated. Hence, in the longer run, the .Net and Java based programs should not be in-efficient when compared to C++.

       

      42. How Finaliz() method will work in .net?


      .Net framework provides ahte Object.Finalize() method to clean up objects unmanaged resources. In general garbage collector keeps track of objects that have Finalize methods, using an internal structure called the finalization queue. Each time your application creates an object that has a Finalize method, the garbage collector places an entry in the finalization queue that points to that object. The finalization queue contains entries for all the objects in the managed heap that need to have their finalization code called before the garbage collector can free their memory.

      Finalize methods requires at least two garbage collections to free the resources. When the garbage collector performs a collection, it reclaims the memory for inaccessible objects without finalizers. At this time, it cannot collect the inaccessible objects that do have finalizers. Instead, it removes the entries for these objects from the finalization queue and places them in a list of objects marked as ready for finalization. Entries in this list point to the objects in the managed heap that are ready to have their finalization code called. The garbage collector calls the Finalize methods for the objects in this list and then removes the entries from the list. A future garbage collection will determine that the finalized objects are truly garbage because they are no longer pointed to by entries in the list of objects marked as ready for finalization. In this future garbage collection, the objects' memory is actually reclaimed.

      Logging JScript Errors to windows event log

      Writing Jscript for Dynamics CRM is a tough task, there were no errors is the data is in proper format, but somtimes i wish to log all those information & exception in some place to review/analyse. But since Jscript is not meant for this. Still there is something that you can do with Windows Event Logger. Here is a small script that uses activeXObject to write the log to eventviewer. Later you can view the log by running "eventvwer" in the cmd prompt.

      Here is the script



      // Creates a log object
      Log.prototype = {
      // adds functions to it
      Err:function(Error){
      var WshShell = new ActiveXObject("WScript.shell");
      WshShell.LogEvent(1,Error);
      },
      Success:function(Message){
      var WshShell = new ActiveXObject("WScript.shell");
      WshShell.LogEvent(0,Message);
      },
      Warn:function(Warning){
      var WshShell = new ActiveXObject("WScript.shell");
      WshShell.LogEvent(2,Message);
      },
      Info:function(Information){
      var WshShell = new ActiveXObject("WScript.shell");
      WshShell.LogEvent(4,Information);
      },
      AuditSuccess:function(Message){
      var WshShell = new ActiveXObject("WScript.shell");
      WshShell.LogEvent(8,Message);
      },
      AuditFailure:function(Message){
      var WshShell = new ActiveXObject("WScript.shell");
      WshShell.LogEvent(16,Message);
      }
      }

      // Calling the log to write error
      Log.Err("error in script");

      Formatting international phone numbers

      The CRM SDK contains a sample to format US phone numbers and it works pretty well. However, there are customers outside the US and the sample doesn't work with international phone numbers. An easy formatting rule is replacing any occurrence of '(', ')' or a space with a dash. People can then enter the phone number in their preferred way, but get the same output.


      var originalPhoneNumber = "+49 (89) 12345678";
      var formattedPhoneNumber = originalPhoneNumber.replace(/[^0-9,+]/g, "-");
      formattedPhoneNumber = formattedPhoneNumber.replace(/-+/g, "-");
      alert(formattedPhoneNumber);


      The first call to the replace method changes every character in the input string that is not a digit and not the plus sign (which is used for international
      numbers) to the dash symbol. However, the output is +49--89--12345678, so the second call replaces all occurrences of multiple dashes with a single
      one, giving a final result of +49-89-12345678.

      Retrieving all fields inside a CRM form

      If you want to loop over all fields (input fields) on a CRM form, you can use the following script



      //CRM 4 Jscript



      for (var index in crmForm.all) {
      var control = crmForm.all[index];

      if (control.req && (control.Disabled != null)) {
      //control is a CRM form field
      }
      }


      The conditions mean that a control must have the "req" attribute and the "Disabled" method. This seems a good indicator for a CRM form field.

      Complete Installation guide for CRM 4.0

      Complete Installation guide for CRM 4.0 / Step by Step guide to install CRM 4.0

              Last week I installed Microsoft Dynamic 4.0 on my virtual machine and I found that it will be helpful for beginner like me, if there is a step by step installation guide. Lets start with OS selection.

      1. You can use Windows Server 2003 or later server version. I had Windows Server 2003 R2.

      2. Install latest service pack for OS you installed.

      3. Install Internet Information Service.

      4. Install Active Directory.

      5. Configure DNS Server.

      6. Create new user for domain and make him member of Administrators group.

      7. Install SQL Server 2005 with Reporting Service and Analysis service.

      8. Configure new account as service account for Report Server and Analysis server.

      9. Install Visual Studio 2008.

      10. Start installation of CRM 4.0

      11. Enter display name for your Organization.

      clip_image001

      12. Next step is to select installation path, you can leave this as it is or select specific folder,

      clip_image002

      13. Next select website for CRM, I choose new website with different port address in my case it was 5555 as shown in image below,

      clip_image003

      14. Next you need to enter URL for Reporting server.

      15. Next you have to select Organization Unit. Click on Browse button and select the root node of your domain in my case it is chirag.

      clip_image004

      16. On next step you need to specify security account, choose the one you created in step 6. Enter the password in password textbox and click next.

      17. Select your local machine as Email Router setting or select specific machine on domain which you are using at email server. I chose my local machine so localhost.

      18. Once you click next you will see System Requirements screen. If Domain user, SQL Server Reporting Service and ASP.NET are installed properly you will receive no error or warning else you will receive error message. I received following errors,

      clip_image005

      19. If you receive error message for SQL Server or SQL Server Reporting Service don’t be afraid. Open Services from Start – All Programs – Administrative Tools – Services. Check whether SQL Server Agent is running. If not right click on service and select property. Select Startup Type as Automatic and click on start button.

      20. Another common error is for Indexing service. Follow the steps mention in point 19 to start Indexing Service.

      21. You can see a warning mentioning Verify Domain User account SPN for the Microsoft Dynamics CRM ASP.NET Application Pool account. This will usually shows when you add specific domain account for security account in step 16.

      22. If System Requirements screen show no error or warning on next step installation will be started.

      23. Finally you will see following screen, this means your CRM is installed.

      clip_image006

      Removing a navigation bar entry at runtime

      To remove a navigation bar entry dynamically, you can use the following code:

      var navigationBarEntry = document.getElementById("navProds");

      if (navigationBarEntry != null) {
      var lbArea = navigationBarEntry.parentNode;
      if (lbArea != null) {
      lbArea.removeChild(navigationBarEntry);
      }
      }

      If you haven't already done it, download and install the Internet Explorer Developer Toolbar to find the name of the navigation bar entry.

      Retrieving the current user information

      The new solution uses the Microsoft CRM web services to retrieve the user id, business unit id, organization id and the first, last and full name of the currently logged on user. I have attached a simple test form with the following OnLoad event:


      var xml = "" +
      "" +
      "" +
      GenerateAuthenticationHeader() +
      " " +
      " " +
      " " +
      " systemuser" +
      " " +
      " " +
      " businessunitid" +
      " firstname" +
      " fullname" +
      " lastname" +
      " organizationid" +
      " systemuserid" +
      "
      " +
      "
      " +
      " false" +
      " " +
      " And" +
      " " +
      " " +
      " systemuserid" +
      " EqualUserId" +
      "
      " +
      "
      " +
      "
      " +
      "
      " +
      "
      " +
      "
      " +
      "
      " +
      "";

      var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");

      xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
      xmlHttpRequest.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple");
      xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
      xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
      xmlHttpRequest.send(xml);

      var resultXml = xmlHttpRequest.responseXML;
      var entityNode = resultXml.selectSingleNode("//RetrieveMultipleResult/BusinessEntities/BusinessEntity");

      var firstNameNode = entityNode.selectSingleNode("q1:firstname");
      var lastNameNode = entityNode.selectSingleNode("q1:lastname");
      var fullNameNode = entityNode.selectSingleNode("q1:fullname");
      var systemUserIdNode = entityNode.selectSingleNode("q1:systemuserid");
      var businessUnitIdNode = entityNode.selectSingleNode("q1:businessunitid");
      var organizationIdNode = entityNode.selectSingleNode("q1:organizationid");

      crmForm.all.sw_firstname.DataValue = (firstNameNode == null) ? null : firstNameNode.text;
      crmForm.all.sw_lastname.DataValue = (lastNameNode == null) ? null : lastNameNode.text;
      crmForm.all.sw_name.DataValue = (fullNameNode == null) ? null : fullNameNode.text;
      crmForm.all.sw_systemuserid.DataValue = (systemUserIdNode == null) ? null : systemUserIdNode.text;
      crmForm.all.sw_businessunitid.DataValue = (businessUnitIdNode == null) ? null : businessUnitIdNode.text;
      crmForm.all.sw_organizationid.DataValue = (organizationIdNode == null) ? null : organizationIdNode.text;

      Web Service Interview Questions

      1. What is Web service?

      Web Services are applications that provide services on the internet. Web services allow for programmatic access of business logic over the Web. Web services typically rely on XML-based protocols, messages, and interface descriptions for communication and access. SOAP over HTTP is the most commonly used protocol for invoking Web services. SOAP defines a standardized format in XML which can be exchanged between two entities over standard protocols such as HTTP.

      Example: Google search engine's web service, e.g., allows other applications to delegate the task of searching over the internet to Google web service and use the result produced by it in their own applications.

      2. What is UDDI?

      UDDI - Universal Description, Discovery and Integration. It is an XML-based standard for describing, publishing, and finding Web services. It is platform independent, open framework and specification for a distributed registry of Web services

      3. 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.

      4. What is the use of Disco.exe?

      The Web Services Discovery tool discovers the URLs of XML Web services located on a Web server and saves documents related to each XML Web service on a local disk.

      5. What are the uses of Web service?
      • Application integration Web services within an intranet are commonly used to integrate business applications running on different platforms.

        For example, a .NET client running on Windows 2000 can easily invoke a Java Web service running on a mainframe or Unix machine to retrieve data from a legacy application.

      • Business integration Web services allow trading partners to engage in e-business allowing them to leverage the existing Internet infrastructure. Organizations can send electronic purchase orders to suppliers and receive electronic invoices. Doing e-business with Web services means a low barrier to entry because Web services can be added to existing applications running on any platform without changing legacy code.
      • Commercial Web services focus on selling content and business services to clients over the Internet similar to familiar Web pages. Unlike Web pages, commercial Web services target applications as their direct users.
      6. What is WSDL?

      The Web Services Description Language (WSDL) is a particular form of an XML Schema, developed by Microsoft and IBM for the purpose of defining the XML message, operation, and protocol mapping of a web service accessed using SOAP or other XML protocol.

      WSDL describes the 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
      7. How to create a web service?

      This sample explains about the creation of sample web service and consuming it.

      Step 1: Create a new web service by clicking File->New->WebSite and select "ASP.Net Web Service"

      Step 2:

      Create a class and methods which is need to be exposed as service. Decorate the class with "WebService" and methods with "WebMethod" attribute.

      [WebService(Namespace = "http://tempuri.org/")]
      [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
      // To allow this Web Service to be called from script,
      //using ASP.NET AJAX, uncomment the following line.
      // [System.Web.Script.Services.ScriptService]

      public class Service : System.Web.Services.WebService
      {
      public Service () {

      //Uncomment the following line if using designed components
      //InitializeComponent();
      }

      [WebMethod]
      public string HelloWorld() {
      return "Hello World";
      }

      [WebMethod ]
      public string SayHello(string name) {
      return "Hello " + name;
      }

      }


      Step 3:

      Run the web service


      Step 4: Create the client application to consume the service by clicking File->New->Project and select the Console Application.

      Step 5: Right click the project file and select "Add Service Reference"


      Step 6:

      Create a new instance for proxy class and call the web method "SayHello"

      class Program
      {
      static void Main(string[] args)
      {
      ServiceReference1.ServiceSoapClient proxy = new
      ServiceReference1.ServiceSoapClient();
      Console.WriteLine(proxy.SayHello("Ram"));
      Console.ReadLine();
      }
      }


      Step 7:

      Output window are shown


      8. What is difference between Add Reference and Add Service reference?

      Add Reference is used to add the .Net assemblies and COM components to the project files, where as Add Service Reference is used to create a proxy for the web service.

      9. What is the transport protocol you use to call a Web service?

      SOAP (Simple Object Access Protocol) is the preferred protocol.

      10. Where on the Internet would you look for Web services?

      http://www.uddi.org

      11. To test a Web Service you must create a windows application or web application to consume this service? It is True/False?

      Every web service by default generates a test page, we need not create or consume the Web service in order to test it.

      12. When would you use .NET Remoting and when Web services?

      When both service and client are .Net platform, .Net remoting will be more efficient where are if both server and client are different platform use web service for communication

      13. A Web service can only be written in .NET True or False?

      False

      14. How to implement security to the web service?

      WS-Security (Web Services Security) is a communications protocol providing a means for applying security to Web services.

      The protocol contains specifications on how integrity and confidentiality can be enforced on Web services messaging. The WSS protocol includes details on the use of SAML and Kerberos, and certificate formats such as X.509

      WS-Security describes how to attach signatures and encryption headers to SOAP messages. In addition, it describes how to attach security tokens, including binary security tokens such as X.509 certificates and Kerberos tickets, to messages.

      WS-Security incorporates security features in the header of a SOAP message, working in the application layer. Thus it ensures end-to-end security.