Jean Paul's Blog

There are 2 types of People in the World, One who Likes SharePoint and..

  • Microsoft MVP

  • MindCracker MVP

  • CodeProject MVP

  • eBook on SharePoint 2010

  • eBook on Design Patterns

  • eBook on Windows Azure

  • NLayers Framework @ CodePlex

  • MSDN Forums

  • .Net vs. Java

    Due to Public Demand
  • Advertisements

Windows Azure – AppFabric Service – Client Creation

Posted by Paul on November 15, 2011

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 new console application

The console application is fine for our purpose. Create a new console application.


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 reference to System.ServiceModel assembly

For the WCF contracts, we need to add reference to the System.ServiceModel assembly as shown below.


Step 3: Add reference to Service Bus assemblies

Now add reference to the following assemblies.

  • Microsoft.ServiceBus
  • RelayConfigurationInstaller

The above files can be located in your AppFabric SDK installation folder. In my computer it was located in the following folder.

C:Program FilesWindows Azure AppFabric SDKV1.5AssembliesNET4.0


Step 4: Create 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 IGreetingContractand add the following code into it.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.ServiceModel;

namespace AppFabricWCFClient


[ServiceContract(Name = “IGreetingContract”, Namespace= “”)]

public interface IGreetingContract



string GetMessage(string name);


public interface IGreetingChannel : IGreetingContract, IClientChannel




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.

static void Main(string[] args)


string servicePath = “GreetingService”;

string serviceNamespace = “YourNameSpaceHere”;

string issuerName = “YourIssuerNameHere”;

string issuerSecret = “YourIssuerSecretHere”;

Uri uri = Microsoft.ServiceBus.ServiceBusEnvironment.CreateServiceUri(“sb”, serviceNamespace, servicePath);

TransportClientEndpointBehavior sharedSecretServiceBusCredential = new TransportClientEndpointBehavior();

sharedSecretServiceBusCredential.CredentialType = TransportClientCredentialType.SharedSecret;

sharedSecretServiceBusCredential.Credentials.SharedSecret.IssuerName = issuerName;

sharedSecretServiceBusCredential.Credentials.SharedSecret.IssuerSecret = issuerSecret;

ChannelFactory<IGreetingChannel> channelFactory = new ChannelFactory<IGreetingChannel>();

channelFactory.Endpoint.Address = new EndpointAddress(uri);

channelFactory.Endpoint.Binding = new NetTcpRelayBinding();

channelFactory.Endpoint.Contract.ContractType = typeof(IGreetingChannel);


IGreetingChannel channel = channelFactory.CreateChannel();


string result = channel.GetMessage(“Pat”);

Console.WriteLine(“Greeting from Service receieved: ” + result);



Step 6: Execute the application

Now we are ready to execute the application. Press F5 and you can see the result below.


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 AppFabric Service Bus. The attached source code contains the service code which you can use it after modifying using your service bus properties.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s