servicestack

Override field name deserialization in ServiceStack

不想你离开。 提交于 2019-12-01 15:40:19
I'm using ServiceStack to deserialize some HTML form values but can't figure out how to override the value that each field should be read from. For example, the form posts a value to first_name but the property on my POCO is called FirstName . how would I do mapping like that in ServiceStack The ServiceStack Text serializers support [DataMember] aliases where you can use the Name parameter to specify what alias each field should be, e.g: [DataContract] public class Customer { [DataMember(Name="first_name")] public string FirstName { get; set; } [DataMember(Name="last_name")] public string

Setting up Web.config to work Side-by-Side with ASP.NET MVC 4 - Location Tag not resolving value “api”

荒凉一梦 提交于 2019-12-01 13:21:43
I checked out Run servicestack side by side with another web framework . When I add the location tag the "api" is unresolved...what do I need to do to get the location tag to be aware of "api"? mythz Firstly make sure you follow the README.txt instructions for running ServiceStack in ASP.NET MVC. ServiceStack automatically infers the handler path based on the <location> tag, if there's more than one or it has some other issue inferring, it can be explicitly set in Config.ServiceStackHandlerFactoryPath , e.g: SetConfig(new EndpointHostConfig { ServiceStackHandlerFactoryPath = "api", }); 来源:

How do I send a complex JSON object from an HTML form using SYNCHRONOUS page POST?

烂漫一生 提交于 2019-12-01 10:59:29
My server is using ServiceStack and would like to receive some data like this: { Customer: { Company: "TheCompany", RegionCode: "AU_NSW" }, Name: { First: "Jimi", Last: "Hendrix" } } I have a form which has these fields and I can easily grab the data using JQuery, make the nested JSON object and use $.post to send it through. But I don't want to send it as AJAX, because I want the entire page to submit and then the browser to show the server's response as a new page. Just classic form post behaviour. I have tried embedding the complex json as strings inside hidden form fields - No cigar. I

How can you change the default ContentType in ServiceStack?

╄→гoц情女王★ 提交于 2019-12-01 10:55:31
I have registered a new content type in ServiceStack with: appHost.ContentTypeFilters.Register("application/x-my-content-type", SerializeToStream, DeserializeFromStream); And everything works as expected, if the client sends the content type in the http stream. Unfortunately, I have a client that is not in my control of HTTP Request Heads and does not send the content type. How can I get ServiceStack to set the default content type for that route? On every ServiceStack /metadata page lists the different ways a client can request a specific Content-Type: To override the Content-type in your

Is there any Equivalent to ValidateAntiForgeryToken in ServiceStack?

放肆的年华 提交于 2019-12-01 09:41:34
问题 I'm looking at SS code in github and I can't to find any equivalent to ValidateAntiForgeryToken because I don't want to reinvent the wheel and I'd like to reuse as much as possible the SS framework, I think that a solution could be to create a custom RequestFilterAttribute, any other ideas? 回答1: It looks like that wheel has already been invented: https://github.com/ServiceStack/ServiceStack/tree/master/src/ServiceStack/Html/AntiXsrf 回答2: I ended up by creating a requestFilterAttibute with

ServiceStack: Testing OrmLite, installed with NuGet but I get error “FileNotFoundException”

人盡茶涼 提交于 2019-12-01 09:34:35
I just installed OrmLite (for MySql) via NuGet in Visual Studio 2012. The installation passes without any errors, and all DLL:s seem to be added as reference: ServiceStack.Common (3.9.70.0) ServiceStack.Interfaces (1.0.0.0) ServiceStack.Text (3.9.70.0) ServiceStack.OrmLite (3.9.70.0) ServiceStack.OrmLite.MySql (3.9.70.0) Compile gives no errors. However, when I run this line: dbConnCommOrm.CreateTableIfNotExists<ModuleSettings>(); Then I get this error: Could not load file or assembly 'ServiceStack.Common, Version=3.9.69.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The

ServiceStack - Validation and Database Access

不羁的心 提交于 2019-12-01 09:26:04
I'm implementing an Api with ServiceStack. One of the key aspects of my solution is an aggressive validation strategy. I use ServiceStack's ValidationFeature, meaning that if there is an IValidator< ReqDto > (or its descendant: AbstractValidator< ReqDto >) registered in the app container, validation will automatically run prior to the service. By aggressive validation, what I mean is that I check all possible error scenarios, and logic validations at the validator level. As a result my service logic is extremely clean and short. This independance of Service Logic from Service Validation is

How to get ServiceStack to serialize / deserialize an expando object with correct types

余生颓废 提交于 2019-12-01 08:27:11
just trying to work out how well servicestack.text supports serializing expando objects to and from json. I know that an expando object implements an IDictionary. When I serialize to and from json I am having trouble getting the correct types in the deserialized IDictionary. As Json does not support types natively and servicestack has a setting called JsConfig.IncludeTypeInfo I expected it to include the type information in the serialized json to enable service stack to deserialize to the correct types on the other side, (eg a decimal without decimal places is deserialized to a uint64). Is

Access Servicstack.net session in validator

旧时模样 提交于 2019-12-01 08:09:06
How can I access a ServiceStack.net session in my validation code? public class UserSettingsValidator : AbstractValidator<UserSettingsRequest> { public UserSettingsValidator() { RuleFor(x => x.UserId) .SetValidator(new PositiveIntegerValidator()) .SetValidator(new UserAccessValidator(session.UserId)); //<-- I need to pass the UserID from the session here } } In the Service Implementation I just do: var session = base.SessionAs<UserSession>(); but this does not work for my abstract validator. Thanks! Edit: this is version 3.9.71.0 I assume you are just using the ValidationFeature plugin, as

Servicestack.net Mini Profiler in razor view

▼魔方 西西 提交于 2019-12-01 06:53:27
Is it possible to use the mini profiler in service stack with the razor views? It looks like the documentation only shows the profiler when using the json html report view. Yes you can include it using the same MVC include but include it .AsRaw() so it doesn't get HTML encoded, e.g: @ServiceStack.MiniProfiler.Profiler.RenderIncludes().AsRaw() Example taken from this RazorRockstars template . 来源: https://stackoverflow.com/questions/12586343/servicestack-net-mini-profiler-in-razor-view