Base solution for your next web application

Activities of "itzoar2"

Just check the source code of AbpWebApiClient

<a class="postlink" href="http://sourcebrowser.io/Browse/aspnetboilerplate/aspnetboilerplate/src/Abp.Web.Api/WebApi/Client/AbpWebApiClient.cs">http://sourcebrowser.io/Browse/aspnetbo ... iClient.cs</a>

Looks like the web api client always throw AbpException. May i know how to change the backend function in order to generate the AbpRemoteCallException in this case. Thanks

    public async Task&lt;TResult&gt; PostAsync&lt;TResult&gt;(string url, object input, int? timeout = null)
        where TResult : class, new()
    {
        using (var client = new HttpClient())
        {
            client.Timeout = timeout.HasValue ? TimeSpan.FromMilliseconds(timeout.Value) : Timeout;

            if (!BaseUrl.IsNullOrEmpty())
            {
                client.BaseAddress = new Uri(BaseUrl);
            }

            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            using (var requestContent = new StringContent(Object2JsonString(input), Encoding.UTF8, "application/json"))
            {
                using (var response = await client.PostAsync(url, requestContent))
                {
                    if (!response.IsSuccessStatusCode)
                    {

<span style="color:#0040FF"> throw new AbpException("Could not made request to " + url + "! StatusCode: " + response.StatusCode + ", ReasonPhrase: " + response.ReasonPhrase);</span> }

                    var ajaxResponse = JsonString2Object&lt;AjaxResponse&lt;TResult&gt;>(await response.Content.ReadAsStringAsync());
                    if (!ajaxResponse.Success)
                    {
                        throw new AbpRemoteCallException(ajaxResponse.Error);
                    }

                    return ajaxResponse.Result;
                }
            }
        }
    }

I have made use the example console app <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate-samples/tree/master/ConsoleRemoteWebApiCall">https://github.com/aspnetboilerplate/as ... WebApiCall</a>

I find that the webapi client won't catch any UserFriendlyException or AbpRemoteCallException exception

It can only catch Abp.AbpException

and it always return somethings like

"Could not made request to <a class="postlink" href="http://localhost:6240/api/services/app/role/GetRoles">http://localhost:6240/api/services/app/role/GetRoles</a>! StatusCode: InternalServerError, ReasonPhrase: Internal Server Error"

Please advise how can a WPF client that call WebApi layer can get meaningful exception. Thanks

My backend GetRoles function

    public async Task&lt;ListResultDto&lt;RoleListDto&gt;> GetRoles(GetRolesInput input)
    {

throw new UserFriendlyException(404, "message", "MessageDetail"); var roles = await _roleManager .Roles .WhereIf( !input.Permission.IsNullOrWhiteSpace(), r => r.Permissions.Any(rp => rp.Name == input.Permission && rp.IsGranted) ) .ToListAsync();

        return new ListResultDto&lt;RoleListDto&gt;(roles.MapTo&lt;List&lt;RoleListDto&gt;>());
    }

When my backend service throw back a new UserFriendlyException

then on my WPF cleint (below code), i didn't catch on the AbpRemoteCallException block

So my question is , should I throw userfriendlyxception or abpremotecallexception if know client is not client calling back end while API layer

Please advise. Thanks a lot

    public async Task&lt;int&gt; AddAsync&lt;TInput&gt;(TInput input, string serviceLink)
    {
        try
        {
            var result = await _abpWebApiClient.PostAsync&lt;object&gt;(BaseUrl + serviceLink, input, timeout: null);
            return Convert.ToInt32(result);
        }
        catch (AbpRemoteCallException e)
        {
            Logger.Error("Error on AddAsync : input " + input.ToString());
            Logger.Error("Error on AddAsync : serviceLink" + serviceLink);
            Logger.Error("Error on AddAsync : Error Message" + e.Message);
            throw;
        }

        catch (Exception e)
        {
            Logger.Error("Error on AddAsync : input " + input.ToString());
            Logger.Error("Error on AddAsync : serviceLink" + serviceLink);
            Logger.Error("Error on AddAsync : Error Message" + e.Message);
            throw;
        }
    }

thanks i think my problem has been solved

Hi

So on the Backend server side can we still throw UserFriendlyException ?

Will AbpRemoteCallException class be able to catch UserFriendlyException ?

<a class="postlink" href="https://aspnetboilerplate.com/Pages/Documents/Handling-Exceptions">https://aspnetboilerplate.com/Pages/Doc ... Exceptions</a>

Look forward your reply. Thanks

So may i know what is the ultimate method to use Office365 SMTP email using TLS?

<a class="postlink" href="https://aspnetboilerplate.com/Pages/Documents/Email-Sending">https://aspnetboilerplate.com/Pages/Doc ... il-Sending</a>

does it mean i should use

Abp.MailKit NuGet package

And replace the IMailKitSmtpBuilder interface with your own implementation

using the above code to config the smtp client ?

<a class="postlink" href="https://aspnetboilerplate.com/Pages/Documents/Handling-Exceptions">https://aspnetboilerplate.com/Pages/Doc ... Exceptions</a>

May i know if i want to pass Exception Message to my WPF client

on the WPF client, i have used the library Abp.WebApi.Client.IAbpWebApiClient

but i am not sure how to pass the exception from the backend to this client.

Please advise. THanks a lot

Hi base on the below link <a class="postlink" href="https://itservices.usc.edu/office365/emailclients/">https://itservices.usc.edu/office365/emailclients/</a>

Office365 is using TLS Encryption Method and Port Number 587

It seems the SMTP client in Aspnetzero doesn't support TLS?

<a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate-samples/tree/master/ConsoleRemoteWebApiCall">https://github.com/aspnetboilerplate/as ... WebApiCall</a>

From this sample, is it compatible to the latest web framework ?

Hi

I have a WPF client and when it comes to Data Layer, it will go to the Service Backend to login

Would you please provide any example to us. Thanks a lot

Showing 1 to 10 of 21 entries