Wednesday, August 26, 2009

WCF in VS 2005 , consuming wcf with VS 2003 or VS 2005, WCF in Sharepoint 2003

We may often come with situation where we want to use a WCF service with .Net framework 1.1 or 2.0. We know that with 2.0 we can add the WCF extenders and work with WCF, but what about VS 2003 and .net Framework. Lets say we have an existing application in .Net 1.1 framework and wants to use WCF. This article expains this situation. First let us create your WCF Service. To keep it simple create a WCF service with VS 2008 and host it in iis. Let say your service is having a method "GetWelcomeMessage" which takes a string as input parameter and retuns the same value by appending "Welcome to WCF" to it. Below is how the WCF code will look like

public string GetWelcomeMessage(string value)
{
return "Welcome to WCF " + value;
}

you may find the details of how to host a service in iis @
Hosting WCF in IIS

Make sure that you use "basicHttpBinding" and make the config file changes as



Now Open your VS 2003 application and add a web reference as shown below. Lets call the service reference as "localhost". Lets say you have hosted your service "http://localhost/HelloWorldService/HelloWorld.svc"



After adding the service it will look like this



Now go to you code where you want to make a call to the code

localhost.Service1 objService = new localhost.Service1();
Response.Write(objService.GetWelcomeMessage("Puru"));


The output of this would be "Welcome to WCF Puru".

Hope this helps....

You can also call the same service in Java client. Know more @ Consuming WCF in Java

No comments: