.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Lee Hnetinka

Home >> Articles >> Azure >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Azure Part 35 - Service – Client Creation

Posted By:Jean Paul       Posted Date: March 15, 2012    Points: 200    Category: Azure    URL: http://www.dotnetspark.com  

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.

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 Files\Windows Azure AppFabric SDK\V1.5\Assemblies\NET4.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 IGreetingContract and 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= "http://tempuri.org")]

    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.

 Subscribe to Articles


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend