Serenity: Someone adapted Serenity.Services for Xamarin?

Created on 29 Aug 2017  路  11Comments  路  Source: serenity-is/Serenity

I need this, for connect to the serenity project and use the endpoints.
As the following example: # 806

add-sample

Most helpful comment

I will post sample showing CRUD + Fileupload from WPF / Desktop Application

All 11 comments

We have consumed Serenity.Services using RestSharp in WPF Application storing cookies in CookiesContainer (For Forms Authentication)
in Android in similar fashion we are consuming Serenity Apis

Hey! @samdubey I'll keep that in mind. You can send me a basic example of how to authorize and consume a service.
Thanks for all!

`public static class SereneRequester
{
public static CookieContainer rsCookie = new CookieContainer();

    // Check user is LoggedIn or not
    [Protect]
    public static IRestResponse<bool> IsLoggedIn(string baseUrl, string cookieName)
    {
        #region IsLoggedIn Request
        IRestResponse<bool> response = new RestResponse<bool>();
        if (InternetConnection.IsConnectedToInternet() == true)
        {
            try
            {
                var restClient = new RestClient(baseUrl);
                var request = new RestRequest(Method.POST);
                request.Resource = "/Account/IsLoggedIn";
                CookieContainer rscookie = RestoreCookie(cookieName);
                if (rscookie == null)
                {
                    rscookie = new CookieContainer();
                }
                restClient.CookieContainer = rscookie;
                response = restClient.Execute<bool>(request);
                if (response.StatusCode == HttpStatusCode.OK && response.ResponseStatus == ResponseStatus.Completed)
                {
                    SereneRequester.SaveCookie(restClient.CookieContainer, cookieName);
                }
            }
            catch (Exception ex)
            {
                response.ErrorMessage = ex.Message;
                response.ErrorException = ex.InnerException;
                //MessageBox.Show(ex.Message);
            }
            return response;
        }
        else
        {
            response.ErrorMessage = "Internet connection not available. Please check connection.";
            return response;
        }
        #endregion
    }

public static IRestResponse Login(string baseUrl, string username, string password, string cookieName)
{
#region Login Service Request
IRestResponse response = new RestResponse();
if (InternetConnection.IsConnectedToInternet() == true)
{
try
{
var restClient = new RestClient(baseUrl);
var request = new RestRequest(Method.POST);
request.Resource = "/Account/Login";
request.AddParameter("Username", username);
request.AddParameter("Password", password);
restClient.CookieContainer = new CookieContainer();
response = restClient.Execute(request);
if (response.StatusCode == HttpStatusCode.OK && response.ResponseStatus == ResponseStatus.Completed)
{
SereneRequester.SaveCookie(restClient.CookieContainer, cookieName);
}
}
catch (Exception ex)
{
response.ErrorMessage = ex.Message;
response.ErrorException = ex.InnerException;
//MessageBox.Show(ex.Message);
}
return response;
}
else
{
response.ErrorMessage = "Internet connection not available. Please check connection.";
return response;
}
#endregion
}`

Very Thanks for your time @samdubey! Can you explain me about parameter "string cookiename"?
And what Using use for InternetConnection.IsConnectedToInternet()?

Thanks a lot @samdubey

@sebacamino cookiename is any name given to cookie just like in web application cookie name could be
APP.AUTH or FORMS.AUTH

@samdubey I'm sorry for my insistence, but I'm doing a final job of my study and I need it.
Could you send me an example? POST data of person (Id(Identity), Name, SecondName, Sex), i need auth and i dont know how do it...
Thank you so much for everything

Replied to you over email

I will post sample showing CRUD + Fileupload from WPF / Desktop Application

It's ok! I will waiting the link!
Thanks a lot!

Hey @samdubey! You have already the sample?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

StefanTheiner picture StefanTheiner  路  3Comments

GitHubOrim picture GitHubOrim  路  3Comments

ahsansolution picture ahsansolution  路  3Comments

john20xdoe picture john20xdoe  路  3Comments

Pinellus picture Pinellus  路  3Comments