Use ServiceStack to build cross-platform Web Services

Source: Internet
Author: User
Tags webhost

This article is mainly from the MSDN magazine Building Cross-Platform Web Services with ServiceStack. Windows Communication Foundation (WCF) is a very good service framework. When we discuss Cross-Platform Services, although WCF supports WebService, Microsoft has re-developed ASP in the face of poor performance in some advanced applications. NET WebAPI framework. For more information about the two frameworks, see my other article, "WCF and ASP. NET Web API selection on the application. ASP. NET Web API is an important option. In this article, I will show you how to use ServiceStack (open source code.. NET and Mono REST service framework) to complete this task, without leaving Visual Studio or Microsoft. NET/Mono, in addition to ServiceStack, there is also a Nancy framework. For details, see 《. NET micro Web framework Nancy.

A typical Web service structure is as follows:

<Add path = "*" type = "ServiceStack. WebHost. Endpoints. ServiceStackHttpHandlerFactory, ServiceStack" verb = "*"/>
</HttpHandlers>
</System. web>
<System. webServer>
<Modules runAllManagedModulesForAllRequests = "true"/>
<Validation validateIntegratedModeConfiguration = "false"/>
<Add path = "*" name = "ServiceStack. factory "type =" ServiceStack. webHost. endpoints. serviceStackHttpHandlerFactory, ServiceStack "verb =" * "preCondition =" integratedMode "resourceType =" Unspecified "allowPathInfo =" true "/>
</Handlers>
</System. webServer>
</Configuration>

You need to inherit from ServiceStack. WebHost. End to implement the endpoint.

Public class AppHost: AppHostBase
{
Public AppHost () // Tell ServiceStack the name and where to find your web services
: Base ("StarterTemplate ASP. NET Host", typeof (HelloService). Assembly ){}

Public override void Configure (Funq. Container container)
{
// Set JSON web services to return idiomatic JSON camelCase properties
ServiceStack. Text. JsConfig. EmitCamelCaseNames = true;

// Configure User Defined REST Paths
Routes
. Add <Hello> ("/hello ")
. Add <Hello> ("/hello/{Name *}");

// Uncomment to change the default ServiceStack configuration
// SetConfig (new EndpointHostConfig {
//});

// Enable Authentication
// ConfigureAuth (container );

// Register all your dependencies
Container. Register (new TodoRepository ());
}

/* Uncomment to enable ServiceStack Authentication and CustomUserSession
Private void ConfigureAuth (Funq. Container container)
{
Var rule ettings = new rule ettings ();

// Default route:/auth/{provider}
Plugins. Add (new AuthFeature () => new CustomUserSession (),
New IAuthProvider [] {
New CredentialsAuthProvider (deleetprovider ),
New FacebookAuthProvider (deleetask ),
New TwitterAuthProvider (appSettings ),
New BasicAuthProvider (appSettings ),
}));

// Default route:/register
Plugins. Add (new RegistrationFeature ());

// Requires ConnectionString configured in Web. Config
Var connectionString = ConfigurationManager. ConnectionStrings ["AppDb"]. ConnectionString;
Container. Register <IDbConnectionFactory> (c =>
New OrmLiteConnectionFactory (connectionString, SqlServerDialect. Provider ));

Container. Register <IUserAuthRepository> (c =>
New OrmLiteAuthRepository (c. Resolve <IDbConnectionFactory> ()));

Var authRepo = (OrmLiteAuthRepository) container. Resolve <IUserAuthRepository> ();
AuthRepo. CreateMissingTables ();
}
*/

Public static void Start ()
{
New AppHost (). Init ();
}
}

When the ServiceStack Web application is started, your service contract is listed as metadata operation ,:

Related Articles:

Interview With Demis Bellot, Project Lead of ServiceStack-Part 1

Interview With Demis Bellot, Project Lead of ServiceStack-Part 2

SignalR, Filters and ServiceStack

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.