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://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 Aaron

I have changed the the below LINQ

but it seems the output still cannot get the ProductApprovals object

I have attached the Domain Entity for your reference too. please advise. Thanks a lot

        var output = from p in
            (_productRepo.GetAllIncluding(
                     p => p.Colour,
                     p => p.Unit,
                     p => p.Serie,
                     p => p.Brand,
                     p => p.Supplier,
                     p => p.ProductCategory1,
                     p => p.ProductCategory2,
                     p => p.ProductCategory3,
                     p => p.ProductCategory4,
                     p => p.MinQuantities,
                     p => p.CreatorUser,
                     p => p.CreatorUser.Company
            ).Include(p => p.ProductApprovals) // Include relationship
                .ThenInclude(pa => pa.Approver1) // ThenInclude nested relationship
            .ToList())
                     where Filter.FilterUtil.FilterForGetProduct(p, input)
                     select p;

Answer

Thanks my problem is solved

Also, it is fine, my data is small , so performance should be ok. THanks

Answer

if i break down to 2 linq query, it will work

                var query = (from q in _clientRepository.GetAllIncluding(dd => dd.Counterparty, ee => ee.ClientContact)
                             select q).ToList();


                query = (from c in query
                         join ct in _companyTypeRepository.GetAllList() on c.Type_Id equals ct.Id into allType
                         from c1 in allType.DefaultIfEmpty()
                         join bn in _businessNatureRepository.GetAllList() on c.Nature_Id equals bn.Id into allNature
                         from c2 in allNature.DefaultIfEmpty()
                         join pm in _clientContactRepository.GetAllList() on c.PurchaseManager_Id equals pm.Id into allPMgr
                         from c3 in allPMgr.DefaultIfEmpty()
                         join pp in _clientContactRepository.GetAllList() on c.PurchasePerson_Id equals pp.Id into allPPerson
                         from c4 in allPPerson.DefaultIfEmpty()
                         join cp in _userRepository.GetAllList() on c.ContactPerson_Id equals cp.Id into allContactPerson
                         from c5 in allContactPerson.DefaultIfEmpty()
                         select c).ToList();
Showing 1 to 10 of 14 entries