Gurpreet Singh
Gurpreet Singh

Reputation: 165

Azure Mobile Service in xamarin forms existing code

I'm working on android app development. I was using non-secure service end point, i am using below method for post the request:-

public static T Get<T>(WebRequest request, string requestData=null)
    {   
        string result=string.Empty;
        request.ContentType = "application/json";

        request.Headers ["ZUMO-API-VERSION"] = "2.0.0";
        try
        {
        WebResponse webResponse = Task.Factory.FromAsync<WebResponse> (request.BeginGetResponse, request.EndGetResponse, null).Result;              
        using (var streamReader = new StreamReader (webResponse.GetResponseStream ())) 
        {
            result = streamReader.ReadToEnd ();
        }
        var typ = typeof(T);
        if (
            typ == typeof(String) 
            || typ == typeof(float)
            || typ == typeof(Decimal)
            || typ == typeof(Int16)
            || typ == typeof(Int32)
            || typ == typeof(Int64)
        ) {
            return  (T) Convert.ChangeType(result, typeof(T), null);
        }
        return result.FromJson<T> ();
        }
        catch(Exception ex) {
            return result.FromJson<T> ();
        }
    }  

` But now i have changed the end points im using Secure end point. I don't know how i can access the end point using MobileServiceClient(). Please help me if anybody have any idea.

Upvotes: 0

Views: 29

Answers (1)

Adrian Hall
Adrian Hall

Reputation: 8035

It looks like you are invoking a custom API, probably under /api/something - however, it's hard to tell as you have posted an incomplete example. The code for this would look something like:

var client = new MobileServiceClient("https://foo.azurewebsites.net");
var result = await client.InvokeApiAsync<Model>("something", HttpMethod.Post);

Model is a class to receive the model you are expecting back. It will handle the ZUMO-API-VERSION. It will also handle authentication if you have it defined.

Upvotes: 1

Related Questions