Showing posts with label Visual Studio 2008. Show all posts
Showing posts with label Visual Studio 2008. Show all posts

Thursday, January 3, 2013

WCF Service Optimization: An interesting technique to split your *.svc.cs file to have more manageable WCF service

Introduction

WCF (Windows communication foundation) is the service layer foundation and the base of SOA in Microsoft dot net, what will happen when you have a huge WCF service consisting of 5000 operation contract. This is not unreal at all, if you design a service bus for a large intranet application, where 1000 employee using your application and doing day to day operation and your WCF service hits per second is about 2000. You can do so many thing to optimize it, first of all you can cluster the service and then apply load balance. So horizontal scaling is a solution.

Now if you are given a task to optimize the operation and each time you need to look at the service you have to find it in a large class where you have about 5000 operation contract. How developers will maintain this huge code base?

Fortunately we have few solutions to that problem

Today we are going to see 1st of many solution

split your *.svc.cs file

This does not help in optimization of the service rather managing the file and the codebase. First of all I would split the svc file in to several pieces. Each will contain in about 100 methods, still we would have 20 files for the svc file, its kind of sounds different but, would help managing 2000 methods, each file will contain domain specific methods for the service.

How we do it?

We will add class with almost same name as the service, for instance if we have a WCF service named “myservice.svc” then the code behind file is  “myservice.svc.cs”. Off Course its not necessary to have svc.cs file with the wcf service we can have only the declaration.

Below a code example is given,This is how a real world service which is out of refactoring and maintain for a while looks like.

image

Figure: Log Class of 2000 method

In above screenshot If you carefully look at the scrollbar of the method dropdown of the visual studio, you will have an idea how much its doing.

So now we need to optimize this in perspective of code management. As we already discussed the technique. we will split this in to several pieces, luckily we have a partial class concept in c#, so we would split this in to several pieces according to class responsibility domain.

Naming convention for the partial class. “myservice.[responsibilityDomain].svc.cs” that’s the filename of the class. In practical case I have named on of my partial class as “ReliantDataConnect.CandidateOffer.svc.cs” I have moved all the methods related to CandidateOffer in this file.

Now Lets say we have added another partial class file name “ReliantDataConnect.Resource.svc.cs” using the following wizard window.

image

Figure: Add a new class

And after moving the related methods in the partial class the partial class may look like below screen shot.

image

Now problem is the partial class will be visible in solution explorer as a isolated file rather part of the WCF Service. Below how it looks like after adding the file.

image

Now if we can add this file as a dependent file of the ReliantDataConnect.svc file this will save us form watching isolated file, and make a combined file. Here is how we do it.

Make a file dependent on another file in visual studio

First of all we have to open the project file in note pad or text pad or note pad ++ which ever you like. Then find the file name that we added “ReliantDataConnect.Resource.svc.cs”, finally add DependentUpon Child node and specify the file name in our case its “RelaintDataConnect.svc” Now saved the file. Close it. If visual studio is open it should already warn you that file is been modified outside and reload is necessary. Reload to proceed.

image

After reload you will see that the file is now part of svc file.

image

Cool right?. Well for now you can go and browse other blog, I will get busy with creating 20 more class file for this project. Until next time.

Masudur Rahman is out.

Thursday, January 7, 2010

Using the Build event of visual studio 2008

Background

Some times we need to execute some custom task just before we build our solution or project, I have no idea how others IDE do that, but recently we have gathered some experience about Visual Studio 2008, and doing these kind of task became pretty easy.

In one of our project we had to use a custom third-party component, the component is easy to incorporate in the project, but we have a problem, the component uses a d-com component which can not be added in the project, but if we keep the com component in bin directory the program runs okay. so our challenge is to copy the component before build in the bin directory of output project from the other projects bin.

Visual Studio 2008 Build Events

In Visual studio 2008 we have two build event, prebuilt event command and post build event command, post build event can be controlled with various parameters for example, post build event will raise when a successful build is happened.

image 

Figure: Visual Studio 2008 Build tab under Project properties

In our particular case we solved our problem in using pre-build event, now let us discuss a little bit more about pre-built event, you can use almost any kind of command in command line, provided that the commands don't require special permissions for executions.

In our case we have used "xcopy" command to solved the problem, there are lot of macro for execution. we used target directory as output macro, and source directory as solution macro, since its a simple problem we set the relative path of the DLL from solution path. worked okay, when we published the project we found that in publish version also contains the DLL, job done with very good time and in a good way.

Post build is almost similar like pre-build except it has some extra control, user can specify when to raise it, in the above screen shot you can see that there is a large combo at the bottom.

Here is a small example command in the for pre-build command.

If we want to copy all output files of a project to a deployment folder after post build event we have to put down the following command in the post build command line,

""xcopy "$(TargetDir)*.*" "c:\output" /S /I /F <NUL:""

Bellow i have put down a pre-build event command line input window with macro.

image

well that's all for now, please visit the references for more information, best of luck and happy coding.

 

References

  1. http://msdn.microsoft.com/en-us/library/42x5kfw4.aspx
  2. http://geekswithblogs.net/dchestnutt/archive/2006/05/30/80113.aspx
  3. http://dotnetperls.com/post-pre-build-macros
  4. http://skysanders.net/subtext/archive/2009/09/05/visual-studio-2008-build-event-xcopy-bug.aspx

Thursday, September 3, 2009

How to work in really local repository with svn.

Two things, First “I don’t want to install a source control repository”, second, “I want the source control in my local machine” finally “I want the facility to check in, check out and keep source history”, That’s actually three things, well what come in my mind is the Tortoise SVN facility.

Create A local repository

Here is how we can do the local repository, first install TortoiseSVN, its totally free so no need to worry about any licensing issue. After successful installation, select any folder from your file system, and right click on that repository. Now from TortoiseSVN menu select “Create repository here”.

image

It is going to take only a second to finish the process, Walla your local repository is created. And you will get a confirmation  like the bello window. After that you can choose to created default folder structure. Next step is to add a solution to this local repo.

image

Adding source in source control

Open your desired solution in your visual studio ide. right click on solution explorer solution file, and select Add solution to Source control. Since I have a VS plugin for svn I will get window like bello screen. It’s recommended that you add a visual studio svn plugin like Visual SVN or Ankh SVN in your development machine.

image

Click on to finish the process and you will get log message entry window.

image

Type your comment and then click ok, that’s it you have a local repository up and working for you.

Check in and checkout

Bellow I have provided the pending checking window screenshot, after adding the project you might want to add every thing un-committed to the source control.

image

History

Since you have your source control you can now check in and checkout any file, and also keep history and ability to revert the changes if anything goes wrong.

image

More over you can track history to find out any changes that is done in the source control.

image

Its fun and no worry to loose your code anymore. But I would recommend that you use a svn server, because your machine could crash, but server will have backup facility.

Until next time, me signing out cya.

Thursday, August 6, 2009

AnkhSVN : a free and full integrated SVN tool for VS IDE.

Subversion integration with VS IDE is one of the necessary things as far as Integrated development is concern. A lot of develop still do folder based file system Update, Merge and Commit while working with code based which has a source control in Subversion.

Nowadays, since the we all want the luxury of having everything accessible through visual studio ide, why not also svn. There are two important tool that come to my mind right way for svn integration.

  • Visual SVN

  • AnkhSVN

No doubt that Visual SVN is a wonderful tool that have full integrated feature with visual studio, but main problem with it is that its not free and a commercial tool. If we use express edition of visual studio and want svn integration we might not want to pay for it.

There AnkhSVN wins, its totally free, for distribution and use. The tool is can be download from http://ankhsvn.open.collab.net/. Ankh SVN is fully integrated and free tool for svn support in visual studio.

Features are given bellow and taken from the AnkhSVN Site.

Features

Pending Changes window

  • One window to handle the normal workflow.
  • Real-time overview of all project changes.
  • Easy access to most Subversion commands.

Merge Tracking

  • Easy-to-use wizard simplifies merging.
  • Wizard is merge-tracking aware.
  • Intuitive integrated conflict resolution
  • Supports all merge scenarios supported by Subversion 1.5/1.6
  • Works with Subversion 1.5+ servers, and pre-1.5 servers.

Optimized workflow

  • Don't leave your IDE for most common operations.
  • Immediately view the source control status of all files in your project/solution.
  • View working copy information such as last committed author, last committed date and the repository URL.
  • Import new solutions automatically.
  • Get support for all Subversion transfer protocols.

Pluggable diff/merge

  • Plug in your diff/merge tool of choice
  • Smart command line templates for the most common merge tools.

Repository Explorer

  • Easily browse any Subversion repository.
  • View extended information about remote files and directories in the Visual Studio Properties window.

License

  • AnkhSVN 2.1 is licensed under the open source Apache 2.0 license.

After installation we can use and when we add the our solution to source control the solution explorer is pretty much looks like the following screen shot.

image

Bellow the pending checking window for AnkhSVN is given.

image

Hope you will like this tool and use open source solution. Until next time cya.