Sunday, March 20, 2011

How to disable CIFS/SMB port 445 on Windows 7 64 bit

So, I had a requirement of disabling the port 445 on a Win 7 64 bit machine. The first thing which we do is to 'google' to find out a solution and I did the same. I found some results and they looked convincing. I tried the first method which was something like:
  • Open registry editor
  • Go to 'HKLM\System\CurrentControlSet\ Services\NetBT\Parameters' key
  • Go to option called TransportBindName (on the right hand side)
  • Empty the value so that Data (value) of 'TransportBindName' is empty. Close Registry Editor.
  • Reboot the PC
  • And you are done
Aah, it was so simple I thought and followed the procedure. To my irritation, this didn't work. no problem, there was another method on some other website:
  • As again, this requires opening the registry editor
  • Go to 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\NetBT\Parameters' key
  • Create a 'REG_DWORD' Entry with the name SMBDeviceEnabled and give it's value 0
  • Close Registry Editor
  • Reboot the PC
Waah, it also seemed simple. I followed the procedures and waited till the PC rebooted. And again to my greater irritation, it didn't work.

I went on googling and almost experimented all the things I found - none of them worked for me. It took almost one full day :(

Then I started experimenting on my own, and luckily to my great satisfaction, I found it. Here is what worked for me:

  • Open Services by typing services.msc in Run dialog box.
  • Locate the service named 'Server'. The description field for this should be saying something like 'Supports file, print, and named-pipe sharing over the network for this computer. If this service is stopped, these functions will be unavailable. If this service is disabled, any services that explicitly depend on it will fail to start. '
  • Double click on that service
  • Click on the button 'Stop' to stop it.
  • In the Startup Type combo choose 'Disabled' so that on the next boot, this service will not start running. Apply your changes by clicking on Ok.
  • Now locate another service named 'TCP/IP NetBIOS Helper'. The description should read something like 'Enables support for NetBIOS over TCP/IP (NetBT) service and NetBIOS name resolution.'.
  • Do the same with this service - stop it and disable it.
  • Restart the computer
There can be slight variation in names/description as while writing this blog post, I was on a XP machine.

Disclaimer: By reading the descriptions of the services you disabled, you should have a hint that your file sharing and other things will not work on the next reboot.

You can always go to Services again and set the services as 'Automatic' to enable them on the next reboot.

if it also works for you, kindly come back and leave a note of appreciation.

Tuesday, February 9, 2010

Search HTML Files in Alfresco: Search only WYSIWYG text, and not HTML tags, style declrations, etc.

By default, If we add any HTML file to Alfresco, it treats it as a text file and indexes everything. That means, all tags, content inside tags, style declarations, etc get indexed.
For example, If the content of HTML file is:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<div>
<table class="AlternateCyanColorGrid" cellspacing="0px" width="100%">
<col style="width: 33.333%;" />
<col style="width: 33.333%;" />
<col style="width: 33.333%;" />
<tr class="t1Row">
<td>heading1</td>
<td>chkheading</td>
<td>newest</td>
</tr>
<tr class="t2Row">
<td>search</td>
<td>results</td>
<td>logged</td>
</tr>
<tr class="t1Row">
<td>cruel</td>
<td>verify</td>
<td>broom</td>
</tr>
</table>
</body>
</html>

Now, if we search for table, body, style, etc, the file will be included in search results.
Sometimes, requirements may be to search for WYSIWYG text of Html files only, and not the extra meta stuff.

What we need to do, is to provide Alfresco, the WYSIWYG text of HTML files, and not the raw text. Alfresco provides transformers for this purpose. We will use a transformer which is present in Alfresco.

To achieve our purpose, create a custom extension file custom-content-services-context.xml in extension folder [For Alfresco deployed inside JBoss, the extension folder is server\\conf\alfresco\extension, for standalone Alfresco, it is tomcat\webapps\alfresco\WEB-INF\classes\alfresco\extension] with the following content:

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
<beans>
<bean id="transformer.HtmlParser"
class="org.alfresco.repo.content.transform.HtmlParserContentTransformer"
parent="baseContentTransformer" >
<property name="explicitTransformations">
<list>
<bean class="org.alfresco.repo.content.transform.ExplictTransformationDetails" >
<property name="sourceMimetype"><value>text/html</value></property>
<property name="targetMimetype"><value>text/plain</value></property>
</bean>
</list>
</property>
</bean>
</beans>

Now, if you add the same Html file, terms like body, table etc should not get indexed.

Thursday, January 28, 2010

Alfresco is taking too much memory : Memory Leak

I was hit hard by a probable memory leak in Alfresco. This post is about how I found the issue and got the solution. Sometimes we need to go extra mile to achieve the much desired success.

I was working on a wrapper above Alfresco 3.1 Stable Edition. We wrote a plug-in (webscript) for Alfresco. Ours is a J2EE App which talks to Alfresco using this plug-in. Our app and Alfresco war both are deployed in JBoss 4.2. I had been hit by a High Memory usage, which possibly could be a memory leak/issue in Alfresco.

Our app extends the folder type to include some (~20) additional meta props. ‘file’ (content) type has also been extended to include ~20 meta properties.

So, we have defined our custom folder and files.

My System Configuration was:
64 bit JVM 1.6 running on Windows Server 2008 R2, core 2 machine with 6 GB of physical RAM. SQL Server 2008 is the DB. I was using JMeter to talk to our app, which eventually talks to our Alfresco plug-in using webscripts. As recommended by Alfresco, I had provided 2GB of Heap to Alfresco.

In the following discussion, memory will mean old gen memory only.

I attached JConsole to the JVM running JBoss. Initial memory consumption was 160m. I added 1000 custom folders and a single xml file in each folder. Files differ (content and name wise) by some strings only and are very small (0.6 KB). Memory consumption started to increase, went up to 1.5 Gb and settled down at around 500m. Settled down means I did GC manually quite a times using JConsole. I added 1000 more folders and similar 1 file in each folder and the memory settled at 800mb. Added the same amount of data more, and it settled at 1GB. More same data and it settled at 1.16 GB. As I have told earlier, all files added so far differ by some strings (content and name wise) only.

I took the heap dump and analyzed with ‘jhat’ (show instance of all classes excluding platform). There were so many objects of different classes, but what took my attention was many objects of classes related to Lucene Indexing. Should they be there? Objects of classes lucene.index.FieldInfo, lucene.index.Term , luene.index.TermInfo , lucene.index.TermBuffer, lucene.store.RAMFile, lucene.store.RAMDirectory,lucene.index.CompoundFileReader$CSIndexInput, lucene.store.RAMInputStream, etc . Count for some of these instances reaching up to 200000. Is Lucene eating up the memory? Other user as also reported similar problem: http://forums.alfresco.com/en/viewtopic.php?f=9&t=18791&p=61675&hilit=leak#p61675. Wiki has a page for similar problem: http://wiki.alfresco.com/wiki/Lucene_Extensions_and_Issues but there is no update on it (whether the issues has been fixed in 3.1). I have scanned my app's code thoroughly and can assume that there is no memory leak from there. Issue seems to be on Alfresco side.

I again conducted my test case. This time I added around 3000 folders and one file in each folder. JVM started with around 200m of memory, and after I was done adding content, it settled at 1050m. ‘jhat’ heap dump (instance count of all classes excluding platform) showed more than 1000000 (1 million) objects from Lucene only, here is the breakup :

277571 instances of class org.apache.lucene.index.FieldInfo
237693 instances of class org.apache.lucene.index.CompoundFileReader$CSIndexInput
174082 instances of class org.apache.lucene.index.SegmentReader$Norm
102453 instances of class org.apache.lucene.index.TermBuffer
77363 instances of class org.apache.lucene.index.Term
55351 instances of class org.apache.lucene.index.TermInfo
42776 instances of class org.apache.lucene.index.CompoundFileReader$FileEntry
35981 instances of class org.apache.lucene.index.SegmentTermEnum
15373 instances of class org.apache.lucene.store.RAMFile
9813 instances of class org.alfresco.repo.search.impl.lucene.index.ReferenceCountingReadOnlyIndexReaderFactory$ReferenceCountingReadOnlyIndexReader$MultipleValueFieldAccessor
9102 instances of class org.apache.lucene.index.FieldsReader$FieldForMerge
6542 instances of class org.alfresco.repo.search.impl.lucene.index.ReferenceCountingReadOnlyIndexReaderFactory$ReferenceCountingReadOnlyIndexReader$SingleValueFieldAccessor
5828 instances of class org.apache.lucene.store.RAMInputStream
5789 instances of class org.apache.lucene.index.FieldInfos
5380 instances of class org.apache.lucene.index.SegmentInfo
5376 instances of class org.apache.lucene.index.FieldsReader
5376 instances of class org.apache.lucene.index.SegmentReader
5376 instances of class org.apache.lucene.index.TermInfosReader
5375 instances of class org.apache.lucene.index.CompoundFileReader
5359 instances of class [Lorg.apache.lucene.index.Term;
5359 instances of class [Lorg.apache.lucene.index.TermInfo;
3698 instances of class org.apache.lucene.store.RAMDirectory
3698 instances of class org.apache.lucene.store.SingleInstanceLockFactory
3610 instances of class org.apache.lucene.index.SegmentInfos
3271 instances of class org.alfresco.repo.search.impl.lucene.index.ReferenceCountingReadOnlyIndexReaderFactory$ReferenceCountingReadOnlyIndexReader
3271 instances of class org.alfresco.repo.search.impl.lucene.index.ReferenceCountingReadOnlyIndexReaderFactory$ReferenceCountingReadOnlyIndexReader$ListFieldAccessor
3089 instances of class org.apache.lucene.store.FSDirectory
2529 instances of class [Lorg.apache.lucene.index.IndexReader;
2528 instances of class org.apache.lucene.index.MultiReader
2356 instances of class org.apache.lucene.util.BitVector
2132 instances of class org.apache.lucene.document.Field
691 instances of class org.apache.lucene.document.Document
...........

I was even not sure whether it is leak or just that the memory consumption is high. If it is not a leak, then the old gen memory should stabilize somewhere. I kept on adding the folders and files and memory usage went on increasing till the point where the JVM seized to respond, as it was only busy doing FULL GC only, old gen max being full. I didn't know even then whether it is leak, as I did not test it with 4GB or 8 GB of heap memory assigned to JVM (as I did not have the resources for that too). So, for me, for 2 GB heap, it was a leak.

The next step which I did was an experiment. I fresh installed Alfresco on a separate machine, and wrote a Java program to add 100 (normal) folders and 1000 (normal) files in each folder, thus total of 100000 files (1/10th of a million) to be added that to on a JVM on which I allocated only 1 GB of RAM. I did not deploy my app on that JVM. Again, each file was an xml file, and two files contents differ by a guid only. The Java program used Webservice interface to call the Alfresco APIs for adding files and folders. When I started the JVM, the old gen memory was 90 MB. I ran the program and it successfully completed. The old gen memory reached up to 600m but it settled at 240m. What did it mean???? It meant to me that something is wrong, what it is - I did not know and I had no clue at all. Alfresco seems to be definitely working fine, as I was able to add 100000 files easily, and in my app case for 4000 files, it was taking up too much memory. The difference between the two cases were a> in my app case, I was also creating one folder per file b> in my app case, I was communicating to Alfresco using plug-in (webscript), and in the experiment scenario, I was using WebService c> in my app case, I was doing everything in transaction (inside our plug-in, each request was catered inside transaction) d> in my app case, we have additional metadata, and aspects for files and folders.

I analyzed the dump of experimental JVM and I found the instance count of Lucene objects as below:


4279 instances of class org.apache.lucene.index.Term
4171 instances of class org.apache.lucene.index.TermInfo
1723 instances of class org.apache.lucene.index.FieldInfo
533 instances of class org.apache.lucene.index.CompoundFileReader$CSIndexInput
373 instances of class org.apache.lucene.index.TermBuffer
302 instances of class org.apache.lucene.index.SegmentReader$Norm
234 instances of class org.apache.lucene.store.RAMFile
85 instances of class org.apache.lucene.store.RAMDirectory
63 instances of class org.apache.lucene.index.FieldInfos
...........

Don't know, why is this difference, but one thing was sure to me : it is something related to indexing/Lucene

I now used netBeans profiler. It took me much time to get it work with my JVM.
Here is the initial snapshot:












This time I added just 10 custom folders and files. netBeans showed that after the folders and files have been added, some amount of memory was retained (after doing GC for some times ). Much of this retained memory was attributed to byte[].
Here is how, it looked like:



I looked the stack trace of byte[]:



So, it looked like to me that mergeIndexes() should be investigated further. This was inside Alfresco. I opened the source code of Alfresco and traversed (statically) the stack chain upwards till buildReferenceCountingIndexReader function. Inside the function, what was causing new RAMDirectory to be created was the check size > config.getMaxDocsForInMemoryMerge() to return false, that is getMaxDocsForInMemoryMerge should be returning higher value. I searched for "maxDocsForInMemoryMerge" string in the Alfresco source code, and actually found a variable of the same name which was default initialized to 10000. Now i wanted to set it to some small value (around 100) but I did not find any documentation in Lucene Configuration section (http://wiki.alfresco.com/wiki/Full-Text_Search_Configuration), so I thought to build the class with initializer setting it to 100 rather than 10000. My source code was not getting built, there were many errors. I just thought of googling the string "maxDocsForInMemoryMerge" and I actually found what I was looking for : http://issues.alfresco.com/jira/browse/ETHREEOH-1147
There is a memory issue in Alfresco and the link gives the workaround.

So here is the workaround:

For default Alfresco installation add lucene.indexer.maxDocsForInMemoryMerge=0 in the file tomcat/webapps/alfresco/WEB-INF/classes/alfresco/repository.properties. For JBoss installation, add the string to conf/alfresco/extension/repository.properties file.

Also create a file named custom-lucene-indexer-context.xml in the same directory as above with the following content:


<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>

<!-- Core and miscellaneous bean definitions -->
<beans>
<bean id="admLuceneIndexerAndSearcherFactory"
class="org.alfresco.repo.search.impl.lucene.ADMLuceneIndexerAndSearcherFactory">
<property name="nodeService">
<ref bean="mlAwareNodeService" />
</property>
<property name="tenantService">
<ref bean="tenantService"/>
</property>
<property name="dictionaryService">
<ref bean="dictionaryService" />
</property>
<property name="nameSpaceService">
<ref bean="namespaceService" />
</property>
<property name="indexRootLocation">
<value>${dir.indexes}</value>
</property>
<property name="contentService">
<ref bean="contentService" />
</property>
<property name="queryRegister">
<ref bean="queryRegisterComponent" />
</property>
<property name="maxAtomicTransformationTime">
<value>${lucene.maxAtomicTransformationTime}</value> <!-- milliseconds allowed for inline text transformation -->
</property>
<property name="queryMaxClauses">
<value>${lucene.query.maxClauses}</value>
</property>
<property name="indexerBatchSize">
<value>${lucene.indexer.batchSize}</value>
</property>
<property name="lockDirectory">
<value>${dir.indexes.lock}</value>
</property>
<property name="indexerMaxFieldLength">
<value>${lucene.indexer.maxFieldLength}</value>
</property>
<property name="writeLockTimeout">
<value>${lucene.write.lock.timeout}</value>
</property>
<property name="commitLockTimeout">
<value>${lucene.commit.lock.timeout}</value>
</property>
<property name="lockPollInterval">
<value>${lucene.lock.poll.interval}</value>
</property>
<property name="defaultMLIndexAnalysisMode">
<value>EXACT_LANGUAGE_AND_ALL</value>
</property>
<property name="defaultMLSearchAnalysisMode">
<value>EXACT_LANGUAGE_AND_ALL</value>
</property>
<property name="threadPoolExecutor">
<ref bean="indexThreadPoolExecutor"></ref>
</property>
<property name="bulkLoader">
<ref bean="hibernateL1CacheBulkLoader"></ref>
</property>
<property name="maxDocsForInMemoryMerge">
<value>0</value>
</property>
</bean>
</beans>


This should fix your memory leak problem (if you are also suffering from the same problem)

I hope this fix doesn't break anything else.

Now if someone can figure out why this issue doesn't arise when someone load tests Alfresco with over 1mn documents.
To me, following can be the key differences between the test case and my case (if someone can get a clue from it):
- we have derived file and folder types to define our own types
- we are using good amount of metadata (15-20 additional properties on each file/folder node)
- we are calling Alfresco APIs using our webscript plug-in to Alfresco.
- inside webscript plug-in, we wrap each call within transaction

Saturday, April 18, 2009

Calling Web Services from C++

Hi,
This post is about calling Web Services from C++. I faced this requirement when I had to access Alfresco from C++. So, I am writing it in the context of Alfresco.

I have been working on MS Visual C++ for long, never worked on Java and JavaScript. I had to use Alfresco as back-end and I had to provide client interface UI from my app (and not from browser) which is written in C++. Common tasks, which I required, include:
  • Authentication, if possible secure
  • Listing all the folders and files on Alfresco Server
  • Getting properties of files ( like Last Modified time )
  • Creating/deleting/moving/updating files and folders
  • Checkin/Checkout/Get Current Version/Revert to old version
  • Getting all the versions of a node
  • Able to get a particular version (other than the current one ) of a node on my client machine ( very important )
  • etc
I explored/googled and found that some of the tasks listed above can be done via WebDAV and Alfresco supports WebDAV interface. I had a WebDAV libraray, using which can do things like create (put) a file on the server. But my library doesn't support versioning and I doubt that Alfresco supports versioning using WebDAV ( Delta V Extension to be precise ).
Now, in order to accomplish all the tasks, what can I do ? As I have already stated, I had to stick to C++, can't switch to Java. I found that Alfresco also supports much of it's functionality via Web Services. I had never used Web Services before and had a very basic idea. I had so many questions.
  • Does all the requirements listed above can be achieved via Web Services ?
  • If yes, from where to start ?
  • what are all the Web methods exposed by Alfresco ?
  • how to create (put) a file on server using Web Service ?
  • Does Alfresco provides support to get a particular version (other than the current one ) of a node on client machine ?
  • Are there other means of accessing Alfresco ?

I came to know that Alfresco also supports FTP interface, and that it also supports Web Scripts. So, if I have HTTP Client available, I could call some methods using Web Scripts. I didn't explore that option, as I was more interested in calling Alfresco Web Services.

I did extensive googling and found that till Visual Studio 2005, there was an option of adding a Web reference to VC++ project. By doing so, Visual Studio automatically generates stubs for a web service given it's .wsdl file. This functionality is now discontinued ( for VC++ projects ) in VS 2008, which was installed on my system. On another system I had VS 2005 installed, and I tried my luck there with the .wsdl files supplied with Alfresco ( VersioningService.wsdl to be specific ), but it was not able to parse the file and was unable to generate stubcode. Googling revealed that stub code for C++ is generated using SPROXY.EXE, and this tool is very outdated, not conforming to newer standards. Microsoft do not recommend calling Web Service from native C++ any more, rather they suggest using WSDL.EXE to generate code in .Net compatible languages ( like managed C++, VB .Net , C# etc ). WSDL.EXE seems updated and was able to parse the alfresco .wsdl file without error. MS has made source code of SPROXY public. As I was interested in getting stub code for native C++, I downloaded the source code for SPROXY, compiled it and tried my luck, but all in vain ( I didn't have that much time to understand the source code, wsdl syntax,SOAP syntax and a lot to modify the source code ).Further googling helped in finding a toolkit gSOAP, which does the same thing as SPROXY.EXE does. I downloaded the same, compiled it ( needed to install flex and bison, faced so many issues, and it took time! ) to get the executables. I then gave gSOAP the input VersioningService.wsdl and it returned the code. The generated code looks too obscure to me, any ways I tried (just playing) to call checkOut function with input parameters. The error code which I got returned was saying Server Internal error. I couldn't get much info about the error. Also, I had no idea, how to specify parameters for the function checkOut, namely repositoryId and documentId, no idea whatsoever, how can I get the input values to supply. I then turned to C#. I added the web reference to VersioningService.wsdl and it generated C# code for the stub. I called the method checkOut() with empty input parameters and it threw an exception. I Examined the exception, the text was something like target service is null, and there was a big stack trace of server java code ( seemed like some settings need to done, don't know how and where) . The call to web service generated following message.

POST /alfresco/api HTTP/ 1.1

User-Agent: Mozilla/4.0 (compatible; MSIE 6 .0; MS Web Services Client Proto col 2.0.50727.83 2)

VsDebuggerCausalityData: [some lengthy string]

Content-Type: text/xml; charset=utf-8

SOAPAction : ""

Host: server-pc:8080

Content-Length: 363

Expect: 100-continue

Connection: Keep-Alive

xyz

abc

I had no idea whether the generated Soap was correct. I had so many doubts.

I kept on exploring the things and found some answers.

First thing is that the Alfresco APIs are exposed at http://server-pc:8080/alfresco/api/, for example http://server-pc:8080/alfresco/api/AuthenticationService ( name of the service can be found in.wsdl file ). I figured this out and tried with http://server-pc:8080/alfresco/api/VersioningService, only to find out that this service was not exposed. I think not all of .wsdl files have their corresponding services exposed. For repositryID and documentID thing, I would suggest not use VersioningService at all. Rather use AuthoringService for CheckOut and similar sort of things. You need to use AuthenticationService first to start a session.There is one more thing needs mention. All Web Services exposed by Alfresco seems secure, menas they will require security token in the SOAP header ( obtained from AuthenticationService ).

The moral of the story is, In C++, without proper support of any library, it can be a great pain working with Web Services.

If I get time, I will try to write a library in C++ to provide support for Web Services.

Thursday, April 16, 2009

Calling Alfresco Web Services from C#

Hi,
I am starting this topic to share my experience of calling Alfresco Web Services from .Net, the problems which you may face and the solutions.
I first started with scratch. I created a C# project and added a Web reference to AuthenticationService (authentication-service.wsdl) , and VersioningService (VersioningService.wsdl).
Then I wrote following lines of code


WindowsApplication1.AuthenticationService.AuthenticationService asvc = new WindowsApplication1.AuthenticationService.AuthenticationService();
AuthenticationResult ar = asvc.startSession("admin", "admin");

It worked fine. Examining ar showed the token returned by Alfresco.
I then wrote the following lines

VersioningService vs = new VersioningService();
string repID = ("xyz");
string docID = ("abc");
string docRefId = docID;
bool b = vs.checkOut(repID, ref docRefId);

I was expecting an exception to be generated for giving invalid parameters, but the exception generated was about target service is null. It seems VersioningService is not exposed at URL/alfresco/api/VersioningService.
I then tried to add reference to RepositoryService (repository-service.wsdl ). Visual Studio reported a problem:
The document was understood, but it could not be processed. The WSDL document contains links that could not be resolved.
The solution was to remove the nillable attributes in cml.xsd files. After doing that, it was able to add the reference. I then wrote the following lines

RepositoryService rs = new RepositoryService();
rs.Credentials = asvc.Credentials;
Store[] stores = rs.getStores();


The exception which got generated was about Unauthorization. It was simple to figure out the cause, I was not passing in the security token, it was hard to figure out how to pass that. I was stuck.
I then googled and found out that there is demo project called dotNet2 for calling Alfresco APIs from .Net. I downloaded the same and tried to build it. It turned out that there was a missing reference to Microsoft.Web.Services3 assembly. Solution was to install MS WSE 3. So well and good.
I tried building the solution and there was a problem:

Error 1 The best overloaded method match for 'WebServiceFactory.addSecurityHeader(Microsoft.Web.Services3.WebServicesClientProtocol)' has some invalid arguments
Error 2 Argument '1': cannot convert from 'Alfresco.RepositoryWebService.RepositoryService' to 'Microsoft.Web.Services3.WebServicesClientProtocol'

I tried google to find out the solution for this, and I got one but it didn't work. A close observation revealed that addSecurityHeader was expecting Microsoft.Web.Services3.WebServicesClientProtocol object the service objects which we were passing were derived from SoapHttpClientProtocol class. I found that Microsoft.Web.Services3.WebServicesClientProtocol itself derives from SoapHttpClientProtocol, so I just let the web services class derive from Microsoft.Web.Services3.WebServicesClientProtocol and it worked!!
Then I tried to call getStores() method of RepositoryWebService and I again encountered exception. There was some problem in class instantiation from the returned response. Close observation again revealed the problem. The StoreEnum of RepositoryWebService was defined like this

public enum StoreEnum {
///
workspace,
///
versionStore,
///
user,
///
search,
///
http,
///
system,
}

I extended this enum to look like this

public enum StoreEnum {
///
workspace,
///
versionStore,
///
user,
///
search,
///
http,
///
system,
archive,
avm,
}

And after doing this, the call succeeded
Now my task was to test checking out of a selected file and getting a previous version of a selected file. After many hit and trials, I got it working and here is the reference code (I added private AuthoringService authoringService; to Browse class)
This is the code for Checking Out a selected file:
private void CheckOut_Click(object sender, EventArgs e)
{
ListViewItem item = listViewBrowse.SelectedItems[0];
if (item != null)
{
ResultSetRowNode node = item.Tag as ResultSetRowNode;
if (node != null)
{
if (node.type.Contains("folder") == false)
{
// Create the reference for the node selected
Alfresco.AuthoringWebService.Store spacesStore2 = new Alfresco.AuthoringWebService.Store();
spacesStore2.scheme = Alfresco.AuthoringWebService.StoreEnum.workspace;
spacesStore2.address = "SpacesStore";
Alfresco.AuthoringWebService.Reference reference = new Alfresco.AuthoringWebService.Reference();
reference.store = spacesStore2;
reference.uuid = node.id;
// Lets try to check out
Alfresco.AuthoringWebService.Predicate predicate = new Alfresco.AuthoringWebService.Predicate();
predicate.Items = new Object[] { reference };
Alfresco.AuthoringWebService.ParentReference pr = new Alfresco.AuthoringWebService.ParentReference();
pr.store = spacesStore2; ;
pr.uuid = this.currentReference.uuid;
pr.associationType = Constants.ASSOC_CONTAINS;
pr.childName = Constants.createQNameString(Constants.NAMESPACE_CONTENT_MODEL,item.Text);
this.authoringService.checkout(predicate, pr);
}
else
{
// show message that a folder has been selected
}
}
}
}


And this is the code for getting the original version of a file
private void GetOriginalVersion_Click(object sender, EventArgs e)
{
Alfresco.RepositoryWebService.Store[] stores = this.repoService.getStores();
Alfresco.RepositoryWebService.Store vStore = stores[3]; // from data,I found out that this is for Versioned store
ListViewItem item = listViewBrowse.SelectedItems[0];
if (item != null)
{
ResultSetRowNode node = item.Tag as ResultSetRowNode;
if (node != null)
{
if (node.type.Contains("folder") == false)
{
// Create the reference for the node selected
Alfresco.AuthoringWebService.Store spacesStore2 = new Alfresco.AuthoringWebService.Store();
spacesStore2.scheme = Alfresco.AuthoringWebService.StoreEnum.workspace;
spacesStore2.address = "SpacesStore";
Alfresco.AuthoringWebService.Reference reference = new Alfresco.AuthoringWebService.Reference();
reference.store = spacesStore2;
reference.uuid = node.id;
VersionHistory VH = this.authoringService.getVersionHistory(reference);
int i = 0;
char[] temp = new char[1];
temp[0] = '0';
string versions = new string(temp);
Alfresco.AuthoringWebService.Version first;
foreach (Alfresco.AuthoringWebService.Version version inVH.versions)
{
if (i == 0)
first = version;
versions += version.label + (";") + version.id.uuid +(";");
}
{
// Create the reference for the node selected
Alfresco.ContentWebService.Store spacesStore3 = new Alfresco.ContentWebService.Store();
spacesStore3.scheme = Alfresco.ContentWebService.StoreEnum.versionStore;
spacesStore3.address = vStore.address;
Alfresco.ContentWebService.Reference reference1 = newAlfresco.ContentWebService.Reference();
reference1.store = spacesStore3;
reference1.uuid = VH.versions[VH.versions.GetUpperBound(0)].id.uuid;
// Lets try and get the content
Alfresco.ContentWebService.Predicate predicate = newAlfresco.ContentWebService.Predicate();
predicate.Items = new Object[] { reference1 };
Content[] contents = this.contentService.read(predicate,"{http://www.alfresco.org/model/content/1.0}content");
Content content = contents[0];
if (content.url != null && content.url.Length != 0)
{
string url = content.url + "?ticket=" + AuthenticationUtils.Ticket;
webBrowser.Url = new Uri(url);
}
}
}
else
{
// show message that a folder has been selected
}
}
}
}

Here is the link for the Holy Grail dotNet2 Demo project
http://forge.alfresco.com/frs/download.php/80/alfresco-dotNet-0.2Beta.zip

And here is the the project which will allow you to do a Check Out and Get Latest version. it is an extended version of dotNet2 Demo project. You should be able to head start with it. Change the Alfresco Server location as per your requirement.

http://cid-f49e53911f11f3b1.skydrive.live.com/self.aspx/.Public/Technical/Alfresco/alfresco-dotNet-0.2Beta-Modified.zip

Thanks,