Positive Affirmations WCF Service & Azure Cloud Services Hosting & Client “Tester” Windows Form Application


This project presents a simple WCF Positive Affirmations Service that demos architectural styles of setting up, hosting via Azure Cloud Services, configuring services, and testing the service for http protocols. The service accepts a simple string, which represents a name, and returns a simple string with a randomized positive affirmation that acknowledges the name.  Instead of using IIS Express, the simple service is hosted using Azure Cloud Services. The Visual Studio solution also has one client “tester” Windows Form application that tests the http protocol connection to the hosted service.


The demo project consists of these component topics:

  • PositiveAffirmationsWCFServiceWebRole Class Library for Cloud Service
    • IPositiveAffirmationService (Interface for Service)
    • PositiveAffirmationService (Code that Implements the Service Interface)
  • MyAzureWCFServiceDemo “Service Host” Azure Cloud Service
    • Configuration Settings for Hosting the Service
    • Cloud Publishing Settings
  • TestClientGUI “Tester to Service” Windows Form Application
    • Connected Service “Proxy Reference”
    • Simple Program to test the service @ http endpoint

Windows Azure Cloud Service Project Template

A Windows Azure Cloud Service project template (a project that creates a scalable service that runs on Windows Azure) was selected in Visual Studio. In template wizard, the WCF Service Web Role was selected for WCF services and named “PositiveAffirmationsWCFServiceWebRole”.  The template process completed with the creation of two separate projects: the “WCF Service Web Role” and the “Cloud Service Project” (MyAzureWCFServiceDemo).

Positive Affirmations “PositiveAffirmationsWCFServiceWebRole” Service Library

The “WCF Service Web Role” project looks very similar to the “WCF Service Application” template, but customized for Cloud. There is a service interface “IPositiveAffirmationService” and a class “PositiveAffirmationService” that implements the service interface. The code is available on GitHub [here].

IPositiveAffirmationService (Interface for Service)

The ServiceContract for the Simple Greeting service has only one OperationContract: a method called “AffirmMe” that accepts a string representing a name. The “AffirmMe” returns string to the caller that includes a positive affirmation plus the name. The code is available on GitHub [here].

PositiveAffirmationService (Code that Implements the Service Interface)

The service implementation code details the “AffirmMe” method. It returns a simple string containing a positive affirmation plus the name that the caller sent. A list of approximately 30 positive affirmations are loaded into memory when the service spins up with a random number generator. When the service is called, it randomly returns an item from the list of positive affirmations along with a personalized message to return to the caller.

After my first attempt of publishing the service and accessing the service, I realized that I was receiving ASP.NET incompatibility errors in both the web browser and my proxy connection via the Client Tester application. The solution was to include a class level attribute:

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]

The code is available on GitHub [here].

MyAzureWCFServiceDemo “Service Host” Azure Cloud Service Project

Instead of hosting with IIS Express, the Positive Affirmations Service is hosted and managed via Azure Cloud Services with specific ports, configuration, endpoints, etc. to allow access via http protocol (suited for Internet traffic). The cloud service project is published to and managed via a Windows Azure Portal that starts, stops, and monitors the service. The project includes publishing and configuration settings for the cloud service. After the solution is built without errors, it can be deployed to the cloud using Visual Studio Build à Publish. Note: The cloud project must be selected for the Publish option to be visible under the Build menu options. The user will then be prompted to login to their Azure account and confirm the publishing settings.

The code is available on GitHub [here].

HttpClient “Tester to Service” Windows Form Application (TestClientGUI)

The HttpClient “tester to service” is a simple windows form application project in the same solution that connects to the “Positive Affirmations Service” by use of a proxy generated by SVCUTIL. The client program will use this proxy and the http protocol to test the OperationContract or method available in the ServiceContract and return the results to the user on the GUI.

The code is available on GitHub [here].

Connected Service “Proxy Reference” MyAffirmServiceRef

I used the simple “Add Service Reference” wizard to create a Service Reference to the client tester project. The existing “Positive Affirmations” Azure Cloud Service had to be already published and running for the SVCUTIL wizard to be able to connect to the metadata exchange via the base address provided and add a service reference to my client. Note: the base address provided was specific to the http protocol. For the http client, the metadata would be available after entering this address into the wizard:


The client was able to then recognize the Positive Affirmations Azure Cloud Service and build the service reference using the exposed meta-exchange data “WSDL”. The auto-generated code is available on GitHub [here].

Note: There is no warranty that this service is still currently running and available. This service was created for a demo project only under a student Azure subscription that has an expiration date.

Main Form Program

The main form program in the client “tester” windows form application creates a proxy using the service reference that was previously created using the wizard, to connect to the simple positive affirmations service. Since there is one service endpoint (http), the proxy does not need to specify the specific endpoint name on the service as it relates to the protocol.

PositiveAffirmationServiceClient proxy = new PositiveAffirmationServiceClient();

Good to Know – Endpoints and Client Implementations

The service could also be implemented using the https protocol, and it in that case, the endpoint would have to be specified in the constructor above. The endpoint name for the specific endpoint differentiates the specific protocol (ex: https). The default endpoint name is available in the app configuration file on the service host, so the client has to be aware of the endpoints. They can also learn this from the metadata exchange or WSDL on the service. The correct endpoint name for the protocol must be specified in the creation of the proxy to use that protocol if it not the default.

Testing the Service

After the proxy is setup, the tester windows form application loads the GUI and allows the user to enter their name. After they click the button “AffirmMe”, the program then makes a request to the service (instancing the proxy) passing their name as a string parameter. After it receives the response from the service, it outputs the result as a string to the text box on the form. If it cannot connect to the service or fails, it will say so in the text box on the GUI. The result is a personalized positive affirmation to the user who requested the service. The code is available on GitHub [here].

Azure Cloud Demo

The following are screen captures taken from my Azure Portal that manages the resource for the service.

Client “Tester” Demo


The entire project code repository is available on GitHub [here].

Kathleen has 15 yrs. of experience analyzing business IT needs and engineering solutions in payments, electric utilities, pharmaceutical, financial, virtual reality, and internet industries with a variety of technologies. Kathleen's project experience has been diverse ranging from executing the business analysis “design phase” to hands-on development, implementation, and testing of the IT solutions. Kathleen and her husband reside in Indiana with no children, instead living along with their fur babies.