In 6.9 I see the continue property is removed, and I have found the replacement is to use Authenticate.Meta property Authenticate Continue removed from this link.
But Meta is not helping us to redirect to log out user page as like continue property did.
var _meta = new Dictionary<string, string>();
_meta.Add("Continue", $"{config.EndSessionEndpoint}?post_logout_redirect_uri={HttpUtility.UrlEncode(redirectTo)}");
return base.LogoutAsync(service, request, token);
Could you please help us out what will be correct way to redirect to logout endpoint with Meta property? or in 6.9 version do we have an alternative way to update this?
Thanks for the response. ReferrelUrl helped resolving the problem.
There is an another issue, We have a console application which calls servicestack apis for authentication and authorization when trying to run that application we are getting an unhandled exception:
“Value cannot be null. Parameter name: provider
at ServiceStack.Auth.AuthenticateService.GetAuthProvider(String provider)
at ServiceStack.AuthUserSession.IsAuthorized(String provider)
at System.Linq.Enumerable.Any[TSource](IEnumerable1 source, Func2 predicate)
at ServiceStack.AuthenticateAttribute.d__12.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at ServiceStack.ServiceStackHost.d__435.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at ServiceStack.ServiceStackHost.d__434.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at ServiceStack.Host.RestHandler.d__14.MoveNext()”
Looks it is looking for provider parameter. Where we want to update this? Can you please help me with this stack trace and exception message and tell what we have missed?
var tt = ServiceStackHandlerBase.DeserializeHttpRequestAsync(operationType, httpReq, httpReq.ContentType);
tt.Wait();
return tt;
With the above code, the tt.Wait(); is on continuous process, that doesn’t returning the value at all, the wait process is not getting completed. I almost waited for 3-5mins but no results.
I checked the source code, the method call CreateContentTypeRequestAsync inside the DeserializeHttpRequestAsync method causing this problem I guess. Can you please check from your end and let me know? Or is there any different API call we can use for this purpose? Please advise.
It sounds like an issue with use of .Wait in an this context, you should use await where possible. tt is also a Task<object> rather than your original code which would have returned the object. We don’t have any known issues. Change your use to avoid .Wait and .Result to use await keyword instead.
If you can create a reproduction of the issue with your code and how you are handling your specific use case we might be able to help more, however at this stage I’m not able to follow your description of how your application is using DeserializeHttpRequestAsync. The more code you can share, the more we will be able to help with your specific issue.
Thanks, I have changed my method to async await and it introduced the new problem when executing the POST request call we are getting an unhandled exception, below is the image reference with stack traces.
We are inherited ServiceStack.Service in our class for running these actions. Need to know the reason behind this error message and how i can resolve it?
Please let me know if you need more information or code from our end which will help.
Yes, the method return type is Task. But i can not have a void method for async await, its returning the required object only and not task. May be before await call completes, the exception is occurring? How can we overcome this? Below is the code reference
public static async Task<T> DeserializeTrimMainObject<T>(IRequest httpReq) where T : TrimMainObject, new()
{
ILog Log = LogManager.GetLogger(typeof(TrimUtils));
string methodData = null;
var isFormData = httpReq.HasAnyOfContentTypes(MimeTypes.FormUrlEncoded, MimeTypes.MultiPartFormData);
if (!isFormData)
{
using (MemoryStream tempStream = new MemoryStream())
{
httpReq.InputStream.CopyTo(tempStream);
httpReq.InputStream.Position = 0;
tempStream.Position = 0;
using (var reader = new StreamReader(tempStream))
{
methodData = reader.ReadToEnd();
}
}
}
T mainObject;
mainObject = await DeserializeHttpRequest(ServiceStackHandlerBase.GetOperationType(httpReq.OperationName), httpReq, httpReq.ContentType) as T;
return mainObject;
}
Misspelled my previous comment. It wont return Task, it will return a instance of an object.
Purpose of this method: Our product is Document management system(Content Manager). We will create different kinds of objects and store it. To create and update each objects(for example: Record, Locations) we will deserialize the httprequest and convert it our Object with required details.
I was using async await to return the ServiceStackHandlerBase.DeserializeHttpRequestAsync(operationType, httpReq, httpReq.ContentType);
since above code causing different problems, I am using below approach for deserializing the httprequest to the object:
var deserializer = HostContext.ContentTypes.GetStreamDeserializerAsync(httpReq.ContentType);
if (deserializer != null)
{
httpReq.AllowSyncIO();
var instance = deserializer(ServiceStackHandlerBase.GetOperationType(httpReq.OperationName), httpReq.InputStream);
instance.Wait();
return instance.Result;
}
return null;
Along with your suggestion i also included two lines of code which will achieve what ServiceStackHandlerBase.DeserializeHttpRequestAsync does. Is this approach is the right way? Please confirm.
It is unclear what context your code is running or why which would enable us to give you better advice.
In general, again, using async methods in the way above isn’t ideal, you are much better to either use the sync options, or use the await keyword rather than .Wait and .Result. If this is unclear, here is your above rewritten using await.
var deserializer = await HostContext.ContentTypes.GetStreamDeserializerAsync(httpReq.ContentType);
if (deserializer != null)
{
httpReq.AllowSyncIO();
var instance = deserializer(ServiceStackHandlerBase.GetOperationType(httpReq.OperationName), httpReq.InputStream);
return instance;
}
return null;
Can you provide specific error details, a stack trace and a way to reproduce the problem? We want to help, but it is difficult if we don’t have the required info.
Again, context about why you need to use DeserializeHttpRequestAsync (eg, what your application is trying to achieve) would enable us better to understand the nature of the problem to are seeing. Hope you can provide more info.
We are trying to call this deserialize API, since the httprequest payload input stream contains required information and we will bind those data with the trimmainobject. Example object:
Public class TrimMainObject
{
public string Id {get; set;}
public object Container {get; set;}
}
the API ServiceStackHandlerBase.DeserializeHttpRequestAsync(operationType, httpReq, httpReq.ContentType); will help us to deserialize the request and return the Trimmainobject with updating the input data(Id and Container input datas).
Issues faced after using async await:
Since i need to use async await, the return type of the method i have changed from object to Task<object>, since the RequestBinder is expecting the return type object but instead returning Task<object> i am getting below error, also included stack trace image: Please refer:
Request Binders are used when you want to change the default binding ServiceStack uses to populate the Request DTO which is not clear that’s what you want to do since you’re just using ServiceStack to deserialize the request anyway.
Why do you need to deserialize the request yourself? i.e. Can you get what you want from the populated Request DTO and do whatever customizations you need from an async Global Request Filter?