Solved: WWAHost.exe remote endpoint was not reachable error in JavaScript Windows Store App

I was working on my office machine. While working I opened a JavaScript based Windows Store Application. When I tried to run application I got following exception,

image

I was baffled due to this exception. After sort of research I found that I was on VPN. I have no idea why on VPN this exception occurred. But to get rid of this exception you need to follow these two steps

  1. Closed all connections to VPN
  2. Restart machine

After performing above two steps you should not get above exception. I hope this quick post is useful. Thanks for reading.

Solved Exception in Passing Relative URI to Windows Runtime

While working today on a Windows Store Application I had a requirement to work with URI. Business class was as follows,

 

image

And I created instance of Product class in usual way setting values for both properties. I had put all images in ProductImages folder.

 

image

 

On running application I got following exception that given System.Uri cannot be converted.

image

 

After small research I found that WinRT does not support Relative URI. It only supports Absolute URI.

 

image

 

Now I fixed above problem by converting Relative URI to Absolute URI.

 

image

 

Exception got fixed after changing URI as absolute URI. I hope you find this quick fix useful. Thanks for reading.

Four Steps to create first WCF Service: Beginners Series

image

This post is for beginners who are starting in WCF. I will be focused and help you to create and consume first WCF Service in simplest steps. We will follow steps as following,

image

At the end of this post you should able to create first WCF Service and consume that in a Console Application. I will keep adding further posts in this series to make WCF easier for you.

Project setup

  1. Launch any edition of Visual Studio 2010 or 2012.
  2. Create a project by choosing WCF Service Application project template from WCF tab.
  3. Delete default created IService1.cs and Service1.svc file.

Step 1: Create Service Contract

To create a Service Contract,

  1. Right click on project and add New Item
  2. From Web tab choose WCF Service to add.
  3. Let us give Calculator.svc name of service.

image

Next you need to perform following tasks,

  1. Open ICalculator.cs and remove void DoWork() function.
  2. Make sure attribute of Interface is set as [ServiceContract]
  3. Define functions you want to create as part of Contract
  4. Set Attribute of functions as [OperationContract]

You will create ICalculator Service Contract with four basic calculator operations as following,

ICalculator.cs


using System.ServiceModel;

namespace fourstepblogdemo
{

 [ServiceContract]
 public interface ICalculator
 {
 [OperationContract]
 double AddNumbers(double number1, double number2);
 [OperationContract]
 double SubstractNumbers(double number1, double number2);
 [OperationContract]
 double MultiplyNumbers(double number1, double number2);
 [OperationContract]
 double DivisionNumbers(double number1, double number2);

}
}

Above you have created a Service Contract with four Operation Contracts. These contracts will be part of Service Contract and exposed to clients. By this step you have created ICalculator Service Contract.

Step 2: Expose Endpoints with Metadata

In this step you need to expose Endpoints and Metadata of service. To do this open Web.config file. We are going to create one Endpoint with basicHttpBinding. We are adding metadata Endpoint also to expose metadata of service. We need metadata at the client side to create proxy.


<services>
 <service name="fourstepblogdemo.Calculator">
 <endpoint address="" contract="fourstepblogdemo.ICalculator" binding="basicHttpBinding"/>
 <endpoint address="mex" contract="IMetadataExchange" binding="mexHttpBinding"/>
 </service>
 </services>


Step 3: Implement Service

In this step we need to implement service. To implement service open Calculator.svc and write codes to implement functions is defined in ServiceContract ICalculator.cs. Delete implementation of DoWork function from Calculator.svc and implement services as following

Calculator.svc.cs

namespace fourstepblogdemo
{
 // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Calculator" in code, svc and config file together.
 // NOTE: In order to launch WCF Test Client for testing this service, please select Calculator.svc or Calculator.svc.cs at the Solution Explorer and start debugging.
 public class Calculator : ICalculator
 {

public double AddNumbers(double number1, double number2)
 {
 double result = number1 + number2;
 return result;
 }

public double SubstractNumbers(double number1, double number2)
 {
 double result = number1 - number2;
 return result;
 }

public double MultiplyNumbers(double number1, double number2)
 {
 double result = number1 * number2;
 return result;
 }

public double DivisionNumbers(double number1, double number2)
 {
 double result = number1 / number2;
 return result;
 }
 }
}


As of now you have created Service and configured Endpoint. Now you need to host service. There are many processes in which a WCF Service can be hosted. Some processes are

  • Managed Application
  • IIS
  • ASP.Net Web Server
  • Windows Service
  • App Fabric

In this post we are not going into details of WCF Service hosting and we will consider simplest hosting option. Let us host service in ASP.Net Web Server. To host press F5 in visual studio.

In browser you can see Service as following.

image

To view metadata of Service click on URL of wsdl. You may notice that Service is hosted on localhost.

image

Step 4: Consume Service

There are various ways a WCF SOAP Service can be consumed in different kind of clients. In this post we will consume service in a Console Application. Launch Visual Studio and create Console Application project.

Now there are two ways you can create proxy at client side.

  1. Using svcuitl.exe at command prompt
  2. By adding Service Reference

In this post we will create proxy at client side using Add Service Reference. In Console Project right click on Reference and select option of Add Service Reference. In Add Service Reference dialog copy paste address of Service or if WCF Service and Console Client project is in same solution then click on Discover. If there is no error in Service then you will find Service Reference added as given in following image. If you want you can change name of Reference. I am leaving here default name ServiceReferenc1.

image

You can consume service at client as following,

  1. Create instance of proxy class
  2. Call different operations from service

You can create instance of proxy class as following

image

And let us say you want to make a call to Add function. That can be done as following

image

So at client side you can call all four functions of Calculator Service as following


using System;
using ConsoleClient.ServiceReference1;

namespace ConsoleClient
{
 class Program
 {
 static void Main(string[] args)
 {

CalculatorClient proxy = new CalculatorClient();

double addResult = proxy.AddNumbers(9, 3);
 Console.WriteLine("Result of Add Operation");
 Console.WriteLine(addResult);
 double subResult = proxy.SubstractNumbers(9, 3);
 Console.WriteLine("Result of Substract Operation");
 Console.WriteLine(subResult);

double mulResult = proxy.MultiplyNumbers(9, 3);
 Console.WriteLine("Result of Multiply Operation");
 Console.WriteLine(mulResult);

double divResult = proxy.MultiplyNumbers(9, 3);
 Console.WriteLine("Result of Division Operation");
 Console.WriteLine(divResult);

Console.ReadKey(true);
 }
 }
}

Press F5 to run Console Client Application. You will get desired result.

image

Just now you have create a Calculator WCF Service and consumed that in a Console Application. In further posts I will simplify other concepts for WCF for beginners. I hope you find this post useful. Thanks for reading.

Windows Azure Blog Posts 100 Not Out

image

I love Windows Azure. I have been growing as professional with Windows Azure. I am excited as kid writing this and informing you that yea I have blogged more than 100 posts on Windows Azure.

Read All Windows Azure Blog Posts here

image

I wrote first blog posts on Windows Azure back on 16th November 2009 with following title

Step by Step walkthrough to create first application for cloud (Windows Azure)

And my latest blog post on Windows I wrote today morning. It is on Windows Azure Mobile Service

Fetching Windows Azure Mobile Services Data in XAML based Windows Store Application

In my journey to 100+ blog posts I touched upon all part of Windows Azure like Windows Azure Hosted Services, Table, Queues, Blobs, SQL Azure, and Windows Azure Mobile Services etc. I am very happy seeing Windows Azure is progressing as platform. Recent addition of Active Directory on Windows Azure is one of my favourite. I try to see Windows Azure always as developer. I put developer touch in Windows Azure. I have authored many posts like exposing Management API operations as WCF SOAP Service etc. I am committed to continue writing on Windows Azure along with other technologies.

Read All Windows Azure Blog Posts here

I complete this post by thanking my readers. Long live Windows Azure. Let us go on cloud way.

Fetching Windows Azure Mobile Services Data in XAML based Windows Store Application

In last post we started learning about Windows Azure Mobile Service in XAML based Windows Store Application. Read it here

In last post we learnt

  • Configuring Window Azure Mobile Service in portal
  • Consuming Windows Azure Mobile Service in Windows Store Application
  • Insert a record from application in Windows Azure Mobile Service data table.

In this post we will take a look on fetching records from table. I recommend you to follow Part 1 of this series here . I will start from where I left in part 1.

Let us design application page. There are two buttons. On click of first button we will fetch all data. On click of second button filtered data will fetched. Let us design application page as following


<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}" >
 <Grid.RowDefinitions>
 <RowDefinition Height="*" />
 <RowDefinition Height="*" />

 </Grid.RowDefinitions>

<StackPanel Orientation="Vertical" Grid.Row="0">
 <Button x:Name="btnFetch" Click="btnFetch_Click_1" Content="Get Data" Height="72" Width="233"/>
 <GridView x:Name="lstBloggers" >
 <GridView.ItemTemplate>
 <DataTemplate>
 <StackPanel Orientation="Horizontal">
 <TextBlock Text="{Binding Name}" />
 <TextBlock Text="{Binding Technology}" />
 </StackPanel>
 </DataTemplate>
 </GridView.ItemTemplate>
 </GridView>
 </StackPanel>
 <StackPanel Orientation="Vertical" Grid.Row="1">
 <StackPanel Orientation="Horizontal">
 <TextBox x:Name="txtSearch" Height="59" Width="436" />
 <Button x:Name="btnFilterfetch" Click="btnFilterfetch_Click_1" Content="Get Filtered Data" Height="72" Width="233"/>
 </StackPanel>
 <ListView x:Name="lstFilterBloggers" Margin="368,20,271,-599">
 <ListView.ItemTemplate>
 <DataTemplate>
 <StackPanel Orientation="Horizontal">
 <TextBlock Text="{Binding Name}" />
 <TextBlock Text="{Binding Technology}" />
 </StackPanel>
 </DataTemplate>
 </ListView.ItemTemplate>
 </ListView>
 </StackPanel>
 </Grid>

Yes this is not one of the best UI we can create but any way creating highly immersive UI is not purpose of this post. Right now UI will look like below image

image

Now to fetch all the records you need to follow following steps

Define Global variables


MobileServiceClient client;
 MobileServiceCollectionView<TechBloggers> items;
 MobileServiceCollectionView<TechBloggers> filteredItems;
 IMobileServiceTable<TechBloggers> bloggerstable;


You need to create mobile service table client in application. That can be created as following


public MainPage()
 {
 this.InitializeComponent();
 MobileServiceClient client = new MobileServiceClient("https://youappurl", "appkey");
 bloggerstable = client.GetTable<TechBloggers>();

 }

&nbsp;

Next you need to create entity class representing table from the Windows Azure Mobile Service. Let us create entity class as following. We are creating entity class TechBloggers.


public class TechBloggers
 {
 public int id { get; set; }
 [DataMember(Name="name")]
 public string Name { get; set; }
 [DataMember(Name = "technology")]
 public string Technology { get; set; }

}

On click event of button you can fetch all data from Mobile Service Table as following


private void btnFetch_Click_1(object sender, RoutedEventArgs e)
 {

items = bloggerstable.ToCollectionView();
 lstBloggers.ItemsSource = items;

}

You can fetch filtered data as following. We are filtering data on search term given in textbox.

private void btnFilterfetch_Click_1(object sender, RoutedEventArgs e)
 {
 filteredItems = bloggerstable.Where
 (blogger => blogger.Technology == txtSearch.Text)
 .ToCollectionView();
 lstFilterBloggers.ItemsSource = filteredItems;

 }

&nbsp;

When you run application you will find all data and filtered data as following

image

In this way we can fetch data from Windows Azure Mobile Service. In next post we will get into update and deletion of record. I hope this post useful. Thanks for reading.

Multiple WCF EndPoints are not only about having Multiple Addresses Dude!

I read astronomical blogs on Multiple EndPoints in WCF. As a reader I find some way of ambiguity in author’s explanation to this relatively easy topic. In this post my agenda is very simple. I will not use any code or jargon to explain you multiple EndPoints. I am trying to let you understand Multiple EndPoints with simple mathematical formula.

Mathematically we can formulate EndPoint as below,

image

Where A, B and C are as follows,

image

Now it is simple mathematical addition rule that if we change any of A, B or C value then we will get new E.

image

We may have multiple EndPoints of same service in any of the following scenario,

  1. Same Service hosted on Multiple Address with same Binding and same Contract.
  2. Same Service with different Contract on same Address and for same Binding.
  3. Same Service with different Bindings on same Address and for same Contract.

To map concept of Multiple EndPoints with real world scenario then assume a business case.

  • You have a WCF Service
  • For Intranet User you do not want authentication
  • For Internet User you want authentication
  • You want Service to be hosted on same base address

In above scenario

  1. You need to have different bindings for Intranet client and Internet client.
  2. You can have basicHttpBinding for Intranet user
  3. You can have wsHttpBinding for Internet user.

Now in above business case you have same Service hosted on same Address with same Contract but with two different Bindings. Essentially you have two EndPoints for the same Service serving two different purposes.

I hope in this post I was able to explain you basic theory behind Multiple EndPoints. Thanks for reading.

Getting Started with Windows Azure Active Directory

On 8th April 2013 Microsoft announces general availability of Active Directory on Windows Azure.

Read Product Team Blog here

image

To start working with Windows Azure Active Directory login to portal. In the side bar you will get option of Active Directory as shown in below image,

image

On clicking of Active Directory you will get message that no Active Directory being created so far. To create click on CREATE YOUR DIRECTORY

image

In next screen you need to provide

  • Domain name
  • Choose Country or region from drop down.
  • Organization name

image

After successful creation of Active Directory you can perform following four operations on that

  • Working with Users
  • Working with Apps
  • Working with Domains
  • Working with Directory Integration

On User tab you will see there is no User added. You can add users to directory by clicking on ADD USERS in bottom

image

On next screen you need to provide type of user and User Name. Among two types of users you can choose from drop down

  • New User in Organisation
  • User with Existing Microsoft Account

image

Now you need to create User Profile. Here you need to provide First Name, Last Name, Display Name and Role of user. There are two types of roles available

  • User
  • Global Administrator

image

This is last step of creating user. You can configure temporary password and send it on alternative Email of newly added user.

image

Once user is successfully added you can view user in Grid on selecting User tab.

image

I am very excited with public availability of Active Directory on Windows Azure. In further posts I will discuss more on Windows Azure Active Directory platform. I hope you find this post useful. Thanks for reading.

Step by Step working with Windows Azure Mobile Service Data in JavaScript based Windows Store Apps

In my last post I discussed Step by Step working with Windows Azure Mobile Service Data in XAML based Windows Store Apps . In this post we will have a look on working with JavaScript based Windows Store Apps. Last post was divided in two parts. First part was Configure Windows Azure Mobile Service in Portal. You need to follow step 1 from last step to configure Windows Azure Mobile Service Data. To work with this proceed as given in following steps,

  1. Configure Windows Azure Mobile Service in Portal. For reference follow Step 1 of this Blog
  2. Download Windows Azure SDK and install.

Now follow post to work with Windows Azure Mobile Service Data from JavaScript based Windows Store Application.

Create Windows Store Application in JavaScript

Create Blank App from creating Blank App template from JavaScript Windows Store App project tab.

image

After creating project add Windows Azure Mobile Services JavaScript Client reference in project.

image

After adding reference let us go ahead and design app page to add a blogger in table. We are going to put two text boxes and one button. On click event of the button blogger will be inserted as row in data table of Windows Azure Mobile Services.


<body>

 <h2>Adding Record to Windows Azure Mobile Service Data</h2> <br />
 Name : <input id="txtname" type="text" /> <br />
 Technology : <input id="txttechnology" type="text" /> <br /> <br />
 <button id="btnInsert" >Insert Blogger</button>

</body>

Application will look like following,

image

We need to add reference of Windows Azure Mobile Service on HTML as following


<script src="//Microsoft.WinJS.1.0/js/ui.js"></script>
 <script type="text/javascript" src="/MobileServicesJavaScriptClient/MobileServices.js"></script>

Next let us create client for Windows Azure Mobile Service. To create this you need to pass application URL and application Key. Client in JavaScript based application can be created as following


args.setPromise(WinJS.UI.processAll());
 var client = new Microsoft.WindowsAzure.MobileServices.MobileServiceClient(
 "https://appurl",
 "appkey"
 );

Now let us create a proxy table. Proxy table can be created as following and after creating proxy table we can add record in table as following


var bloggerTable = client.getTable('techbloggers');

var insertBloggers = function (bloggeritem) {

bloggerTable.insert(bloggeritem).done(function (item) {
 //Item Added
 });

On click event of button we need to call insertBloggers javascript function.

btnInsert.addEventListener("click", function () {
 insertBloggers({
 name: txtname.value,
 technology: txttechnology.value
 });
 });

On click event of button you should able to insert blogger in Windows Azure Mobile Service Data table. In further post we will learn to perform update, delete and fetch data. I hope you find this post useful. Thanks for reading.

Step by Step working with Windows Azure Mobile Service Data in XAML based Windows Store Apps

In this post we will take a look on working with Windows Azure Mobile Service in XAML based Windows Store Application. We will follow step by step approach to learn goodness of Windows Azure Mobile Service. In first part of post we will configure Windows Azure Mobile Service in Azure portal. In second part of post we will create a simple XAML based Windows Store application to insert records in data table. This is first post of this series and in further posts we will learn other features of Windows Azure Mobile Services.

Configure Windows Azure Mobile Service on Portal

Step 1

Login to Windows Azure Management Portal here

Step 2

Select Mobile Services from tabs in left and click on CREATE NEW MOBILE SERVICE

image

Step 3

In this step provide URL of mobile service. You have two choice either to create mobile service in existing database or can create a new database. Let us go ahead and create a new database. In DATABSE drop down select option of Create New SQL database instance. Select SUBSCRIPTION and REGION from drop down as well.

image

Step 4

On next screen you need to create database. Choose either existing database server or create a new one. You need to provide credential to connect with database servers.

image

Step 5

After Successful creation of mobile services you need to select platform. Let us go ahead and choose Windows Store as platform

image

Step 6

After selecting platform click on Data in menu. After selecting Data click on ADD A TABLE

image

Next you need to provide Table name. You can provide permission on table. There are three options available

  1. Anybody with Application Key
  2. Only Authenticated Users
  3. Only Scripts and Admins

Let us leave default permission level for the table.

image

Step 7

Next click on tables. You will be navigated to table dashboard. When you click on Columns you will find one default created column id. This column gets created automatically. This column must be there in Windows Azure Mobile Service table.

image

On enabling of dynamic schema when you will add JSON objects from client application then columns will get added dynamically.

Create Windows Store Application in XAML

Very first you need to install Windows Azure SDK for Windows Phone and Windows 8.

image

After installing create a Windows Store Application by choosing Blank App template.

image

Before we move ahead to create Windows Store App let us go back to portal and mange App URL and key. You need key and application URL to work with Windows Azure Mobile Services from Windows Store application. You will find key and application URL at the portal.

image

Now go ahead and add following namespaces on MainPage.xaml.cs


using Microsoft.WindowsAzure.MobileServices;
using System.Runtime.Serialization;

Next you need to create entity class representing table from the Windows Azure Mobile Service. Let us create entity class as following. We are creating entity class TechBloggers.


public class TechBloggers
 {
 public int id { get; set; }
 [DataMember(Name="name")]
 public string Name { get; set; }
 [DataMember(Name = "technology")]
 public string Technology { get; set; }

}

After creating entity class go ahead and global variables.


MobileServiceClient client;
 IMobileServiceTable<TechBloggers> bloggerstable;

Once global variable is defined in the constructor of page you need to create instance of MobileServiceClient and MobileServiceTable. Let us go ahead and create that in constructor of the page.


public MainPage()
 {
 this.InitializeComponent();
 MobileServiceClient client = new MobileServiceClient("https://youappurl", "appkey");
 bloggerstable = client.GetTable<TechBloggers>();

 }

Now let us go back and design app page. On XAML let us put two textboxes and one button. On click event of button we will insert bloggers in the table.


<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}" >
 <Grid.RowDefinitions>
 <RowDefinition Height="100" />
 <RowDefinition Height="100" />
 <RowDefinition Height="100" />
 </Grid.RowDefinitions>
 <StackPanel Grid.Row="0" Orientation="Horizontal" Margin="40,40,0,0">
 <TextBlock Text="Name" FontSize="40" />
 <TextBox x:Name="txtName" VerticalAlignment="Top" Width="400" />
 </StackPanel>
 <StackPanel Orientation="Horizontal" Grid.Row="1" Margin="40,40,0,0">
 <TextBlock Text="Technology" FontSize="40" />
 <TextBox x:Name="txtTechnology" VerticalAlignment="Top" Width="400" />
 </StackPanel>

 <Button Grid.Row="2" x:Name="btnInsert" Click="btnInsert_Click_1" Content="Insert Record" Height="72" Width="233" Margin="248,42,0,-14" />

 </Grid>

Application will look like as given in below image. I know this is not best UI. Any way creating best UI is not purpose of this post

image

On click event of button we can insert a record to table using Windows Azure Mobile Services using following code


private void btnInsert_Click_1(object sender, RoutedEventArgs e)
 {

TechBloggers itemtoinsert = new TechBloggers
 {
 Name = txtName.Text,
 Technology = txtTechnology.Text
 };

InserItem(itemtoinsert);

}

InsertItem function is written like following,

private async void InserItem(TechBloggers itemtoinsert)
 {

await bloggerstable.InsertAsync(itemtoinsert);

 }

On click event of button you can insert records in Windows Azure Mobile Service data table. To verify inserted records browse to portal and click on table.

image

In further posts we will learn update, delete and view of the records. I hope you find this post useful. Thanks for reading.

Got Microsoft Most Valuable Professional award 4th times in a row

image

Read more about MVP award program here

Since 2010 1st April is very important day for me. I wait for this day to recreate my trust in saying “Good work does not go unnoticed”. I work with developers, write blogs, and speak in user groups, conferences whole years. Being a human I feel happy and very happy when Microsoft recognise my work. It gives me motivation to get going.

Yes I am getting older now. This is fourth times in a row Microsoft says “I am their Most Valuable Professional

My last year contribution [1st April 20012 to 31st March 2013] is as follows’,

clip_image002

clip_image003

I hope I was useful to developers and helped them to bring best out of them. I thank each one of you who supported me. I am committed to work harder and I would try to be more useful to you.

Thanks.

/DJ

In between where is party tonight? …..