Saturday, April 24, 2010

Visit UK tours

Visit UK tours

Saturday, March 13, 2010

WCF Service Hosting on Production Server

Host a WCF Service in IIS 7 & Windows 2008 - The right way


I am going to cover some information here in this blog post that is nowhere else on the web. That is not surprising, consider that less than 2 people in the world are actually using WCF + .NET 3.5 + IIS 7.

Anyway, deploying a WCF service using .NET 3.5 framework to IIS 7 requires you to jump through a couple of hoops ..


Well, in this blogpost, I am going to cover hosting the service in IIS 7. I saw this MSDN article talking about hosting the WCF service in IIS. I thought that article was very sub-optimal. Here are my reasons:

a) It won't work for IIS 7 . IMO it's quite bad that an MSDN article isn't upto the times - and they expect us devs to be up on all this cool new shiny stuff :-).
b) It talks of creating an App_Code directory, and throwing a .cs file in there - this is okay for your development environments, but not for production code deployment. Your deployment process must not require you to work in .cs.
c) That article literally talks about writing a new WCF service in IIS - Dangit!

I'm going to instead talk about - you've developed a service, now how the heck we deploy it. Well, here are the steps.

  1. Build your Service Library in release mode.
  2. Go to your Win2k8 server, and add the "Web Server" role - make sure ASP.NET is enabled.
  3. Create a dir on your disk - I put mine in c:\code\HelloWorld <-- this will be the physical directory that will run my WCF service.
  4. Fix the security on this dir by adding the following permissions
    1. Ensure that "Network Service" has Read & Execute + List folder contents + Read.
    2. Ensure that IIS_IUSRS have Read & Execute + List folder contents + Read.
  5. Now, go to IIS MGR, and add a new application pool called "Hello World". Ensure that this Application Pool is set to the settings as shown below -


  6. Next, create a website in IIS7 with the following settings -


  7. Are we done yet? Heck no! Apparently, WCF .. doesn't work with IIS 7 OOTB. So you need to run command prompt as administrator, and run the following command -

    "%windir%\Microsoft.NET\Framework\v3.0\Windows Communication Foundation\ServiceModelReg.exe" -r -y
  8. Now, the DLL that you created in step #1, copy that to C:\Code\HelloWorld\Bin .. where C:\Code\HelloWorld is the physical path of my website.
  9. Next, create a file called HelloWorld.svc at C:\Code\HelloWorld with the following text in it -

    <% @ServiceHost Service="MyServices.HelloWorld" %>

    Note that it looks very much like ASP.NET code behind .. shocking huh?
  10. Next, create a web.config with the following -
  11.    1: xml version="1.0" encoding="utf-8"?>
       2: <configuration>
       3:   <system.serviceModel>
       4:     <services>
       5:       <service behaviorConfiguration="MyServices.HelloWorldBehavior" name="MyServices.HelloWorld">
       6:         <endpoint address="" binding="wsHttpBinding" contract="MyServices.IHelloWorld" />
       7:         <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
       8:         <host>
       9:           <baseAddresses>
      10:             <add baseAddress="http://localhost:8000/" />
      11:           baseAddresses>
      12:         host>
      13:       service>
      14:     services>
      15:     <behaviors>
      16:       <serviceBehaviors>
      17:         <behavior name="MyServices.HelloWorldBehavior">
      18:           <serviceMetadata httpGetEnabled="true" />
      19:           <serviceDebug includeExceptionDetailInFaults="false" />
      20:         behavior>
      21:       serviceBehaviors>
      22:     behaviors>
      23:   system.serviceModel>
      24: configuration>

    As you can see, I have set a base address of http://localhost:8000 <-- change that to what suits you. Also, I have created 2 endpoints, one uses wsHttpBinding, and the other uses mexHttpBinding.
  12. Now browse to this URL - http://localhost:8000/HelloWorld.svc, you should see the service hosted as shown below -


  13. Thats it! You can either use svcutil now, or you can hand-create a channel/proxy to use the above service as shown in this earlier blogpost of writing a WCF client.

___________________________________

There are other ways of hosting a WCF service too. You could host them using WAS - Windows Activation Service. Hosting them in WAS or IIS means, you don't have to worry about the host lifetime. IIS and Win2k8/Vista take care of the host lifetime for you. However, for the rather interesting situation of two WF's talking to each other, you may need to have an EXE that is both a WF host, and a WCF host, as I described here. In such instances, you may need to write your very own host. As it turns out .. it's rather easy to write your own WCF host.


Sunday, August 30, 2009

Installing Spring Plugin for Eclipse Ganymede

1.Install Eclipse 3.4.1 JEE Ganymede SR1 from (http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/ganymede/SR1/eclipse-jee-ganymede-SR1-win32.zip)
2. Load Eclipse and goto Help->Software Updates
3. Add New site and paste URL http://download.eclipse.org/tools/ajdt/33/update/ Select All click Install
4. Restart Eclipse
5. Load Eclipse and goto Help->Software Updates
6 Add New site and paste URL (http://dist.springframework.org/release/IDE) Select All click Install
7 Restart Eclipse you are all set

Monday, June 29, 2009

Http Post In android

HttpResponse response;
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httpost = new HttpPost("url");

httpost.setHeader("Content-Type", "application/x-www-form-urlencoded");
//Input the user id and authentication key here

StringEntity message = new StringEntity("");

httpost.setEntity(message);
ResponseHandler responseHandler = new BasicResponseHandler();

String responseBody = httpclient.execute(httpost, responseHandler);
responseBody = " Sent!";
return responseBody;

Concurrency In using AsyncTask class (Android1.5)

I found that two AsyncTasks do not work concurrently. I investigated a bit and found a workaround .AsyncTask allows the app to do a task on a thread other than the UI thread. But IIUC, it only provides a single thread on which a queue of tasks is performed. Therefore, if one of the task is to wait on some event (n/w or sleep) then all other tasks will wait for it to finish.

To elaborate with the coding example:


public class MyTask extends AsyncTask<...>
{ ... }

// On the UI thread execute two tasks
MyTask mt1 = new MyTask().execute(args);

MyTask mt2 = new MyTask().execute(args);


In the above code both the execute calls will return immediately and free up
the UI thread; however mt1 will be executed first and mt2 will have to wait
until mt1 finishes.

Thanks to the android's open source, we can see implementation of AsyncTask.
http://google.com/codesearch/p?hl=en&sa=N&cd=2&ct=rc#uX1GffpyOZk/core...

I copied AsyncTask.java as UserTask.java in my project and changed the value
of CORE_POOL_SIZE to 5. This makes the thread pool to use 5 threads to
multiplex the queued AsyncTasks. This indeed solved my problem. Now if mt1
blocks on a sleep; mt2 goes ahead and finishes its job.

Sunday, June 28, 2009

Chicken Biryani ..Luch time:-)

Chicken biryani – Malabar ishtyle.


Finally i tried my hand in making Chicken Biryani Kerala Ishtyle ....:-)..It was an experiment but to tell you the truth i loved it . Even my mom and dad loved it..:-)

I would like to thank my Mom for helping me in making this experimental dish for my family

Once you have made biryani you will see that it is more of a method than exact measure ( except for cooking the rice).

Here are some pictures to get you inspired.

Cooking the rice:

Soak the rice in water for 30min or so prior to cooking. Drain off the water.

Add ghee( a must for authentic taste), cloves, cardamon and cinnamon. Add the rice. Stir well. Add water and salt. ( For 3 cups of rice, I used 5 3/4 water). Cook covered. When all water is evaporated, shut off the flame and keep covered for a few more minutes. In the meanwhile avoid stirring. You can fluff with a fork after it has finished cooking

.basmati-rice-cooked.jpg

Cooking the chicken

chicken-biryani.jpg

Layering the rice and chicken

biryani-layers.jpg



Also fry onions, raisins and cashews.

Bake for 15- 20 minutes.

Serve warm with raita ,curd , achar .

biryani-plated.jpg

Saturday, June 27, 2009

Inheritance Vs Composition in Java

One of the fundamental activities of any software system design is establishing relationships between classes. Two fundamental ways to relate classes are inheritance and composition. Although the compiler and Java virtual machine (JVM) will do a lot of work for you when you use inheritance, you can also get at the functionality of inheritance when you use composition. This article will compare these two approaches to relating classes and will provide guidelines on their use.

First, some background on the meaning of inheritance and composition.

About inheritance
In this article, I'll be talking about single inheritance through class extension, as in:

class Fruit {      //... }  class Apple extends Fruit {      //... } 

In this simple example, class Apple is related to class Fruit by inheritance, because Apple extends Fruit. In this example, Fruit is the superclass and Apple is thesubclass.

I won't be talking about multiple inheritance of interfaces through interface extension. That topic I'll save for next month's Design Techniques article, which will be focused on designing with interfaces.

Here's a UML diagram showing the inheritance relationship between Apple and Fruit:

Inheritance relationship
Figure 1. The inheritance relationship

About composition
By composition, I simply mean using instance variables that are references to other objects. For example:

class Fruit {      //... }  class Apple {      private Fruit fruit = new Fruit();     //... } 

In the example above, class Apple is related to class Fruit by composition, because Apple has an instance variable that holds a reference to a Fruit object. In this example, Apple is what I will call the front-end class and Fruit is what I will call the back-end class. In a composition relationship, the front-end class holds a reference in one of its instance variables to a back-end class.

The UML diagram showing the composition relationship has a darkened diamond, as in:

Composition relationship
Figure 2. The composition relationship