Using InsertOrReplace/InsertOrMerge with the Storage Client!

Trying out the new Replace or Insert option(Upsert) in the Storage Client and can’t get rid of the following error message

“"<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>\r\n<error xmlns=\"http://schemas.microsoft.com/ado/2007/08/dataservices/metadata\">\r\n  <code>InvalidHeaderValue</code>\r\n  <message xml:lang=\"en-US\">The value for one of the HTTP headers is not in the correct format.</message>\r\n</error>"”

The main issue is that the new API is available only in the "2011-08-18" version which the storage dll does not hit . The reason the below code is necessary is because the released library sends an older storage version “2009-09-19” that does not support these newly released features

So we need to specifically set the headers in the data-context request. Also remember that this does not work with the local development storage ( at least as of now), so remember to use these headers ( and these operations) only with the Cloud storage account.

dataContext.SendingRequest +=
   (sender, args) => (args.Request).Headers["x-ms-version"] = "2011-08-18";

               dataContext.AttachTo(<tableName>, <data>);
               dataContext.UpdateObject(<data>);
             dataContext.SaveChangesWithRetries(SaveChangesOptions.ReplaceOnUpdate);

This gives you Insert Or Replace option with Storage Client Lib!!

If you leave the SaveChangeOptions.ReplaceOnUpdate option then you get Insert or Merge!

Until Next time!

Team Cennest!

Advertisements

About Cennest
Cennest is the brainchild of a group of IT Professionals keen to try their hand in the world of IT Freelancing. After working in the corpora

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: