WCF - Starting troubles and solutions

Tuesday, July 5, 2011 - Posted by రాజేష్ జి at 8:02 PM
When I had led off playing with WCF (Windows Communication Foundation) services, blistered with three major issues to overcome before running the application successfully. These three issues are aroused from outside of WCF services but triggered while WCF communicating with other piece of service in order to achieve application functionality in question. This post targets to discuss about those issues in a PSA (Problem-Solution-Approach) fashion but confined to below machine configuration. Please bear in mind that this post is not going to discuss about the creation WCF services and related stuff. 

Machine configuration: Windows server 2008 Enterprise/.NET 4.0/Visual Studio 2010/IIS 6.0/SQLServer 2008
 

What is this application about:
 This is a tiny application that creates a WCF service to fetch  products from Adventureworks database and then hosted on IIS so that client application can start to consume the service.



1.Problem: WCF service has been built successfully buy while trying to host it on IIS, visual studio thrown up a exception dialogue box saying that

"To access local IIS Web sites, you must install the following IIS6 compatible components".


Solution: There are two solutions lying around to resolve this problem. One is about running visual studio under Administrator mode and second one, most probably, would be installation of IIS6 compatible components.


Approach: 
1) Though the exception was messaging that IIS6 components were missed, It is likely could be a permission issue. Thus mean, to host a WCF service on IIS, you must be an administrator or should acquire admin rights over the machine you are using. If you self-assured that you are an administrator then rush to visual studio, right-click against it and select "Run as Administrator" to start running it under system administrator mode. Now try to publish/host the WCF service on IIS.  If you still left behind the issue, follow below approach which embed with second solution and would solve the issue most probably. 


2)When you reach this approach, It is apparent that required IIS6 compatible components haven't been installed. Follow below steps to install IIS6 compatible components. 


  • Start -> Administrative Tools and select Server Manager to invoke it
  • From Server Manager application, select Roles -> Web server(IIS), right-click and hit for Add Role Services. See below snap.   

  • Add Role Services window would popped out with list of role services to install for IIS Webserver. Observe large text area labelled with Role Services and here scroll down until you find a tree child node labelled with Management tools. Select that node to get collapsed and observe a child node labelled with IIS6 Management Compatibility. Under this child node, select all components or the one which visual studio reported and hit for "install". When everything installed successfully,  Add Role Services window look like          
          
             
  • Now rush to visual studio and start publish/host your service on local IIS. This time publishing should be successful.     


2.Problem: WCF service was running very well until it gets hosted on IIS. Now throwing an exception saying 


" Could not load type System.ServiceModel.Activation.HttpModule.."


A sudden jerk! 


Solution: Yes, It is really a pissed off one. Also very disgusting that exception message is not at all assisting in troubleshooting the root cause. Anyhow, the reason behind exception would be installation of .NET framework 4.0 after IIS installation or WCF 3.0 version of Http activation module is installed after IIS and .NET 4.0 installation. That mean IIS is not cognizant of running your service under .NET 4.0 which leads to an exception. To resolve the issue, simply register .NET 4.0 version with IIS.


Approach: .NET framework comes with wide number of tools which will assist developers to finish off core common tasks speedily. ASP.NET IIS registration tool(Aspnet_regiis.exe)  is one of the pretty tool from that tool set and is useful to register the correct version of .NET framework/ASP.NET with IIS. Follow below steps to accomplish that.
  • Start -> All Program -> Microsoft Visual Studio 2010 and select it to get collapsed 
  • From there, select child node visual studio tools and then hit for visual studio command prompt (2010) which will popped out visual studio command prompt where you can  execute .NET provided command line tools at ease.

  • From VS command prompt, run the command aspnet_regiis.exe -iru.        
  • If the registration went successful,  VS command prompt should look like

          
  • When everything looks good, rush to WCF service and refresh it. Service should work now. 
3.Problem: When WCF service was on ASP.NET development server, It was consumed by a console application and pulled Product data from Adventureworks database. Everything went well until WCF service hosted on IIS and modified endpoint address of console application to use WCF service from IIS rather ASP.NET development server. WCF service is running well, but console app is not showing up any data. 

Solution: This is a valid issue and surrounded with security policy. When a WCF service is hosted on IIS, It is literally meant that service is available for public to consume but authenticated one. So IIS puts security locks on WCF service by placing it under default application pool and running it under a  default service account i.e. usually NetworkService account.[We can also create our own application pool and service account to run the service.] Since the service is running under a service account, it should have given appropriate access to AdventureWorks database. And in this instance, the service account must be a member of db_owner role in AdventureWorks database.  

Approach:   Follow below steps to sort out the problem 
  •  Find the application pool under which WCF service is running
    • Start -> Run -> INETMGR should open IIS. Now rush to your service and hit for "basic settings" which will pop us a dialogue box looks like    
  • In this instance, WCF service is running under DefaultAppPool. Now look for the service account/identity of DefaultAppPool. [Press cancel button to close the dialogue box opened.]
  • Select Application pools appeared under machine name and observe list of Application pools available on right side. Here select DefaultAppPool and hit for Advanced settings link available on extreme right. See below snap.

  

  • Check and note down the service account/identity of Application pool. In this instance, it is NetworkService. 
  • Now start->all programs-> Microsoft SQLserver 2008 and select SQL Server Management studio to run SQLServer Management studio
  • In MS SQLserver, you can add new login either under server level or under a database level. The purpose is very intuitive. For now, adding at database level would suffice the requirement.
  • From SQL Server Management studio, Select the database i.e. AdventureWorks and then Security-> users, right click New User which will pop up a window to add new user. 
  • Now enter user name Network Service, You may go for CheckName to make sure what you entered is correct, and select db_owner from role members and hit for ok to create a login. 
  • When everything went successful, SSMS looks like


  • Now client console application should pull the product information as expected :) 

As said at inception of this post, solutions and approaches explored over here confined to the specified machine configuration and may work for other too but I am not sure. Check yourself and keep fingers crossed. Post here If you need any help on the same front.

Keep Koding :)

JSON, Javascript, CSS, DHTML Saga..!

Saturday, May 14, 2011 - Posted by రాజేష్ జి at 11:15 AM
I've been vexing about what should be the next post? Then got a sudden thunder thought about keeping a post up on .NET Web development aiding technologies such as JSON, Javascript, CSS, DHTML to make up web pages more dynamic and user friendly.

We know that those technologies in question have been running around Internet from its inception. But it is always a bizarre to self-learn these due to lack of single ownership and subsequently worthy help. Thus mean, developers has to share what they learnt by experience rather bookish.

As all we know, said technologies are playing vital role in web development and ASP.NET is not an exception. You must see novice and veteran developers running around internet aiding each other in getting though them. Yes, There I am and turned on.

I feel myslef excel in such quaky technologies :). Do you think my saying was exaggerated and want to testify me whilst getting your problems solved? If yes, I wish you will go far.

No more blah blah. Let us start sharing nuggets. Use this space to post technical issues you are facing with the technologies in question by bearing my below humble notes about problem posting.


Before Posting Problem:
1) Time is very precious to everyone. Bear in mind.
2)Thus mean, make sure yourself that you did enough troubleshoot to solve the problem prior posting.

While Posting Problem:
1) Make sure the problem statement is descriptive yet comprehensive.
2)It would be good If you can share the troubleshooting steps triggered so far

When Problem got resolved:  Worthy to follow
1) Take a minute and brief about how did you resolve problem off and solution applied
2) If you can share the exact approach taken, that would really helpful to other techies too who running with same problem.

So theme followed  here "Problem - Solution - Appoach!" After some worthy discussion flow, I will pile up significant problems and  relevant solutions and post them into separate posts for readers convenience. 

Then why late :) let us rock and keep fingers crossed!
 




Hello Techies!

Friday, May 6, 2011 - Posted by రాజేష్ జి at 7:28 PM

Technocrat, Welcome!

It has been my long wish to start a Techno blog and share technical aspects where I have been working for years.

Well. The minute reached now to kick off my first official technical blog that stacks up blistering and vibrant  Microsoft .NET technologies from C# to Silverlight  to WCF.

You might shoot a question what so special here when there are plenty of of similar running around Internet. Though it is truly but bit tricky question, My answer would be imparting .NET nuggets in more practical and fashionable way and less theory. That's my pledge!

If you have something in mind to share, You are most welcome.

Thanks for dropping by:)

Keep coding!