c# - unauthorized exception after removing Task code -


i getting following exception after having removed task/async code:

{ "message": "an error has occurred.", "exceptionmessage": "one or more errors occurred.", "exceptiontype": "system.aggregateexception", "stacktrace": " @ system.threading.tasks.task1.getresultcore(boolean waitcompletionnotification)\r\n @ abb.api.customers.dynamicscrm.accounts.businesslogic.accountservice.getaccount(string query, httprequestheaders headers) in f:\\tfs\\orian360 res\\abb.api\\dev\\customers\\dynamicscrm\\accounts\\businesslogic\\accountservice.cs:line 26\r\n @ abb.api.customers.dynamicscrm.accounts.web.accountscontroller.getaccount() in f:\\tfs\\orian360 res\\abb.api\\dev\\customers\\dynamicscrm\\accounts\\web\\controllers\\accountscontroller.cs:line 27\r\n @ lambda_method(closure , object , object[] )\r\n @ system.web.http.controllers.reflectedhttpactiondescriptor.actionexecutor.<>c__displayclass10.<getexecutor>b__9(object instance, object[] methodparameters)\r\n @ system.web.http.controllers.reflectedhttpactiondescriptor.executeasync(httpcontrollercontext controllercontext, idictionary2 arguments, cancellationtoken cancellationtoken)\r\n--- end of stack trace previous location exception thrown ---\r\n @ system.runtime.compilerservices.taskawaiter.throwfornonsuccess(task task)\r\n @ system.runtime.compilerservices.taskawaiter.handlenonsuccessanddebuggernotification(task task)\r\n @ system.web.http.controllers.apicontrolleractioninvoker.d__0.movenext()\r\n--- end of stack trace previous location exception thrown ---\r\n @ system.runtime.compilerservices.taskawaiter.throwfornonsuccess(task task)\r\n @ system.runtime.compilerservices.taskawaiter.handlenonsuccessanddebuggernotification(task task)\r\n @ system.web.http.filters.actionfilterattribute.d__5.movenext()\r\n--- end of stack trace previous location exception thrown ---\r\n @ system.web.http.filters.actionfilterattribute.d__5.movenext()\r\n--- end of stack trace previous location exception thrown ---\r\n @ system.runtime.compilerservices.taskawaiter.throwfornonsuccess(task task)\r\n @ system.runtime.compilerservices.taskawaiter.handlenonsuccessanddebuggernotification(task task)\r\n @ system.web.http.filters.actionfilterattribute.d__0.movenext()\r\n--- end of stack trace previous location exception thrown ---\r\n @ system.runtime.compilerservices.taskawaiter.throwfornonsuccess(task task)\r\n @ system.runtime.compilerservices.taskawaiter.handlenonsuccessanddebuggernotification(task task)\r\n @ system.web.http.controllers.actionfilterresult.d__2.movenext()\r\n--- end of stack trace previous location exception thrown ---\r\n @ system.runtime.compilerservices.taskawaiter.throwfornonsuccess(task task)\r\n @ system.runtime.compilerservices.taskawaiter.handlenonsuccessanddebuggernotification(task task)\r\n @ system.web.http.dispatcher.httpcontrollerdispatcher.d__1.movenext()", "innerexception": { "message": "an error has occurred.", "exceptionmessage": "an error occurred while sending request.", "exceptiontype": "system.net.http.httprequestexception", "stacktrace": null, "innerexception": { "message": "an error has occurred.", "exceptionmessage": "the remote server returned error: (401) unauthorized.", "exceptiontype": "system.net.webexception", "stacktrace": " @ system.net.httpwebrequest.endgetresponse(iasyncresult asyncresult)\r\n @ system.net.http.httpclienthandler.getresponsecallback(iasyncresult ar)", "innerexception": { "message": "an error has occurred.", "exceptionmessage": "the target principal name incorrect", "exceptiontype": "system.componentmodel.win32exception", "stacktrace": " @ system.net.ntauthentication.getoutgoingblob(byte[] incomingblob, boolean throwonerror, securitystatus& statuscode)\r\n @ system.net.ntauthentication.getoutgoingblob(string incomingblob)\r\n
@ system.net.negotiateclient.doauthenticate(string challenge, webrequest webrequest, icredentials credentials, boolean preauthenticate)\r\n @ system.net.negotiateclient.authenticate(string challenge, webrequest webrequest, icredentials credentials)\r\n @ system.net.authenticationmanagerdefault.authenticate(string challenge, webrequest request, icredentials credentials)\r\n @ system.net.authenticationstate.attemptauthenticate(httpwebrequest httpwebrequest, icredentials authinfo)\r\n @ system.net.httpwebrequest.checkresubmitforauth()\r\n @ system.net.httpwebrequest.checkresubmit(exception& e, boolean& disableupload)" } } } }

the code in previous state worked without issue:

public async task<httpresponsemessage> getaccount(string query)         {              var response = client.instance.getasync(client.instance.baseaddress + query);             var responsetype = response.result.statuscode;             if (responsetype == httpstatuscode.notfound)             {                 return new httpresponsemessage                 {                     statuscode = responsetype                 };             }             return await response;         }  

i updated non-async:

    public httpresponsemessage getaccount(string query, httprequestheaders headers)     {         var requesturi = new uri(client.instance.baseaddress + query);         var request = new httprequestmessage         {             requesturi = requesturi         };          foreach (var header in headers)         {             request.headers.add(header.key, header.value);         }          var response = client.instance.sendasync(request).result;         return response;     } 

what causing exception? seems related async/async?

the controller defined follows:

    [httpget]     [route("accounts({id:guid})")]     [route("accounts")]     public task<httpresponsemessage> getaccount()     {         var query = request.requesturi.absolutepath.split('/').last() + request.requesturi.query;         var response = _accountservice.getaccount(query, request.headers);         return response;     } 


Comments

Popular posts from this blog

javascript - Create a stacked percentage column -

Optimising Firebase database by automatically overwriting data -

javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -