WCF Proxy Creation ways
There are different ways of creating WCF proxy :
Adding service reference to a WCF service using Visual Studio
Use SvcUtil.exe utility to create proxy
Implementing ClientBase<T> Class
Click on Add Service Reference option , you'll see the dialog box that is shown in Figure :
Once you've clicked OK in the dialog box, the add-in spawns SvcUtil.exe, generating the necessary proxy class and the required configuration file (or modifying it) and adding the necessary references to the project.
This is the way to create sync WCF service proxy
To create WCF service proxy in async way please follow below steps before clicking on OK :
Click on Advanced Button
Click on Generate Asynchronous operation checkbox and then click on OK button
Using SVCUtil.exe
To generate manually, choose the CMD window by selecting Start | All Programs | Microsoft Windows SDK | CMD.The output files SVCUtil generates are the client proxy source code file and the application configuration file.
Command for producing both proxy class and configuration file
svcutil /config:app.config /out:"CalculatorService.cs" /language:csharp /n:*,SimpleClientWithProxy.CalculatorService "http://localhost/MathService/?CalculatorService.svc"
By default , svcutil generates only synchronous method signatures in proxy .
Use option /async to generate both synchronous and asynchronous method signatures in proxy
Implementing ClientBase<T> Class
Of all the methods , implementing ClientBase is best one because we need not create proxy class every time we make changes in service implementation.
public partial class SampleServiceClient : System.ServiceModel.ClientBase<ISampleService>, ISampleService
{
public SampleServiceClient()
{
}
public SampleServiceClient(string endpointConfigurationName) :
base(endpointConfigurationName)
{
}
public SampleServiceClient(string endpointConfigurationName, string remoteAddress) :
base(endpointConfigurationName, remoteAddress)
{
}
public SampleServiceClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) :
base(endpointConfigurationName, remoteAddress)
{
}
public SampleServiceClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) :
base(binding, remoteAddress)
{
}
public string SampleMethod(string msg)
{
return base.Channel.SampleMethod(msg);
}
}
No comments:
Post a Comment