Wednesday, 19 June 2013

Convert WSDL file to a C# class and then DLL

Today I was trying to update a web reference of custom web services in my project but because of some reason visual studio 2010 wasn't getting the latest methods I added even though I could see them using browser. Hence to get around problem I converted WSDL file into C# class and then into a dll.

You can target dll to any framework you would like. In order to get DLL in .Net 4.0 framework try following steps;

For getting you library dll in.Net 4.0 framework you will require Visual Studio 2010 tools installed on your machine, however for it in .Net 3.5 framework you will need Visual Studio 2008.

  1. Open Visual Studio Command prompt as a administrator by going to Start menu > All Programs > Microsoft Visual Studio 2010 > Visual Studio Tools > Visual Studio Command Prompt (2010).
  2. Put your WSDL file in somewhere accessible e.g. in this case I will put it in my C drive and getting output CS class in C drive too but you can change it. Type this command and press okay,

    C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC>wsdl /l:C# /out:C:\OutPutClassName.cs C:\myWebService.wsdl
  3. Above command will generate a CS class in your C drive, now if you want to convert this class into dll in .Net 4.0, type this command;

    C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC>csc /target:library /r:System.Data.dll /r:System.Data.Services.Client.dll /out:C:\OutPutClassName.dll C:\OutPutClassName.cs

    Above command will get you class library dll in .Net 4.0 framework.
  4. In order to get ..Net 3.5 use this command,

    C:\Program Files\Microsoft Visual Studio 9.0\VC>csc /target:library /r:System.Data.dll  /out:C:\OutPutClassName.dll C:\OutPutClassName.cs
MSDN Reference:

Wednesday, 5 June 2013

Right way of installing assembly into GAC in Windows Server 2012

In previous version's of Windows Server we were able to simply drag and drop assemblies into GAC folder which wasn't recommended at all, however being in a development environment (Windows Server 2012) when I tried to drag and drop a DLL into GAC, I received this error,

Now if you want to install assembly to GAC following steps,

  1. Assuming you are new to Windows Server 2012, Move your mouse pointer to right bottom of your screen just next to Date & Time.
  2. Click on "Search" tile.
  3. Now enter "cmd" in search text box.
  4. Most likely you will see two apps named as "Command Prompt" and "Visual Studio Command Promp...".
  5. If you will right click on "Visual Studio Command Promp.." it will give you few options at bottom of screen as show in picture below,

  6. Click on "Run as administrator" and press "Yes" for typical dialogue appears each time you try to start       a processes as administrator as security confirmation.
  7. Now type down this command,

    cd C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC
  8. Copy your assembly to folder directory,

    C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC
  9. Once assembly is copied you can use following syntax to install assembly to GAC,

    gacutil /i mySolution.myProject.dll
    an IIS reset will be produced as a result of above command so be careful as if you might break any on going process

That's it. Your assembly is installed, you can follow the procedure as many times as you want.

For more information please check this MSDN link out: