The commoditization of technology has reached its pinnacle with the advent of the recent paradigm of Cloud Computing. Infosys Cloud Computing blog is a platform to exchange thoughts, ideas and opinions with Infosys experts on Cloud Computing

« Is cloud computing same as putting things Online? | Main | Basic Azure enabling guide »

Basic steps to expose the on-premise WCF service through appfabric Service bus to be used by Silverlight client in the Azure cloud

Basic steps to expose the on-premise WCF service through appfabric Service bus to be used by Silverlight client in the Azure cloud. It also talks about the steps to be followed to move an existing Silverlight client to the Azure. Some of the information has been taken from MSDN, Azure SDK and other blogs. The purpose of this is to provide all the information in a single place and there-by saving the precious time of developer. 


Steps to be followed in the service configuration:

1.       To the existing service, add a service end point with binding - "basichttprelaybinding". E.g.-

<service name="<service name>" behaviorConfiguration="WCFonIISServiceBehavior">

<endpoint address="http://<service bus namespace><Service name>/" behaviorConfiguration="sharedSecretClientCredentials" binding="basicHttpRelayBinding" bindingConfiguration="HttpRelayEndpointConfig" name="RelayEndpoint" contract="<service contract>" />



And then add the corresponding binding section-



        <binding name="HttpRelayEndpointConfig">

          <security mode="None" relayClientAuthenticationType="None" />





2.       Add the end point behavior to configure the credentials needed to connect to appfabric service bus and register the end point URL in the service bus. E.g.- in the end point declaration in step 1, "sharedSecretClientCredentials" is the end point behavior reference.  Add the declaration of the same as:


<behavior name="sharedSecretClientCredentials">

<transportClientEndpointBehavior credentialType="SharedSecret">


<sharedSecret issuerName="<ISSUER NAME>" issuerSecret="<ISSUER KEY>" />



       <ServiceRegistrySettings discoveryMode="Public" />




3.       To understand the steps to be followed to get the service namespace, issuer name and issuer key needed for on-premise service registration, please refer to APPENDIX- C.

4.       To make the end point available in the atom feed exposed by the service bus when the base service bus namespace URL is browsed (e.g.  http://<service-namespace> ); to the end point behavior, one end point setting needs to be added. In step 2 the same has been provided by - "ServiceRegistrySettings"

For using this setting we need to add a class file having the class definition provided in APPENDIX- D with as applicable class namespace name (for the project in concern).

5.       To make "ServiceRegistrySettings" recognizable, we need add the corresponding behavior extensions like:



<add name="ServiceRegistrySettings" type="<class namespace>.ServiceRegistrySettingsElement, <class namespace>, Version=, Culture=neutral, PublicKeyToken=null" />



                With as applicable class namespace.

Steps to be followed in the service deployment environment/machine:

The following are the steps to be followed in the machine where the service(s) to be exposed through appfabric service bus will be hosted and running.

1.       To make the service bus related DLLs available, install the "Windows Azure AppFabric SDK" from here.

2.       In the IIS, create the corresponding virtual directory and add the service related files and folders to it.

3.       Install TMG client and enable it with proper TMG forefront/ ISA server settings. Make sure the identity under which the application pool for the service running has internet access.

4.       When any wcf service is hosted in IIS, the service is ignited /started and made to be consumable only when the first request comes. But in this case, service in concern needs to be started before even any request for the service is made. This is because only once the service is started with the above mentioned settings, the service is registered to the service bus and a public URL is exposed which a client in the public (internet) may refer to while making a service request. To achieve this we need to enable the auto-start for the service i.e. the moment the hosting service is started (here IIS), the service hosted also gets started. To enable this, install the "Windows Server AppFabric Setup" from here. Once installed follow APPENDIX- A for the steps for enabling the service auto-start in IIS.

5.       To use the wcf service in a Silverlight client, if the service base url is different from that of the Silverlight client web application; as we know, we need to expose the client access policy xml file at the base address of the service. That is, in case of wcf service exposed through service bus, the client access policy needs to be accessible as - http://<servicebus-namepscae> . And since we don't have direct access to keep the said xml file to the root of the service, we need to expose a RESTful wcf service interface through service bus which will serve this purpose of exposing the policy file. For code sample on how to expose client access policy xml file RESTfully, please refer to this.


6.       Make sure to expose - http://<servicebus-namepscae> only after all the services to be exposed through service bus are started and could be verified by accessing the URL- http://<service-namespace> For the reason of this order of execution, refer to the APPENDIX- B.

Steps to be followed in the Silverlight client application:

1.       In the Silverlight project (i.e. .... SilverlightUX)

a.       If this is a new project then add the service reference to the services

b.      If this is an existing project then either refresh the service reference(s) or in the ServiceReferences.ClientConfig file:

                                                               i.      For the concerned service's client end point add/edit the address attribute to provide the service bus url like- http://<servicebus-namespace><service-name>/  e.g.:


<endpoint address="http://<service-bus namespace><service name>/"

                binding="basicHttpBinding" bindingConfiguration="RelayEndpoint"

                contract="<service proxy name>.<service contract>" name="RelayEndpoint" />



                                                             ii.      Provide the binding type as "basicHttpBinding" because this is compatible with the "basicHttpRelayBinding" used to register the on-premise service to the service bus. And accordingly provide the binding configuration as needed e.g.:



              <binding name="RelayEndpoint" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">

<security mode="None" />





2.       To the solution having the Silverlight application project and the corresponding hosting website project, add a blank Windows Azure project i.e. without any roles.

a.       Once the Azure project add, on the "Roles" folder right click and add role using the menu-  "Web role project in solution":



b.       And from the shown list select the website project hosting the concerned Silverlight application:


3.       If the Silverlight project is of type Business application then for all the WCF RIA services related dlls, make sure to set the property "Copy Local" to true to include these in the deployment package:


4.       If the Silverlight application is making use of the "by default provided Login form" then make sure to override at least the method - GetAuthenticatedUser in:


If ADFS is used for user authentication then for example override as:

                protected override User GetAuthenticatedUser(System.Security.Principal.IPrincipal principal)


            //return base.GetAuthenticatedUser(principal);

            User claimsUser = new User();

            string alias = "loggedInUser";



                Microsoft.IdentityModel.Claims.IClaimsPrincipal claimsprincipal = principal as Microsoft.IdentityModel.Claims.IClaimsPrincipal;

                Microsoft.IdentityModel.Claims.IClaimsIdentity claimsIdentity = claimsprincipal.Identity as Microsoft.IdentityModel.Claims.IClaimsIdentity;

                foreach (Microsoft.IdentityModel.Claims.Claim claim in claimsIdentity.Claims)


                     if (claim.ClaimType.ToLower().Contains("upn"))


                         alias = claim.Value.Split('@')[0];





            catch (System.Exception ex)


                alias = ex.Message + ": " + ex.StackTrace;


            claimsUser.FriendlyName = alias;

            claimsUser.Name = alias;

            return claimsUser;




This is needed otherwise an error will be thrown by Login form- "Load operation failed for query 'GetUser'.". GetUser internally calls GetAuthenticatedUser. For further understanding and extension please refer to the blog at Enabling Federated Identity in Wcf Ria Services by Robert O'Brien.


1.       Create Virtual Directory for the WCF service-

a.       In the machine (on-premise) where this service is to be deployed, run the visual studio under the administrator privilege. Open the solution and go to the properties of the project having the WCF service declaration.

b.      Go to the "Web" tab:


c.       Select "Use Local IIS Web server", with proper project url and click "Create Virtual Directory"

2.       Enable auto-start-

a.       Once the Azure SDK installed, copy the ServiceBus_schema.xml file from <installation folder>\Labs\IntroServiceBus2010Part1\Source\Assets

to %SystemRoot%\System32\inetsrv\config\schema directory. Make sure to keep a copy of the old one (if any) so that if needed could be reverted back to the old file.

b.      Open IIS manager and navigate to the virtual directory created:


c.       On the right, from the Actions section click "Configure":


d.       In the "Configure WCF and WF for Application" window, select the "Auto-Start" from left and "Custom" from the right:


e.       Click Apply and then "Yes" on the subsequent message box.

f.      Click "OK" and then double click on the Services option:


g.       From the center panel, select the service and then click "Configure":


h.       In the "Configure Service" window select "Enable" for Auto-Start:


i.       And once applied, reset IIS:



Suppose we need to expose the url i.e.  just http://<sevice-namespace> e.g. to expose client access policy file through services bus. Then once the base url (as mentioned earlier) is registered, for any further url registration like http://<sevice-namespace><service-name>/ appfabric will through the below mentioned error message even if the url is tried to register for the first time.

The specified address already exists.Address sb://<namespace><service name>/ already in use.

 So the resolution is, if needed then first register url like http://<sevice-namespace><service-name>/ and then only register the url http://<sevice-namespace> for any appfabric service namespace. 


1.       From the Azure Management Portal, for the concerned subscription, select the "Service Bus, Access Control and Caching":            

13.png            2.       Once project in the AppFabric details page, add a new service namespace:


3.       Provide a namespace (e.g. servicesandsupport) and select the region suiting the project:




4.       Once the namespace is activated, click on it to get its details on the right:




5.       In the property panel scrol down and click on the "View" button in the Deafult key section:



6.       Make a note of the Service Namespace, Default Issuer Name and Default Issuer Key:





using System;

using System.Collections.Generic;
using System.Linq;
using System.Web;

using System.ServiceModel.Configuration;
using Microsoft.ServiceBus;
using System.Configuration;

namespace <namespace>
    public class ServiceRegistrySettingsElement : BehaviorExtensionElement
        private const string displayNameId = "displayName";
        private const string discoveryModeId = "discoveryMode";

        public override Type BehaviorType
            get { return typeof(ServiceRegistrySettings); }

        protected override object CreateBehavior()
            return new ServiceRegistrySettings()
                DiscoveryMode = this.DiscoveryMode,

        [ConfigurationProperty(discoveryModeId, DefaultValue = DiscoveryType.Private)]
        public DiscoveryType DiscoveryMode
            get { return (DiscoveryType)this[discoveryModeId]; }
            set { this[discoveryModeId] = value; }

        public string DisplayName
            get { return (string)this[displayNameId]; }
            set { this[displayNameId] = value; }




There is no Appendix D?

Thanks for identifying. It was missed. I have added it now.

I failed to discover the service by adding service reference. Are there more steps required. If my client knows the endpoint and security key then it successfully the service is accessed.

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

Please key in the two words you see in the box to validate your identity as an authentic user and reduce spam.