ChannelAdam WCF Library — Version 2 Documentation
Quick Start
To get you started quickly, here is some sample code showing the basic usage.
Install NuGet Package
You can install the ChannelAdam.Wcf NuGet package from within Visual Studio, or find it on the NuGet.org gallery at https://www.nuget.org/packages/ChannelAdam.Wcf.
To install ChannelAdam WCF Library via the Package Manager Console, run the following command:
PM> Install-Package ChannelAdam.Wcf
How To Call a WCF Service
Let’s assume for the duration of this documentation that there is a web service named FakeService
and in Visual Studio we have generated a service reference and interface to FakeService
, and there is now an IFakeService
interface and a FakeServiceClient
class to use.
That is all normal and basic Visual Studio functionality.
Let’s also assume that the service has the following operation signature:
1int AddIntegers(int first, int second);
Below is sample code for how to use the ChannelAdam WCF Library ServiceConsumer
and ServiceConsumerFactory
to call the AddIntegers
operation.
1using ChannelAdam.ServiceModel;
2
3...
4
5//using (var service = ServiceConsumerFactory.Create<IFakeService>("BasicHttpBinding_IFakeService"))
6using (var service = ServiceConsumerFactory.Create<IFakeService>(() => new FakeServiceClient()))
7{
8 try
9 {
10 int actual = service.Operations.AddIntegers(1, 1);
11
12 ...
13 }
14 // catch (FaultException<MyBusinessLogicType> fe)
15 catch (FaultException fe)
16 {
17 Console.WriteLine("Service operation threw a fault: " + fe.ToString());
18 }
19 catch (Exception ex)
20 {
21 Console.WriteLine("Technical error occurred while calling the service operation: " + ex.ToString());
22 }
23}
Easy and no hassles.
There is no need to catch a CommunicationException
or TimeOutException
and try to perform the Close/Abort pattern, as the underlying channel is dealt with automatically for you by the ServiceConsumer
.
Please see the other documentation pages for further details.
comments powered by Disqus