How to Debug Windows Service

Hi Folks, Sorry for being invisible for a long time. But i got really tied up with my bits. Anyways itโ€™s good if i be more busy then i will get more stuff to write ๐Ÿ™‚

First of All Happy Diwali And Happy new year to all of you! I hope this year you face so many challenges which makes you strong in your field!

Challenge

If anyone of you worked developing Windows Services in Visual Studio then one thing you must be wondering too do Debug โ€“ which makes programming easier. Itโ€™s not as easy as putting breakpoint and do debug like console,windows or web. It is an art to debug windows service.

Solution

To Debug windows service you can use Debugger.Break() method — Signals a breakpoint to an attached debugger.

So here are the steps to debug any piece of code in windows service:

1. Call Debugger.Break() Method before the line you want to put Debug point.

2. Now on the point which you want to get called put breakpoint. Means next line to your Debugger.Break() Line.

3. Now start your windows service. Whenever your piece of code executed. You will see Visual Studio Just-In Time Debugger Window. Choose VS instance and here you go!

Have a Happy Debugging!

Webliography

http://dotnettipoftheday.org/tips/how-to-debug-windows-service-startup.aspx — Another Blog

http://stackoverflow.com/questions/761120/how-to-debug-a-windows-service-using-breakpoints — Same Challenge

Get up to 25 percent off select Microsoft Certification exams


Howdy! I just logged in today in to my MCP portal and found one great thing that MS is giving special discount on Certification exams..Yippee!!!
They have kept three slots : 15%,20% and 25%
All TS Level exams comes under 15% and 20% slot – TS Level means Technology Specialist exams. For example 70-536 comes under TS Level.
All PRO Level exams comes under 25%ย  slot – PRO Level means Professional level exams. For example 70-547 comes under PRO Level[Hoorah!! currently i am preparing for this exam :)]
Best thing in this offer is that : This Offer is Good until December 31, 2009 or while supplies last.
So, if you take it positively then you got a reason to give exam before December and which will boost you to start preparation for the exam ๐Ÿ™‚
So, to get your voucher code follow the steps as given below:
1. Go to this URL :
http://www.prometric.com/microsoft/careeroffer.htm
2. From the given table locate your exam code. for example 547 or 536
3. Right side of that column click on “Get Voucher” Link.
4. Fill the form. Please provide the valid e-mail ID. Because your voucher will be mailed to you.
5.Now keep this Voucher code with you and when you go to your local prometric center. Just provide that Voucher Code and you might need to provide the same e-mail id. Which you provided in last step.
6. Take your exam.
7. If you passed the examย  then plan the party for your friends by using the discounted amount ๐Ÿ™‚
Pls note that it is valid by 31 Dec. 2009.
Good luck on your exam!

Showing Default Date and Visible Date with Calendar control

Challenge:

if you are using Calendar control to show Birthday of your friend. So, when you run the application it will show whose b’day is coming in this month or next month or next month …. So, you can be ready for a treat ๐Ÿ™‚ . The Challenge here is how to select that particular date and how to make it visible while user runs the application?

Solution:

You can set SelectedDate of Calendar Control to show date selected like this:
DateTime dtBirthday = getUpcomingBirthday(); //assume this method returns upcoming b’day in DateTime
calBirthday.SelectedDate = dtBirthday.Date; //use Date here else it won’t work
You can set VisibleDate of Calendar Control to show that date:
calBirthday.VisibleDate= dtBirthday.Date; //use Date here else it won’t work
Here DateTime.Date part it too important. Else it won’t work. Do you know why? i know but it’s homework for you guys ๐Ÿ™‚
Cheers

Programmatically Posting Data to ASP .NET Web Applications

Usually what we do. We open a page and fill up a form and submit a form data by pressing “Submit” Button. And after that we get some data/responseย  as per the logic.ย  But how to do this programmatically?? — That’s what we have been doing since so long..we faced too many challenges and finally we made it working. You also want to do the same then here we go…
First follow this nice article :
http://dotnet.sys-con.com/node/45127
if you follow all the steps and also COPY-PASTE the whole code given below:
http://gemsres.com/photos/story/res/45127/source.html
IT WON’T WORK
As someone has already commented on that post — That it throws Internal Server Error(500). But unfortunately no solution has been answered. But don’t worry. i’m here to answer that ๐Ÿ™‚
Okay, The problem is in your target ASPX page — Means ASPX Page which has form tag. it should have event validation false:

<%@ Page EnableEventValidation=”false” %>

That’s it. It should work now. And if it dosen’t works then try to debug using Fiddler — Really great tool
Okay, So in short to post form data programmatic ally using ASP.NET following steps are required.
1. ViewState Must be passed.
2. In Target page — enableeventvalidation – false.
3. Fiddler must need to install to see what’s going on ๐Ÿ™‚
Webliography
http://xneuron.wordpress.com/2007/12/05/programmatically-post-a-form-in-aspnet/
http://schleichermann.wordpress.com/2009/07/13/asp-net-programmatically-submit-form-post/
Hope this helps ๐Ÿ™‚

There is no script engine for file extension “.vbs”

Challenge:

If you received an error saying There is no script engine for file extension โ€œ.vbsโ€ then you are on right post ๐Ÿ™‚

Solution:

I tried doing this : regsvr32 %systemroot%\system32\vbscript.dll

http://www.technologystory.net/2009/02/25/windows-vista-tips-there-is-no-script-engine-for-file-extension-vbs/

But like you — for me too no luck ๐Ÿ™

But finally following trick worked for me ๐Ÿ™‚

1. Locate the file %windir%\inf\wsh.inf (inf is a hidden
folder)

2.right click and select “Install”.

Happy Coding!!

svn: Can’t create tunnel: The system cannot find the path specified.

We are using CruiseControl.NET for continuous integration. I must say really great tool!

We have configured a server where CruiseControl runs and our repository is on Tortoise SVN and it uses SVN+SSH. When we start our “ccnet.exe” it was giving us error like this “svn: Can’t create tunnel: The system cannot find the path specified.”

We really got confused as the message says the system can’t find the file specified But which file?? ๐Ÿ™

After struggling a lot we found the solution..Here it is:

SVN_SSH Environment Variable value was like this[Won’t Work]:

C:\Program Files\Putty\bin\plink.exe

It should be like this [Will work]:

C:\\Program Files\\Putty\\bin\\plink.exe

OR

C:/Program Files/Putty/bin/plink.exe

That’s it!!

If you are new and don’t know how to access Environment Variables see this:http://www.pushok.com/help/svnscc/index.php?redirect=adv_svnssh.htm

HTH

"Writing a code is a one kind of prayer for me"

using Table control

Challenge:

How I generate <tbody> tag using Table, TableRow, etc … controls ?

I want to generate table o/p like this:

<table border="1">
  <thead>
    <tr>
      <th>Month</th>
      <th>Savings</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>January</td>
      <td>$100</td>
    </tr>
    <tr>
      <td>February</td>
      <td>$80</td>
    </tr>
  </tbody>
  <tfoot>
    <tr>
      <td>Sum</td>
      <td>$180</td>
    </tr>
  </tfoot>
</table>

Src : http://www.w3schools.com/TAGS/tag_tbody.asp

I want to create table like this from my code

behind using .net f/w classes.

Solution:

TableRow.TableSection is the solution for it:

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.tablerow.tablesection.aspx

for whatever row you create just provide itโ€™s TableSetion property to appropriate section e.g Body,head etc.

Hope this helps

Happy Programming!!

IE innerHTML – “Unknown runtime error”

Setting value of <div id=”divhtml”> using js like this :

document.getElementById(“divhtml”).innerHTML = “<form><input type=”text”>…</form>”;

it was giving me error..

Solution:

oldDiv = document.getElementById(divhtml);
newDiv = document.createElement(oldDiv.tagName);
newDiv.id = oldDiv.id;
newDiv.className = oldDiv.className;
newDiv.innerHTML = “<form><input type=”text”>…</form>”;

oldDiv.parentNode.replaceChild(newDiv, oldDiv);

And it worked like a charm!!!!!!

Link : http://piecesofrakesh.blogspot.com/2007/02/ies-unknown-runtime-error-when-using.html

There was an error while trying to serialize parameter http://tempuri.org/:obj. The InnerException message was ‘Type ‘System.Collections.Generic.List`1[Employee, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]’ with data contract name ‘ArrayOfEmployee:http://schemas.datacontract.org/2004/07/Interfaces’ is not expected. Add any types not known statically to the list of known types – for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.

Hi if you are getting your hands dirty with WCF and got your mind blown up with the error as shown above or shown in Screen i have medicine of it..so go ahead!!!!

image

I am creating one simple serviceoperation which should take argument as an object but i will pass instance of my generic list which can be like List<Employee> or List<Person> and all this….because in service implementation i will do further operation based on type….I have created one application like this:

IService.cs

image

Service.CS

image

Employee.CS

image

Client.CS

image

Now when i run this application it gives me error of KnownTypeAttribute and serialization

Cause:

Actually root cause of problem is that we have defined object as our datacontract but when we pass List<Employee> or List<Person> it dosen’t knows what to serialize and send from wire…..hoohh…….simple if i have told you to say HI and it i will sat Bye…you can’t understand what i mean to say…so i need to help you in understanding Bye…Simple!!!!!so let us tell CLR that hey what to do if i pass List<Employee> or any type which i want to pass..

Solution:

Open your service contract IService.cs

and after [ServiceContract] Add [ServiceKnownType(typeof(List<Employee>))] or [ServiceKnownType(typeof(List<Person>))]….and Run the application…modified IService.cs looks like this:

image

Hope it helped you…Wants to say..Thanks say it to

Sowmy Srinivasan’s for nice and in-depth article:http://blogs.msdn.com/sowmy/

Question:

I am just wondering suppose if i have 50 Types which i want to pass then i need to declare all this on top of IService….just searching some alternative for it..if i found will let you know and hoping for the same….