Friday, January 08, 2010

First WCF program on Windows Vista

I got a WCF Unleashed book and started going through it. As the book reading progressed, I started trying the examples explained in the book on my Vista laptop. Surprisingly I had to workaround many things to get things set right. None of the steps worked as is. Hence the blog post.
My laptop is running Vista SP2 Home Premium. This edition of Vista comes up with IIS 6.1, I think (It needs to be enabled using Windows Add Remove components).
The first example I was trying was to create a simple WCF service(1 operation defined in contract), host it in a simple Console host. I created a client using standard svcutil.exe tool. The client was supposed to access the WCF service using basicHttpBinding. Projects were ready everything looked simple till this point.
I ran the WCF service, and bummer, it threw an exception which said something like you don’t have access to the HTTP address. It was referring to the HTTP address which I had specified in the app.config for the WCF service host. Looked around and found that I need to use, netsh command to grant permission to listen on the ports. Many blog entries said this is a new security feature with Vista. With this I was able to run the service( using the console host ). With service running I was also able to connect using the Client and everything looked fine.
After this, I tried to deploy the service in IIS. Followed the instructions from the book, created a virtual directory pointed to the service ( this time just the contract) solution's output directory. Everything looked fine. Then I tried to access the URL from the browser and bummer IIS 500 error. It said something like, bad configuration data. I re-verified the web.config it looked all right. Again, back to Google searching for this , I came across some blogs which said we need to first register WCF before one can use the WCF service. This looked strange to me in first place then it kind of made sense. To install WCF I used ServiceModelReg.exe -I. This looked something similar to the ASP.Net registration utility for IIS.
Once WCF is installed I had to install ASP.Net as well. It would have been great if it would have been pre installed in IIS Emoticon1.
Also I needed to grant Read permission to IIS_IUSRS and IUSR built in users on the physical directory.
I was kind of relieved at this point, and was all geared up to test it. Here I try and get another error , crap.
This time the error said,
The type , provided as the Service attribute value in the ServiceHost directive could not be found.

I had hard time getting around this. I finally went to Fusion Log Viewer to check which assembly bindings are failing. This tool showed, the loader is looking for the assembly where the type is defined in the \bin directory. The assembly was in the same location where the Service.svc file was located. Also the virtual directory I created was pointing to the \bin directory for the service Visual Studio project. So I ended up creating a new directory bin inside bin directory and copied the assembly there.
After all this it worked finally hoo hoo Emoticon1[1]
Thanks
Prasad

Thursday, December 17, 2009

A malaware attack..

Recently my laptop(Vista SP2) came under a malaware attack. I got redirected from one site to page which was resembling a progressing virus scan in the Windows Explorer. I closed this page, but it somehow managed to download few things on my machine. One of them was a kind of  security tool, indicating something wrong on my machine in the task bar. It was running an executable named like some big number. It was running off c:\program data folder. I killed the executable and got rid of that folder . After this was done, Norton virus scan dialog box came up. It was essentially asking me to buy Norton. I don't have, never had Norton on my machine. It looks, what ever got installed on my machine installed Norton as well ( I was surprised with this). I uninstalled Norton. I thought everything is gone and I am good.

Next day when I started browsing, I noticed clicking any link on any website was taking me to some advertising sites. I was shocked with this.At this point I went to famous No Script for Firefox. It showed me there is a host which is doing all this. That host was google-analystiks.us. I didn't notice this at the first glance as it is very similar to the Google Analytics. I think this was introduced by the malaware.

I have McAffee installed on my machine. I ran a scan and it didn't help. After that I came across a tool called MalawareBytes. A quick scan of this tool found the malaware and quarantined it. This tool looked very efficient. It completed a quick scan of the PC in about 8-10 minutes and found the malaware.

Information about this tool can be found here http://download.cnet.com/Malwarebytes-Anti-Malware/3000-8022_4-10804572.html

Since then the sytem is looking good, I haven't experienced automatic redirects to advertising sites. Hope fully its recovered husssssh.

I always use NoScript with Firefox, I uninstalled it for few days because of some issue and ran into this. I got NoScript back again and hopefully don't have to uninstall it again.

Thanks
Prasad Pimparkar

Thursday, December 03, 2009

Project Creation Failed in VS2008

Recently I ran in to an error while creating a project in Visual Studio 2008 which said "Project creation <project name> failed".

I spent couple of hours figuring out what's wrong. Here are the options which I came across. I will start with the one that worked for me.

1) Run following command to start visual studio

devenv /resetskippkgs

What I noticed in my case was, few days back I got an error in VS2008, which said its skipping some packages because of some issues.

2) This is another option which I came across. Follow following steps.

Another option which I came across is as follows.
  1. Run following command.regsvr32 C:\[Visual Studio installation dir]\Common7\IDE\VsWizard.dll
  2. After running this command, open registry editor and assign appropriate permissions to HKLM\SOFTWARE\Classes\VSWizard.VsWizardEngine.9.0 key. (though I did not find any issues with this key). Restart Visual Studio.

3) Following is last which I came across for this purpose. This looked to be related to the Beta release of Visual Studio.
  1. Navigate to: C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE in Windows Explorer
  2. Load devenv.exe.config in your favorite text editor.
  3. Find this string: "Microsoft.VisualStudio.TemplateWizardInterface"
  4. Comment out the element
These are various options I could see for this issue. If anybody knows any other solutions for this, please comment.

Monday, February 04, 2008

XSLT

XSLT is used to convert XML documents from one format to other.
It can also be used to convert XML document to other formats like HTML commonly called as XHTML and also text documents.
These text documents can be anything example C# programs . :)

Following is the URL for the W3C schools XSLT tutorial.
http://www.w3schools.com/xsl/default.asp.

This is an introducyory tutorial which introduces to the XSLT.

Thanks

Sunday, February 03, 2008

XPath in a nutshell

XPath expressions are used to navigate in the XML document. XSLT uses XPath

.Net supports XPath queries through classes like XPathDocument, XPathNavigator and XPathIterator.

XPath expressions and their meaning.
Following are the expressions which can be used for entire document search. This is an absolute search not relevant to the current node in the XML document.

Expression

Description

Nodename

Selects all child nodes of the named node

/

Selects from the root node

//

Selects nodes in the document from the current node that match the selection no matter where they are

.

Selects the current node

..

Selects the parent of the current node

@

Selects attributes

*

Matches any element node

@*

Matches any attribute node

node()

Matches any node of any kind



Following are the XPath axes expressions which can be used to search the XML document hierarchically. This search is relative to the current node in the XML document as it sounds from there names. When we are traversing the document we can use these expressions to get the required elements.

XPath Axes

Description

ancestor

Selects all ancestors (parent, grandparent, etc.) of the current node

ancestor-or-self

Selects all ancestors (parent, grandparent, etc.) of the current node and the current node itself

attribute

Selects all attributes of the current node

child

Selects all children of the current node

descendant

Selects all descendants (children, grandchildren, etc.) of the current node

descendant-or-self

Selects all descendants (children, grandchildren, etc.) of the current node and the current node itself

following

Selects everything in the document after the closing tag of the current node

following-sibling

Selects all siblings after the current node

namespace

Selects all namespace nodes of the current node

parent

Selects the parent of the current node

preceding

Selects everything in the document that is before the start tag of the current node

preceding-sibling

Selects all siblings before the current node

self

Selects the current node




Following is the detailed XPath document from W3C Schools.
http://www.w3schools.com/xpath/xpath_intro.asp

Thanks
Prasad

Sunday, December 16, 2007

Expression Trees

Hi

C# 3.0 introduced Lambda Expressions.
These are one of the building blocks of the LINQ.
Expression is a syntactic feature. uses the anonymous methods and the delegates (generic delegates).
It is a simplified syntax over using the generic delegates.

The general form of a Lambda Expression is

parms => function body

Consider following example.

p => ++p;

This Lambda Expression translates to

Func <<int,int>> incr = delegate (int p)
{
return ++p;
}

One good thing about these Lambda expressions is that one can tell compiler to generate an expression tree for a Lambda expression instead of a IL method ( in above example the Func delegate tells the compiler to generate the IL method).

Above expression can be rewritten as follows

Expression<<<<Func<<int,int>>>> exprIncr =
delegate (int p)
{
return ++p;
}

or

Expression<<<<Func<<int,int>>>> exprIncr = p=> ++p;

both code snippets above are same.

Expression trees are nothing but a binary tree which represents an expression. ( something like a tree for an arithmetic expression like a+b).

Following article goes in depth for expression trees.
http://courseweb.sp.cs.cmu.edu/~cs200/lecture18/lecture18.html.

Following post gives an overview of Lambda expressions and there genesis starting from .Net 1.0 delegates.

http://www.interact-sw.co.uk/iangblog/2005/09/30/expressiontrees


Thanks

LINQ to SQL

Hi

One of the cool features of C# 3.0 is the LINQ.
This technology has the capability of changing the way tiered applications are written.

This is a great article from Microsoft this topic.
http://msdn2.microsoft.com/en-us/library/bb425822.aspx

Thanks

Saturday, December 15, 2007

Object Initializers in C# 3.0

Hi

C# 3.0 introduced something called as object initializers.

Consider following class

class Person
{
public int Age;
public string Name;
.....
}

One can instantiate this class as

Person firstPerson = new Person();
firstPerson.Age =10;
firstPerson.Name = "Bal";

We can also use the parametrized constructors for initializing attributes of a class.

With C# 3.0 we can create the Person object as

Person secondPerson = new Person{ Age = 10, Name ="Bandu" };

This is not same as creating the object and setting its values.

The expression is evaluated right to left and hence a temporary object is created which is finally assigned to the secondPerson.

One good thing about this expression is this is an atomic expression.
Means we don't have to specify any lock kind of construct when using this in multi threaded programs.


Thanks