//Cloud notes from my desk -Maheshk

"Fortunate are those who take the first steps.” ― Paulo Coelho

[Azure Batch] Server failed to authenticate the request

Today happen to work on this problem, where developer running unit test code creating Azure Batch Jobs in row and check the status in a tight loop getting forbidden error. Interestingly, it worked for him for the first couple of calls “job” creation but fails continuously after that in row. Grabbed the the fiddler log to see the request and response and noticed something as like below. 

Fiddler trace:

HTTP/1.1 403 Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.

Content-Length: 864

Content-Type: application/json;odata=minimalmetadata

Server: Microsoft-HTTPAPI/2.0

request-id: fd81d621-xxxxx-b252-1db46324f1a6

Strict-Transport-Security: max-age=31536000; includeSubDomains

X-Content-Type-Options: nosniff

DataServiceVersion: 3.0

Date: Tue, 13 Dec 2016 15:51:34 GMT

Cache-Control: proxy-revalidate

Proxy-Connection: Keep-Alive

Connection: Keep-Alive



    “lang”:”en-US”,”value“:”Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.nRequestId:xxxxx-564c-4930-xxx-xxxnTime:2016-12-13T15:51:34.2917937Z”



      “key”:”AuthenticationErrorDetail“,”value“:”The MAC signature found in the HTTP request ‘6nxk/xxxxxx/xmdrWt55RnMRmsg=’ is not the same as any computed signature. Server used following string to sign: ‘GETnnnnnnnTue, 13 Dec 2016 15:42:18 GMTnn0x8D4236E9EB80606nnnocp-date:Tue, 13 Dec 2016 15:51:35 GMTn/xxxxx/jobs/deleteJob0napi-version:2016-07-01.3.1’.”





This appears to be some kind of caching – https://social.msdn.microsoft.com/Forums/SqlServer/en-US/67183d62-60ab-4ef0-a1ca-b765d85ea2f6/authenticationfailed?forum=azurebatch.  It is caused by client-side caching at the proxy layer. Usually the proxy server at client side caches the get responses and for subsequent gets proxy server will try to serve the request from its cache. It sends a different request to server by adding If-Match header with the ETag. However, this causes a problem in this case because the proxy server does not change the Authorization header, it uses the same Auth header that client sends. Hence, the auth header that client sends does not match what server expects.


Added the below config value to App.Config file which resolved this issue. He was able to continue execute his test harness by submitting/deleting 10 jobs successfully without caching issues.


    <requestCaching defaultPolicyLevel=”NoCacheNoStore“/>

Hope this helps.

2016-12-20 Posted by | Azure, Azure Batch, C#, VS2015 | | Leave a comment

Quick tip on Service Fabric Remoting service development

Azure Service Fabric needs no introduction. It is our next gen PaaS offering or also called PaaS v2. It’s been used internally for many years, tested and released as SDK for consumption. Some of the well known offerings like Az Sql, Az DocDB, Skype etc runs on Service Fabric. We already see developer community consuming for their production and hearing lot of goodness.

It is free, any one can download the SDK, develop and run from their laptop or own data center or publish to Azure. It works on windows and Linux as well. It has lot of rich features over the previous PaaS offerings (cloud services) so seeing lot of traction from big companies considering for critical application.

This sample is based on this example:-https://azure.microsoft.com/en-us/documentation/articles/service-fabric-reliable-services-communication-remoting/ 

Service side proj settings: Set the platform target as x64 If you want to use reliable collections, reliable actors APIs, failing to have this set throws as binding exception as below.

System.BadImageFormatException was unhandled
  FileName=Microsoft.ServiceFabric.Services, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35
  FusionLog=Assembly manager loaded from:  C:WindowsMicrosoft.NETFrameworkv4.0.30319clr.dll
Running under executable  D:Cases_CoderemotingclienttestbinDebugremotingclienttest.vshost.exe
— A detailed error log follows.






For client side/calling method, I do not see set up related information in detailed here https://azure.microsoft.com/en-us/documentation/articles/service-fabric-reliable-services-communication-remoting/. I found, these 3 dll’ s has to be referred at client side project for consuming service. I simply copied from service side sample packages folder to calling side proj folder.





sample code available – https://1drv.ms/u/s!ApBwDDnGdg5BhNd-KQHtWtaH-sbRcA

2016-11-13 Posted by | .NET, Azure Dev, C#, Microservices, PaaS, ServiceFabric, VS2015 | | Leave a comment

How to get the connection string for Redis Cache using Azure Redis Mgmt Library

Recently I had this query from an Azure developer asking sample ARM template for creating Redis cache and then get the connection string from the created cache so to pass it to our next resource creation say Azure WebApps . End to end in single ARM template.  I have explored few samples in Github but could not find any end-to end sample to get this done. The one important part is not very clear for me, how to make REST API call within ARM template to get the accesskey for the newly created cache. And the last part about how to play around with strings to create the qualified ConnectionString from the fragmented REST response. I felt quite challenging to get this all done using ARM template without any sample to refer. More importantly I did not find any documentation around ARM capabilities. But I am sure there must be some way to do this by invoking PS or external scripts etc.

Problem statement: 1) Create or update the Redis Cache 2) Get the list of cache and its Access Key 3) Use the details and create the fully qualified ConnectionString

Possible options: Portal/Powershell/CLI/SDK’s. I chose to go .NET way using Azure Redis Management Library 1.2.1(preview)https://www.nuget.org/packages/Microsoft.Azure.Management.Redis/1.2.1-preview.

Here is the code address the problem,

using System;
using Microsoft.Azure;
using StackExchange.Redis;
using Microsoft.Azure.Management.Redis;
using Microsoft.Azure.Management.Redis.Models;
using Microsoft.IdentityModel.Clients.ActiveDirectory;

//Using ADAL library 2.28 to avoid Async complexities
//Using StackExchange Redis dll to resolve "ConfigurationOptions" Dependency

namespace ConsoleApplication1
    class Program
        static void Main(string[] args)
            string resourcegroupName = "";
            string cacheName = "";
            string subscriptionId = "";
            string location = "";
            string token = string.Empty;
            string tenantId = "";

            //get the bearer token from AAD by passing your tenantID
            token =GetAuthorizationHeader(tenantId);

            TokenCloudCredentials creds = new TokenCloudCredentials(subscriptionId, token);
            RedisManagementClient redisclient = new RedisManagementClient(creds);

            Console.WriteLine("Do you want to create or update the Redis Cache [y/n]?");
            ConsoleKeyInfo consoleKeyInfo=Console.ReadKey();

            if (consoleKeyInfo.Key.ToString().ToLower() == "y")
                var redisProperties = new RedisProperties();
                redisProperties.Sku = new Sku("Basic", "C", 1);
                var redisParams = new RedisCreateOrUpdateParameters(redisProperties, location);
                //Create or update the existing cache
                redisclient.Redis.CreateOrUpdate(resourcegroupName, cacheName, redisParams);

            //List all the caches under the given resourcegroupname
            RedisListResponse listresponse = redisclient.Redis.List(resourcegroupName);

            string connectionString = string.Empty;
            string existingcachename = string.Empty;
            string existingcachehostname = string.Empty;
            string existingcachepkey = string.Empty;

            foreach (RedisResource redisresource in listresponse.Value)
                Console.WriteLine("DISPLAY EXISTING CACHE..................n");
                existingcachehostname = redisresource.Properties.HostName;
                Console.WriteLine("Redis cachename:"+ existingcachehostname);
                existingcachename = redisresource.Name;
                Console.WriteLine("Redis hostname:" + existingcachename);
                Console.WriteLine("Redis redisversion:" + redisresource.Properties.RedisVersion);
                Console.WriteLine("Redis ProvisioningState" + redisresource.Properties.ProvisioningState);

                //RedisGetResponse response = redisclient.Redis.Get(resourcegroupName, existingcachename);
                Console.WriteLine("PRINTING KEYS..................n");
                RedisListKeysResponse redislistkeysresponse = redisclient.Redis.ListKeys(resourcegroupName, existingcachename);
                Console.WriteLine("PrimaryKey:" + redislistkeysresponse.PrimaryKey);
                Console.WriteLine("SecondaryKey:" + redislistkeysresponse.SecondaryKey);
                Console.WriteLine("RequestId:" + redislistkeysresponse.RequestId);
                Console.WriteLine("StatusCode:" + redislistkeysresponse.StatusCode);

            //for regenerating the Primary and Secondary Key
            // redisclient.Redis.RegenerateKey(resourcegroupName, existingcachename, new RedisRegenerateKeyParameters(RedisKeyType.Primary));

            //to delete the cache. This would take some time to cleanup. 
            //redisclient.Redis.Delete(resourcegroupName, existingcachename);

            //referenced StackExchange.Redis here for only using the ConfigurationOptions
            var configoptions = new ConfigurationOptions();
            configoptions.Password = existingcachepkey;
            configoptions.ConnectTimeout = 10000;
            configoptions.SyncTimeout = 70000;
            configoptions.AbortOnConnectFail = false;
            Console.WriteLine("REDIS ConnectionString >"+ configoptions);


        private static string GetAuthorizationHeader(string tenantId)
            var authenticationContext = new AuthenticationContext("https://login.microsoftonline.com/"+ tenantId);
            //For clientId, using Powershell wellknown clientId- 1950a258-227b-4e31-a9cf-717495945fc2
            AuthenticationResult resultstr = authenticationContext.AcquireToken("https://management.core.windows.net/",
                            new Uri("urn:ietf:wg:oauth:2.0:oob"),
            Console.WriteLine("Login Successfull..! Access token is ready to use. ");
            return resultstr.AccessToken;

Let me know if you find this useful and have details around equivalent ARM for this..

Disclaimer:- The above sample code is provided for the purpose of illustration only and is not intended to be used in a production environment.

2016-07-13 Posted by | .NET, Azure, C#, PaaS, Redis, VS2015 | | 4 Comments

.NET today, tomorrow and future..

This blog post was drafted few weeks ago but stuck in the same state because I was not sure what to add or write on top of what we learned from our recent dotnetConf2016.  Any how today I decided to wrap this so that it will be useful for readers. This post is mainly written for .NET developer who wanted to know where we are heading as  a community.


Motivation:- If you notice in recent times, there is a bunch of articles targeting .NET platform and its future. Few trolled about WPF and Winform roadmap. I saw most of them are one sided and simply trolled comparing with recent programming stack like LAMP/MEAN as an alternate. But the true story is, .NET is not going to go away. This applies to Java as well. I have my good old friends still doing WPF consulting work for big banking companies and happy with that. We all need “Growth Mindset” in looking at them.

We may have to agree that our recent startup companies are going 100% open source but when it comes to desktop development still WPF rules.The skill what you acquired from WPF is not going to be waste, because UWP is based on XAML. .NET is growing and evolving faster than ever. If you look at our .NET Foundation, it has got some fantastic open source projects run by community. We are breaking the platform dependencies, IIS, underlying win32 thick references which is the great thing for cross platform movement.  


Technology:- Things are changing very rapidly when it comes to programming side especially for the web & mobile technologies. As we march towards mobile first cloud first world, it makes sense to investment towards platform mobility and in cloud. please note, “mobile first” here is nothing to do with our mobile device. It’s about application mobility – should be able to port our app across the device.

Every week/month we see new set of tools/services/JS framework/scripting things comes out constantly and occupies the head line or top slot in tech conferences. One shouldn’t be worrying about new things, we should stay calm and keep learning at least one new languages every year as an investment. If I remember correctly, for last few years we are seeing a trend in IT requirement. Yr 2013 was for Big data, 2014 for Machine learning/deep learning/AI , 2015 for IoT + dockers,  again in 2016 seeing BoT, headless servers, nano servers, cognitive services and what not. Btw, Cloud and OSS is the constant thing for last few years and going to be more talked in coming years as well Smile. It shouldn’t be a matter for us to pick up this in couple of weekends if we know the fundamentals of programming & design standards.



Roadmap:- If we know the technology roadmap in advance, then it is easy for anyone to refer and suggest for customers. I had this .NET roadmap guide constantly referred, forwarded to architects for newer design consideration but the last one published was in the year 2013 and sadly no update after that.

Get our last guide “.NET Technology Guide for business applications” downloaded from- > here

[P.s: Some of them are already outdated]




Few months back, I reached out to Cesar(author of this PDF) seeking clarity on our guidance update. He has promptly shared the preview version but today I see the same guide available for download freely here. What a timing Smile

Microsoft Platform and Tools for Mobile App Development –





Having said all, Thanks to our recent .net Conference for sharing more clarity around .NET future and developments. If you are .NET developer and not seen the updates from our recent dotnetConf 2016 –  then you are in the right place to get the updates through screenshot.

As title says, this is our current landscape. If you look closer, there is “no code sharing” across the platform and also carry the same learning. The new addition to this slide is our “UWP” and “Xamarin” story.




How about .NET tomorrow:- Yes, it allows us to reuse the skills by mastering one/two library not a platform. You can build and reuse the same code across the platform say iOS or Android or to OSX.

Main objective here is to make the “.NET standard library” to grow without updating platforms. It is going to be decoupled so that you can update libraries as you wish.




How is .NET Future looks like: More and more “.NET standard” supported API’s are expected in few months. Complex Libs like App Domains, Full Reflection and Binary Serialization are also getting considered. In near future, one should be able to easily move the code b/w .NET framework or .NET Core or .Xamarin.




.NET future- sub slide (.NET Framework) :-

a) C# – C#7, VB 15 is the talk of the town

b) Going forward- new version of windows 10,

c) Winforms/WPF  –> Store model

d) Winform/WPF convert to Store apps model, use store to push across the organization






What others are busy learning..




Closing note: & Key take away:








Recommended video:-

.NET Conf Day 1 Keynote – Scott Hunter

.NET Conf Day 2 Keynote – Miguel de Icaza

.NET Conf Day 3 Keynote – Scott Hanselman on The State of .NET


Watch the event videos here:-https://channel9.msdn.com/Events/dotnetConf/2016



Hope this is useful for you..

<update : 6/28/2016>

Another milestone on developer’s world: .NET Core & ASP.NET Core 1.0 got released at Red Hat DevNation. https://channel9.msdn.com/Events/Linux/DevNation-2016

.NET Home Page http://dot.net/

.NET Documentation https://docs.microsoft.com/en-us/dotnet/

Announcement https://blogs.msdn.microsoft.com/dotnet/2016/06/27/announcing-net-core-1-0/


2016-06-22 Posted by | .NET, ASP.NET 5, Azure Dev, C#, DevOps, OSS, PaaS, Uncategorized, VS2015 | , , , | 2 Comments


%d bloggers like this: