Windows Azure - AppFabric Service - Client Creation
In this article you will see how to create a client to connect to the WCF Service using the AppFabric Service Bus feature.
In the previous article we have seen how to create a WCF Service using the AppFabric Service Bus feature. Now we can create a client to connect to the same service.
Following are the steps to create the WCF
client. The first few steps are the repeating of the server creation.
Step 1 : Create a new console application
The console application is fine for our purpose. Create a new console
Now change the project property Target Framework to .NET Framework 4 as shown
below. This is needed because the Microsoft.ServiceBus assembly has dependency
on the above framework assembly.
Step 2 : Add a reference to System.ServiceModel assembly
For the WCF contracts, we need to add a reference to the System.ServiceModel
assembly as shown below.
Step 3 : Add a reference to Service Bus assemblies
Now add references to the following assemblies.
The above files can be located in your
AppFabric SDK installation folder. In my computer it was located in the
C:\Program Files\Windows Azure AppFabric SDK\V1.5\Assemblies\NET4.0
Step 4 : Create a new client side Interface and Client Channel
As we cannot automatically create the client side proxy and associated channel
types, we need to create them manually.
Create a new interface named IGreetingContract and add the following code into
Now we are ready with the necessary client contracts and the channel types.
Step 5 : Create the service invoking code
Open the Program.cs and add the following code into it. Here also we are not
using the application configuration file for specifying the end points.
servicePath = "GreetingService";
serviceNamespace = "YourNameSpaceHere";
issuerName = "YourIssuerNameHere";
issuerSecret = "YourIssuerSecretHere";
uri = Microsoft.ServiceBus.ServiceBusEnvironment.CreateServiceUri("sb",
sharedSecretServiceBusCredential = new
channelFactory = new
channelFactory.Endpoint.Address = new
channelFactory.Endpoint.Binding = new
channelFactory.Endpoint.Contract.ContractType = typeof(IGreetingChannel);
channel = channelFactory.CreateChannel();
result = channel.GetMessage("Pat");
from Service receieved: "
Step 6 : Execute the application
Now we are ready to execute the application. Press F5 and you can see the result
Note: Ensure the WCF service is kept running.
In this article we have seen how to create a client to connect to the WCF
service using the AppFabric Service Bus. The attached source code contains the
service code which you can use it after modifying using your service bus