1

I am using Azure Mobile Services to provide data to a Windows Universal app and Azure API Management as a proxy for API usage and analytics purposes. This is working great.

Now I was asked to provide offline functionality to the application so I started using Azure Mobile Services Synchronization Context in order to implement this using SQLite as the local store.

Azure API Management requires me to send my subscription key as part of my query string. I have been doing this using the 'parameters' dictionary provided by the IMobileServiceTable.InsertAsync method and this was working fine as well.

Now the offline implementation requires me to use IMobileServiceSyncTable.InsertAsync method instead, which doesn't provide an overload with the 'parameters' dictionary. The MobileServiceSyncContextExtensions.PushAsync method does not seem to provide a way to add custom parameters to the query string either.

Does anyone know of a way to include custom parameters when using the Mobile Services Synchronization Context in order to send the subscription key of the Azure API Management service?

1 Answer 1

4

I've found the way to do this.

I implemented the following HTTP Message Handler:

using System; using System.Collections.Generic; using System.Net.Http; using System.Text; class AzureApiManagementHandler : DelegatingHandler { string _subscriptionKey; public AzureApiManagementHandler(string subscriptionKey) { _subscriptionKey = subscriptionKey; } protected override System.Threading.Tasks.Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) { var baseUri = new UriBuilder(request.RequestUri); string queryToAppend = string.Format("subscription-key={0}", _subscriptionKey); if (baseUri.Query != null && baseUri.Query.Length > 1) baseUri.Query = baseUri.Query.Substring(1) + "&" + queryToAppend; else baseUri.Query = queryToAppend; request.RequestUri = baseUri.Uri; return base.SendAsync(request, cancellationToken); } } 

And then I passed it to the Mobile Services client in the constructor:

 public static MobileServiceClient MobileService = new MobileServiceClient( "https://yoursubdomainhere.azure-api.net", "yourapikeyhere", new AzureApiManagementHandler("yoursubscriptionkeyhere") ); 

I hope this is useful for anyone facing the same problem.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.