Learning WCF 4 : Default endpoint
Prior to WCF 4 , i.e. in WCF3 , there were three major steps when one talked about WCF Service.
- Creating WCF Service Contract (IService)
- Implementing the contract(Service1.svc)
- Making an endpoint for the service , which could be done using code or web.config file . Majority of times it was done using web.config file.
- Hosting the service
- Consuming that service
Most of the times developers felt that creating a basic wcf service even , they need to play with web.config file, which was a tedious task. Thus Microsoft came up with concept of DEFAULT ENDPOINT in WCF4.
So enjoy coding your first program with WCF4 , without creating endpoint.
Open Visual Studio IDE 2010
Fileà New Project à WCF Tab.
Choose template WCF Service Application, Name it BasicWcf
Step 2:
Delete default code generated from Contarct IService1 , so that it should look like following .
namespace BasicWcf
{
[ServiceContract]
public interface IService1
{
[OperationContract]
string GetData(int value);
}
}
Similary do for Service class : so that it looks like following
namespace BasicWcf
{
public class Service1 : IService1
{
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}
}
}
Step3: Open web.config file and delete following line for the time being .
Step 4: Build the service
Step 5: Add new project to the application
Step 6: Add service refrence in this console app to the service created.
Step 7: Click on discover .
Step 8: Add the following in the Program.cs
using ConsoleApplication1.ServiceReference1;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Service1Client proxy = new Service1Client();
var res=proxy.GetData(2403);
Console.WriteLine(res);
Console.ReadKey(true);
}
}
}
Step 9: Build the console app.
Step 10 : Set it as start up project.
Step 11; Run the project (F5)
Output :
Summary : This article shows how WCF 4 works with default endpoint . Default endpoint in WCF uses basicHttpBinding.
To check this just add following code in the Program.cs file and run again.
var bindingName = proxy.Endpoint.Binding.Name;
Console.WriteLine(bindingName);
Console.ReadKey(true);
Great Information in the post
ReplyDeleteGujarat postal circle recruitment 2016
Similary do for Service class : so that it looks like following using ConsoleApplication1
ReplyDelete10th supplementary result 2017 ts.ServiceReference1
Hey, Wow all the posts are very informative for the people who visit this site. Good work! We also have a Blog.Please feel free to visit our site. Thank you for sharing.
ReplyDelete@ Packers And Movers Gurgaon
Packers And Movers Gurgaon to Pune
Packers And Movers Gurgaon to Bhubaneswar
Packers And Movers Gurgaon to Bhopal
Packers And Movers Gurgaon to Lucknow
Packers And Movers Gurgaon to Chandigarh
Packers And Movers Gurgaon to Patna
Packers And Movers Gurgaon to Mumbai
Packers And Movers Gurgaon to Haridwar
This comment has been removed by the author.
ReplyDelete