├── src └── Northwind │ ├── Northwind │ ├── Global.asax │ ├── Northwind.sqlite │ ├── img │ │ ├── bg-footer.png │ │ ├── vcard-ALFKI.png │ │ ├── database-icon.jpg │ │ ├── database-18x18.jpg │ │ ├── logo-txt-small.png │ │ ├── vcard-ALFKI-200.png │ │ └── vcard-ALFKI-300.png │ ├── Global.asax.cs │ ├── Properties │ │ ├── PublishProfiles │ │ │ └── WebDeploy.pubxml │ │ └── AssemblyInfo.cs │ ├── Web.config │ ├── Northwind.csproj │ ├── vcard-format.htm │ └── default.htm │ ├── Northwind.ServiceModel │ ├── Types │ │ ├── Region.cs │ │ ├── CustomerCustomerDemo.cs │ │ ├── CustomerDemographic.cs │ │ ├── Shipper.cs │ │ ├── Category.cs │ │ ├── Territory.cs │ │ ├── EmployeeTerritory.cs │ │ ├── CustomerOrders.cs │ │ ├── OrderDetail.cs │ │ ├── Product.cs │ │ ├── Supplier.cs │ │ ├── Customer.cs │ │ ├── Order.cs │ │ └── Employee.cs │ ├── AutoQuery.cs │ ├── Customers.cs │ ├── CachedOperations.cs │ ├── Orders.cs │ ├── CustomerDetails.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ └── Northwind.ServiceModel.csproj │ ├── Northwind.ServiceInterface │ ├── CustomersService.cs │ ├── CustomerDetailsService.cs │ ├── CachedServices.cs │ ├── OrdersService.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── VCardFormat.cs │ └── Northwind.ServiceInterface.csproj │ └── Northwind.sln ├── README.md └── .gitignore /src/Northwind/Northwind/Global.asax: -------------------------------------------------------------------------------- 1 | <%@ Application Codebehind="Global.asax.cs" Inherits="Northwind.Global" Language="C#" %> 2 | -------------------------------------------------------------------------------- /src/Northwind/Northwind/Northwind.sqlite: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ServiceStackApps/Northwind/HEAD/src/Northwind/Northwind/Northwind.sqlite -------------------------------------------------------------------------------- /src/Northwind/Northwind/img/bg-footer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ServiceStackApps/Northwind/HEAD/src/Northwind/Northwind/img/bg-footer.png -------------------------------------------------------------------------------- /src/Northwind/Northwind/img/vcard-ALFKI.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ServiceStackApps/Northwind/HEAD/src/Northwind/Northwind/img/vcard-ALFKI.png -------------------------------------------------------------------------------- /src/Northwind/Northwind/img/database-icon.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ServiceStackApps/Northwind/HEAD/src/Northwind/Northwind/img/database-icon.jpg -------------------------------------------------------------------------------- /src/Northwind/Northwind/img/database-18x18.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ServiceStackApps/Northwind/HEAD/src/Northwind/Northwind/img/database-18x18.jpg -------------------------------------------------------------------------------- /src/Northwind/Northwind/img/logo-txt-small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ServiceStackApps/Northwind/HEAD/src/Northwind/Northwind/img/logo-txt-small.png -------------------------------------------------------------------------------- /src/Northwind/Northwind/img/vcard-ALFKI-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ServiceStackApps/Northwind/HEAD/src/Northwind/Northwind/img/vcard-ALFKI-200.png -------------------------------------------------------------------------------- /src/Northwind/Northwind/img/vcard-ALFKI-300.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ServiceStackApps/Northwind/HEAD/src/Northwind/Northwind/img/vcard-ALFKI-300.png -------------------------------------------------------------------------------- /src/Northwind/Northwind.ServiceModel/Types/Region.cs: -------------------------------------------------------------------------------- 1 | namespace Northwind.ServiceModel.Types 2 | { 3 | using System.Runtime.Serialization; 4 | 5 | [DataContract] 6 | public class Region 7 | { 8 | [DataMember] 9 | public int Id { get; set; } 10 | 11 | [DataMember] 12 | public string RegionDescription { get; set; } 13 | } 14 | } -------------------------------------------------------------------------------- /src/Northwind/Northwind.ServiceModel/AutoQuery.cs: -------------------------------------------------------------------------------- 1 | using Northwind.ServiceModel.Types; 2 | using ServiceStack; 3 | 4 | namespace Northwind.ServiceModel 5 | { 6 | [Route("/query/customers")] 7 | public class QueryCustomers : QueryDb { } 8 | 9 | [Route("/query/orders")] 10 | public class QueryOrders : QueryDb { } 11 | } -------------------------------------------------------------------------------- /src/Northwind/Northwind.ServiceModel/Types/CustomerCustomerDemo.cs: -------------------------------------------------------------------------------- 1 | namespace Northwind.ServiceModel.Types 2 | { 3 | using System.Runtime.Serialization; 4 | 5 | [DataContract] 6 | public class CustomerCustomerDemo 7 | { 8 | [DataMember] 9 | public string Id { get; set; } 10 | 11 | [DataMember] 12 | public string CustomerTypeId { get; set; } 13 | } 14 | } -------------------------------------------------------------------------------- /src/Northwind/Northwind.ServiceModel/Types/CustomerDemographic.cs: -------------------------------------------------------------------------------- 1 | namespace Northwind.ServiceModel.Types 2 | { 3 | using System.Runtime.Serialization; 4 | 5 | [DataContract] 6 | public class CustomerDemographic 7 | { 8 | [DataMember] 9 | public string Id { get; set; } 10 | 11 | [DataMember] 12 | public string CustomerDesc { get; set; } 13 | } 14 | } -------------------------------------------------------------------------------- /src/Northwind/Northwind.ServiceModel/Types/Shipper.cs: -------------------------------------------------------------------------------- 1 | namespace Northwind.ServiceModel.Types 2 | { 3 | using System.Runtime.Serialization; 4 | 5 | [DataContract] 6 | public class Shipper 7 | { 8 | [DataMember] 9 | public int Id { get; set; } 10 | 11 | [DataMember] 12 | public string CompanyName { get; set; } 13 | 14 | [DataMember] 15 | public string Phone { get; set; } 16 | } 17 | } -------------------------------------------------------------------------------- /src/Northwind/Northwind.ServiceModel/Types/Category.cs: -------------------------------------------------------------------------------- 1 | namespace Northwind.ServiceModel.Types 2 | { 3 | using System.Runtime.Serialization; 4 | 5 | [DataContract] 6 | public class Category 7 | { 8 | [DataMember] 9 | public int Id { get; set; } 10 | 11 | [DataMember] 12 | public string CategoryName { get; set; } 13 | 14 | [DataMember] 15 | public string Description { get; set; } 16 | } 17 | } -------------------------------------------------------------------------------- /src/Northwind/Northwind.ServiceModel/Types/Territory.cs: -------------------------------------------------------------------------------- 1 | namespace Northwind.ServiceModel.Types 2 | { 3 | using System.Runtime.Serialization; 4 | 5 | [DataContract] 6 | public class Territory 7 | { 8 | [DataMember] 9 | public string Id { get; set; } 10 | 11 | [DataMember] 12 | public string TerritoryDescription { get; set; } 13 | 14 | [DataMember] 15 | public int RegionId { get; set; } 16 | } 17 | } -------------------------------------------------------------------------------- /src/Northwind/Northwind.ServiceInterface/CustomersService.cs: -------------------------------------------------------------------------------- 1 | using Northwind.ServiceModel; 2 | using Northwind.ServiceModel.Types; 3 | using ServiceStack.OrmLite; 4 | 5 | namespace Northwind.ServiceInterface 6 | { 7 | public class CustomersService : ServiceStack.Service 8 | { 9 | public object Get(Customers request) 10 | { 11 | return new CustomersResponse { Customers = Db.Select() }; 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/Northwind/Northwind.ServiceModel/Types/EmployeeTerritory.cs: -------------------------------------------------------------------------------- 1 | namespace Northwind.ServiceModel.Types 2 | { 3 | using System.Runtime.Serialization; 4 | 5 | [DataContract] 6 | public class EmployeeTerritory 7 | { 8 | public string Id 9 | { 10 | get { return this.EmployeeId + "/" + this.TerritoryId; } 11 | } 12 | 13 | [DataMember] 14 | public int EmployeeId { get; set; } 15 | 16 | [DataMember] 17 | public string TerritoryId { get; set; } 18 | } 19 | } -------------------------------------------------------------------------------- /src/Northwind/Northwind.ServiceModel/Types/CustomerOrders.cs: -------------------------------------------------------------------------------- 1 | namespace Northwind.ServiceModel.Types 2 | { 3 | using System.Collections.Generic; 4 | using System.Runtime.Serialization; 5 | 6 | [DataContract] 7 | public class CustomerOrder 8 | { 9 | public CustomerOrder() 10 | { 11 | this.OrderDetails = new List(); 12 | } 13 | 14 | [DataMember] 15 | public Order Order { get; set; } 16 | 17 | [DataMember] 18 | public List OrderDetails { get; set; } 19 | } 20 | } -------------------------------------------------------------------------------- /src/Northwind/Northwind.ServiceModel/Types/OrderDetail.cs: -------------------------------------------------------------------------------- 1 | namespace Northwind.ServiceModel.Types 2 | { 3 | using System.Runtime.Serialization; 4 | 5 | [DataContract] 6 | public class OrderDetail 7 | { 8 | public string Id 9 | { 10 | get { return this.OrderId + "/" + this.ProductId; } 11 | } 12 | 13 | [DataMember] 14 | public int OrderId { get; set; } 15 | 16 | [DataMember] 17 | public int ProductId { get; set; } 18 | 19 | [DataMember] 20 | public decimal UnitPrice { get; set; } 21 | 22 | [DataMember] 23 | public short Quantity { get; set; } 24 | 25 | [DataMember] 26 | public double Discount { get; set; } 27 | } 28 | } -------------------------------------------------------------------------------- /src/Northwind/Northwind.ServiceModel/Customers.cs: -------------------------------------------------------------------------------- 1 | using ServiceStack; 2 | using System.Collections.Generic; 3 | using System.Runtime.Serialization; 4 | using Northwind.ServiceModel.Types; 5 | 6 | namespace Northwind.ServiceModel 7 | { 8 | [DataContract] 9 | [Route("/customers")] 10 | public class Customers 11 | { 12 | } 13 | 14 | [DataContract] 15 | public class CustomersResponse : IHasResponseStatus 16 | { 17 | public CustomersResponse() 18 | { 19 | this.ResponseStatus = new ResponseStatus(); 20 | this.Customers = new List(); 21 | } 22 | 23 | [DataMember] 24 | public List Customers { get; set; } 25 | 26 | [DataMember] 27 | public ResponseStatus ResponseStatus { get; set; } 28 | } 29 | } -------------------------------------------------------------------------------- /src/Northwind/Northwind.ServiceModel/CachedOperations.cs: -------------------------------------------------------------------------------- 1 | using ServiceStack; 2 | using System.Runtime.Serialization; 3 | 4 | namespace Northwind.ServiceModel 5 | { 6 | [DataContract] 7 | [Route("/cached/customers")] 8 | public class CachedCustomers 9 | { 10 | } 11 | 12 | [DataContract] 13 | [Route("/cached/customers/{Id}")] 14 | public class CachedCustomerDetails 15 | { 16 | [DataMember] 17 | public string Id { get; set; } 18 | } 19 | 20 | [DataContract] 21 | [Route("/cached/orders")] 22 | [Route("/cached/orders/page/{Page}")] 23 | [Route("/cached/customers/{CustomerId}/orders")] 24 | public class CachedOrders 25 | { 26 | [DataMember] 27 | public int? Page { get; set; } 28 | 29 | [DataMember] 30 | public string CustomerId { get; set; } 31 | } 32 | } -------------------------------------------------------------------------------- /src/Northwind/Northwind.ServiceModel/Orders.cs: -------------------------------------------------------------------------------- 1 | using ServiceStack; 2 | using System.Collections.Generic; 3 | using Northwind.ServiceModel.Types; 4 | 5 | namespace Northwind.ServiceModel 6 | { 7 | [Route("/orders")] 8 | [Route("/orders/page/{Page}")] 9 | [Route("/customers/{CustomerId}/orders")] 10 | public class Orders : IReturn 11 | { 12 | public int? Page { get; set; } 13 | 14 | public string CustomerId { get; set; } 15 | } 16 | 17 | public class OrdersResponse : IHasResponseStatus 18 | { 19 | public OrdersResponse() 20 | { 21 | this.ResponseStatus = new ResponseStatus(); 22 | this.Results = new List(); 23 | } 24 | 25 | public List Results { get; set; } 26 | 27 | public ResponseStatus ResponseStatus { get; set; } 28 | } 29 | } -------------------------------------------------------------------------------- /src/Northwind/Northwind.ServiceModel/Types/Product.cs: -------------------------------------------------------------------------------- 1 | namespace Northwind.ServiceModel.Types 2 | { 3 | using System.Runtime.Serialization; 4 | 5 | [DataContract] 6 | public class Product 7 | { 8 | [DataMember] 9 | public int Id { get; set; } 10 | 11 | [DataMember] 12 | public string ProductName { get; set; } 13 | 14 | [DataMember] 15 | public int SupplierId { get; set; } 16 | 17 | [DataMember] 18 | public int CategoryId { get; set; } 19 | 20 | [DataMember] 21 | public string QuantityPerUnit { get; set; } 22 | 23 | [DataMember] 24 | public decimal UnitPrice { get; set; } 25 | 26 | [DataMember] 27 | public short UnitsInStock { get; set; } 28 | 29 | [DataMember] 30 | public short UnitsOnOrder { get; set; } 31 | 32 | [DataMember] 33 | public short ReorderLevel { get; set; } 34 | 35 | [DataMember] 36 | public bool Discontinued { get; set; } 37 | } 38 | } -------------------------------------------------------------------------------- /src/Northwind/Northwind.ServiceModel/Types/Supplier.cs: -------------------------------------------------------------------------------- 1 | namespace Northwind.ServiceModel.Types 2 | { 3 | using System.Runtime.Serialization; 4 | 5 | [DataContract] 6 | public class Supplier 7 | { 8 | [DataMember] 9 | public int Id { get; set; } 10 | 11 | [DataMember] 12 | public string CompanyName { get; set; } 13 | 14 | [DataMember] 15 | public string ContactName { get; set; } 16 | 17 | [DataMember] 18 | public string ContactTitle { get; set; } 19 | 20 | [DataMember] 21 | public string Address { get; set; } 22 | 23 | [DataMember] 24 | public string City { get; set; } 25 | 26 | [DataMember] 27 | public string Region { get; set; } 28 | 29 | [DataMember] 30 | public string PostalCode { get; set; } 31 | 32 | [DataMember] 33 | public string Country { get; set; } 34 | 35 | [DataMember] 36 | public string Phone { get; set; } 37 | 38 | [DataMember] 39 | public string Fax { get; set; } 40 | 41 | [DataMember] 42 | public string HomePage { get; set; } 43 | } 44 | } -------------------------------------------------------------------------------- /src/Northwind/Northwind.ServiceModel/CustomerDetails.cs: -------------------------------------------------------------------------------- 1 | using ServiceStack; 2 | using System.Collections.Generic; 3 | using System.Runtime.Serialization; 4 | using Northwind.ServiceModel.Types; 5 | 6 | namespace Northwind.ServiceModel 7 | { 8 | [DataContract] 9 | [Route("/customers/{Id}")] 10 | public class CustomerDetails 11 | { 12 | [DataMember] 13 | public string Id { get; set; } 14 | } 15 | 16 | [DataContract] 17 | public class CustomerDetailsResponse : IHasResponseStatus 18 | { 19 | public CustomerDetailsResponse() 20 | { 21 | this.ResponseStatus = new ResponseStatus(); 22 | this.CustomerOrders = new List(); 23 | } 24 | 25 | [DataMember] 26 | public Customer Customer { get; set; } 27 | 28 | [DataMember] 29 | public List CustomerOrders { get; set; } 30 | 31 | [DataMember] 32 | public ResponseStatus ResponseStatus { get; set; } 33 | } 34 | } -------------------------------------------------------------------------------- /src/Northwind/Northwind.ServiceInterface/CustomerDetailsService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Net; 3 | using Northwind.ServiceModel; 4 | using Northwind.ServiceModel.Types; 5 | using ServiceStack; 6 | using ServiceStack.OrmLite; 7 | 8 | namespace Northwind.ServiceInterface 9 | { 10 | public class CustomerDetailsService : Service 11 | { 12 | public CustomerDetailsResponse Get(CustomerDetails request) 13 | { 14 | var customer = Db.SingleById(request.Id); 15 | if (customer == null) 16 | throw new HttpError(HttpStatusCode.NotFound, 17 | new ArgumentException("Customer does not exist: " + request.Id)); 18 | 19 | var ordersResponse = base.Gateway.Send(new Orders { CustomerId = customer.Id }); 20 | return new CustomerDetailsResponse 21 | { 22 | Customer = customer, 23 | CustomerOrders = ordersResponse.Results, 24 | }; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Northwind/Northwind.ServiceModel/Types/Customer.cs: -------------------------------------------------------------------------------- 1 | namespace Northwind.ServiceModel.Types 2 | { 3 | using System.Runtime.Serialization; 4 | 5 | [DataContract] 6 | public class Customer 7 | { 8 | [DataMember] 9 | public string Id { get; set; } 10 | 11 | [DataMember] 12 | public string CompanyName { get; set; } 13 | 14 | [DataMember] 15 | public string ContactName { get; set; } 16 | 17 | [DataMember] 18 | public string ContactTitle { get; set; } 19 | 20 | [DataMember] 21 | public string Address { get; set; } 22 | 23 | [DataMember] 24 | public string City { get; set; } 25 | 26 | [DataMember] 27 | public string Region { get; set; } 28 | 29 | [DataMember] 30 | public string PostalCode { get; set; } 31 | 32 | [DataMember] 33 | public string Country { get; set; } 34 | 35 | [DataMember] 36 | public string Phone { get; set; } 37 | 38 | [DataMember] 39 | public string Fax { get; set; } 40 | 41 | public string Email 42 | { 43 | get { return this.ContactName.Replace(" ", ".").ToLower() + "@gmail.com"; } 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## [Northwind](https://github.com/ServiceStackApps/Northwind) 2 | 3 | > Northwind database viewer, showing how to easily expose read and cached view services of an internal dataset with ServiceStack + OrmLite 4 | 5 | [![](https://raw.githubusercontent.com/ServiceStack/Assets/master/img/livedemos/northwind.png)](http://northwind.servicestack.net) 6 | 7 | #### Features 8 | 9 | - [AutoQuery](http://docs.servicestack.net/autoquery-rdbms.html) 10 | - [OrmLite Sqlite](https://github.com/ServiceStack.OrmLite) 11 | - [Multiple automatic built-in Content-Types](http://northwind.servicestack.net/default.htm) 12 | - [Custom Media Types - Adding vcard format](http://northwind.servicestack.net/vcard-format.htm) 13 | - [1 CachedService](https://github.com/ServiceStackApps/Northwind/blob/master/src/Northwind/Northwind.ServiceInterface/CachedServices.cs) 14 | 15 | Try it out live at: [northwind.servicestack.net](http://northwind.servicestack.net) 16 | 17 | Follow [@ServiceStack](http://twitter.com/ServiceStack) or [+ServiceStack](https://plus.google.com/u/0/communities/112445368900682590445) for updates. 18 | -------------------------------------------------------------------------------- /src/Northwind/Northwind.ServiceModel/Types/Order.cs: -------------------------------------------------------------------------------- 1 | namespace Northwind.ServiceModel.Types 2 | { 3 | using System; 4 | using System.Runtime.Serialization; 5 | 6 | [DataContract] 7 | public class Order 8 | { 9 | [DataMember] 10 | public int Id { get; set; } 11 | 12 | [DataMember] 13 | public string CustomerId { get; set; } 14 | 15 | [DataMember] 16 | public int EmployeeId { get; set; } 17 | 18 | [DataMember] 19 | public DateTime? OrderDate { get; set; } 20 | 21 | [DataMember] 22 | public DateTime? RequiredDate { get; set; } 23 | 24 | [DataMember] 25 | public DateTime? ShippedDate { get; set; } 26 | 27 | [DataMember] 28 | public int? ShipVia { get; set; } 29 | 30 | [DataMember] 31 | public decimal Freight { get; set; } 32 | 33 | [DataMember] 34 | public string ShipName { get; set; } 35 | 36 | [DataMember] 37 | public string ShipAddress { get; set; } 38 | 39 | [DataMember] 40 | public string ShipCity { get; set; } 41 | 42 | [DataMember] 43 | public string ShipRegion { get; set; } 44 | 45 | [DataMember] 46 | public string ShipPostalCode { get; set; } 47 | 48 | [DataMember] 49 | public string ShipCountry { get; set; } 50 | } 51 | } -------------------------------------------------------------------------------- /src/Northwind/Northwind/Global.asax.cs: -------------------------------------------------------------------------------- 1 | 2 | using System; 3 | using System.Web; 4 | using Funq; 5 | using ServiceStack; 6 | using Northwind.ServiceInterface; 7 | using ServiceStack.Admin; 8 | using ServiceStack.OrmLite; 9 | using ServiceStack.Data; 10 | 11 | namespace Northwind 12 | { 13 | public class AppHost : AppHostBase 14 | { 15 | public AppHost() : base("Northwind Web Services", typeof(CustomersService).Assembly) { } 16 | 17 | public override void Configure(Container container) 18 | { 19 | container.Register( 20 | new OrmLiteConnectionFactory("~/Northwind.sqlite".MapHostAbsolutePath(), SqliteDialect.Provider)); 21 | 22 | //Use Redis Cache 23 | //container.Register(new PooledRedisClientManager()); 24 | 25 | VCardFormat.Register(this); 26 | 27 | Plugins.Add(new AutoQueryFeature { MaxLimit = 100 }); 28 | Plugins.Add(new AdminFeature()); 29 | 30 | Plugins.Add(new CorsFeature()); 31 | } 32 | } 33 | 34 | public class Global : HttpApplication 35 | { 36 | protected void Application_Start(object sender, EventArgs e) 37 | { 38 | new AppHost().Init(); 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /src/Northwind/Northwind/Properties/PublishProfiles/WebDeploy.pubxml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | MSDeploy 9 | Release 10 | Any CPU 11 | northwind.servicestack.net 12 | True 13 | False 14 | awstest.servicestack.net 15 | Northwind 16 | 17 | True 18 | WMSVC 19 | True 20 | deploy 21 | <_SavePWD>True 22 | False 23 | 24 | -------------------------------------------------------------------------------- /src/Northwind/Northwind.ServiceModel/Types/Employee.cs: -------------------------------------------------------------------------------- 1 | namespace Northwind.ServiceModel.Types 2 | { 3 | using System; 4 | using System.Runtime.Serialization; 5 | 6 | [DataContract] 7 | public class Employee 8 | { 9 | [DataMember] 10 | public int Id { get; set; } 11 | 12 | [DataMember] 13 | public string LastName { get; set; } 14 | 15 | [DataMember] 16 | public string FirstName { get; set; } 17 | 18 | [DataMember] 19 | public string Title { get; set; } 20 | 21 | [DataMember] 22 | public string TitleOfCourtesy { get; set; } 23 | 24 | [DataMember] 25 | public DateTime? BirthDate { get; set; } 26 | 27 | [DataMember] 28 | public DateTime? HireDate { get; set; } 29 | 30 | [DataMember] 31 | public string Address { get; set; } 32 | 33 | [DataMember] 34 | public string City { get; set; } 35 | 36 | [DataMember] 37 | public string Region { get; set; } 38 | 39 | [DataMember] 40 | public string PostalCode { get; set; } 41 | 42 | [DataMember] 43 | public string Country { get; set; } 44 | 45 | [DataMember] 46 | public string HomePhone { get; set; } 47 | 48 | [DataMember] 49 | public string Extension { get; set; } 50 | 51 | public byte[] Photo { get; set; } 52 | 53 | [DataMember] 54 | public string Notes { get; set; } 55 | 56 | [DataMember] 57 | public int? ReportsTo { get; set; } 58 | 59 | [DataMember] 60 | public string PhotoPath { get; set; } 61 | } 62 | } -------------------------------------------------------------------------------- /src/Northwind/Northwind.ServiceInterface/CachedServices.cs: -------------------------------------------------------------------------------- 1 | using Northwind.ServiceModel; 2 | using ServiceStack; 3 | 4 | namespace Northwind.ServiceInterface 5 | { 6 | public class CachedServices : Service 7 | { 8 | public object Get(CachedCustomers request) 9 | { 10 | return base.Request.ToOptimizedResultUsingCache(this.Cache, 11 | "urn:customers", () => 12 | this.ResolveService() 13 | .Get(new Customers())); 14 | } 15 | 16 | public object Get(CachedCustomerDetails request) 17 | { 18 | var cacheKey = UrnId.Create(request.Id); 19 | 20 | return base.Request.ToOptimizedResultUsingCache(this.Cache, 21 | cacheKey, () => 22 | this.ResolveService() 23 | .Get(new CustomerDetails { Id = request.Id })); 24 | } 25 | 26 | public object Get(CachedOrders request) 27 | { 28 | var cacheKey = UrnId.Create(request.CustomerId ?? "all", request.Page.GetValueOrDefault(0).ToString()); 29 | 30 | return base.Request.ToOptimizedResultUsingCache(Cache, 31 | cacheKey, () => 32 | this.ResolveService() 33 | .Get(new Orders { CustomerId = request.CustomerId, Page = request.Page })); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Northwind/Northwind.ServiceInterface/OrdersService.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using Northwind.ServiceModel; 3 | using Northwind.ServiceModel.Types; 4 | using ServiceStack; 5 | using ServiceStack.OrmLite; 6 | 7 | namespace Northwind.ServiceInterface 8 | { 9 | public class OrdersService : Service 10 | { 11 | private const int PageCount = 20; 12 | 13 | public OrdersResponse Get(Orders request) 14 | { 15 | var orders = request.CustomerId.IsNullOrEmpty() 16 | ? Db.Select(Db.From().OrderByDescending(o => o.OrderDate)) 17 | .Skip((request.Page.GetValueOrDefault(1) - 1) * PageCount) 18 | .Take(PageCount) 19 | .ToList() 20 | : Db.Select(x => x.CustomerId == request.CustomerId); 21 | 22 | if (orders.Count == 0) 23 | return new OrdersResponse(); 24 | 25 | var orderDetails = Db.Select(detail => Sql.In(detail.OrderId, orders.ConvertAll(x => x.Id))); 26 | 27 | var orderDetailsLookup = orderDetails.ToLookup(o => o.OrderId); 28 | 29 | var customerOrders = orders.ConvertAll(o => new CustomerOrder 30 | { 31 | Order = o, 32 | OrderDetails = orderDetailsLookup[o.Id].ToList() 33 | }); 34 | 35 | return new OrdersResponse { Results = customerOrders }; 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Northwind/Northwind/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Northwind")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Northwind")] 13 | [assembly: AssemblyCopyright("Copyright © 2011")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("3d5900ae-111a-45be-96b3-d9e4606ca793")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Revision and Build Numbers 33 | // by using the '*' as shown below: 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /src/Northwind/Northwind.ServiceInterface/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Northwind.ServiceInterface")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Northwind.ServiceInterface")] 13 | [assembly: AssemblyCopyright("Copyright © 2011")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("09a6902b-528b-41d0-b79e-a5518c89c315")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /src/Northwind/Northwind.ServiceModel/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | using System.Runtime.Serialization; 5 | 6 | // General Information about an assembly is controlled through the following 7 | // set of attributes. Change these attribute values to modify the information 8 | // associated with an assembly. 9 | [assembly: AssemblyTitle("Northwind.ServiceModel")] 10 | [assembly: AssemblyDescription("")] 11 | [assembly: AssemblyConfiguration("")] 12 | [assembly: AssemblyCompany("")] 13 | [assembly: AssemblyProduct("Northwind.ServiceModel")] 14 | [assembly: AssemblyCopyright("Copyright © 2011")] 15 | [assembly: AssemblyTrademark("")] 16 | [assembly: AssemblyCulture("")] 17 | 18 | // Setting ComVisible to false makes the types in this assembly not visible 19 | // to COM components. If you need to access a type in this assembly from 20 | // COM, set the ComVisible attribute to true on that type. 21 | [assembly: ComVisible(false)] 22 | 23 | // The following GUID is for the ID of the typelib if this project is exposed to COM 24 | [assembly: Guid("ffcb238e-d6ec-4c54-af20-de954fbd02f4")] 25 | 26 | // Version information for an assembly consists of the following four values: 27 | // 28 | // Major Version 29 | // Minor Version 30 | // Build Number 31 | // Revision 32 | // 33 | // You can specify all the values or you can default the Build and Revision Numbers 34 | // by using the '*' as shown below: 35 | // [assembly: AssemblyVersion("1.0.*")] 36 | [assembly: AssemblyVersion("1.0.0.0")] 37 | [assembly: AssemblyFileVersion("1.0.0.0")] 38 | 39 | [assembly: ContractNamespace("http://schemas.servicestack.net/types", ClrNamespace = "Northwind.ServiceModel")] 40 | [assembly: ContractNamespace("http://schemas.servicestack.net/types", ClrNamespace = "Northwind.ServiceModel.Operations")] 41 | 42 | -------------------------------------------------------------------------------- /src/Northwind/Northwind/Web.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /src/Northwind/Northwind.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2012 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Northwind", "Northwind\Northwind.csproj", "{3E968D84-7C23-42E9-A443-6355FAA845E2}" 5 | EndProject 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Northwind.ServiceModel", "Northwind.ServiceModel\Northwind.ServiceModel.csproj", "{14856482-95D3-4A02-968C-665F3D08F94D}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Northwind.ServiceInterface", "Northwind.ServiceInterface\Northwind.ServiceInterface.csproj", "{A724F80D-4341-4ECA-AC43-CF84A3F03779}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {3E968D84-7C23-42E9-A443-6355FAA845E2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {3E968D84-7C23-42E9-A443-6355FAA845E2}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {3E968D84-7C23-42E9-A443-6355FAA845E2}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {3E968D84-7C23-42E9-A443-6355FAA845E2}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {14856482-95D3-4A02-968C-665F3D08F94D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {14856482-95D3-4A02-968C-665F3D08F94D}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {14856482-95D3-4A02-968C-665F3D08F94D}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {14856482-95D3-4A02-968C-665F3D08F94D}.Release|Any CPU.Build.0 = Release|Any CPU 24 | {A724F80D-4341-4ECA-AC43-CF84A3F03779}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 25 | {A724F80D-4341-4ECA-AC43-CF84A3F03779}.Debug|Any CPU.Build.0 = Debug|Any CPU 26 | {A724F80D-4341-4ECA-AC43-CF84A3F03779}.Release|Any CPU.ActiveCfg = Release|Any CPU 27 | {A724F80D-4341-4ECA-AC43-CF84A3F03779}.Release|Any CPU.Build.0 = Release|Any CPU 28 | EndGlobalSection 29 | GlobalSection(SolutionProperties) = preSolution 30 | HideSolutionNode = FALSE 31 | EndGlobalSection 32 | EndGlobal 33 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Build Folders (you can keep bin if you'd like, to store dlls and pdbs) 2 | [Bb]in/ 3 | [Oo]bj/ 4 | .idea/ 5 | .vs/ 6 | 7 | # mstest test results 8 | TestResults 9 | 10 | ## Ignore Visual Studio temporary files, build results, and 11 | ## files generated by popular Visual Studio add-ons. 12 | 13 | # User-specific files 14 | *.suo 15 | *.user 16 | *.sln.docstates 17 | *.secrets.cs 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Rr]elease/ 22 | deploy/ 23 | x64/ 24 | *_i.c 25 | *_p.c 26 | *.ilk 27 | *.meta 28 | *.obj 29 | *.pch 30 | *.pdb 31 | *.pgc 32 | *.pgd 33 | *.rsp 34 | *.sbr 35 | *.tlb 36 | *.tli 37 | *.tlh 38 | *.tmp 39 | *.log 40 | *.txt 41 | *.vspscc 42 | *.vssscc 43 | .builds 44 | 45 | # Visual C++ cache files 46 | ipch/ 47 | *.aps 48 | *.ncb 49 | *.opensdf 50 | *.sdf 51 | 52 | # Visual Studio profiler 53 | *.psess 54 | *.vsp 55 | *.vspx 56 | 57 | # Guidance Automation Toolkit 58 | *.gpState 59 | 60 | # ReSharper is a .NET coding add-in 61 | _ReSharper* 62 | 63 | # NCrunch 64 | *.ncrunch* 65 | .*crunch*.local.xml 66 | 67 | # Installshield output folder 68 | [Ee]xpress 69 | 70 | # DocProject is a documentation generator add-in 71 | DocProject/buildhelp/ 72 | DocProject/Help/*.HxT 73 | DocProject/Help/*.HxC 74 | DocProject/Help/*.hhc 75 | DocProject/Help/*.hhk 76 | DocProject/Help/*.hhp 77 | DocProject/Help/Html2 78 | DocProject/Help/html 79 | 80 | # Click-Once directory 81 | publish 82 | 83 | # Publish Web Output 84 | *.Publish.xml 85 | 86 | # NuGet Packages Directory 87 | packages 88 | 89 | # Windows Azure Build Output 90 | csx 91 | *.build.csdef 92 | 93 | # Windows Store app package directory 94 | AppPackages/ 95 | 96 | # Others 97 | [Bb]in 98 | [Oo]bj 99 | sql 100 | *.Cache 101 | ClientBin 102 | [Ss]tyle[Cc]op.* 103 | ~$* 104 | *.dbmdl 105 | 106 | Generated_Code #added for RIA/Silverlight projects 107 | 108 | # Backup & report files from converting an old project file to a newer 109 | # Visual Studio version. Backup files are not needed, because we have git ;-) 110 | _UpgradeReport_Files/ 111 | Backup*/ 112 | UpgradeLog*.XML 113 | 114 | ssl/ 115 | *.crt 116 | *.ssl 117 | *.pem 118 | results/ 119 | teststub.* 120 | *.sqlite 121 | -------------------------------------------------------------------------------- /src/Northwind/Northwind.ServiceInterface/VCardFormat.cs: -------------------------------------------------------------------------------- 1 | using Northwind.ServiceModel; 2 | using ServiceStack; 3 | using ServiceStack.Web; 4 | using System; 5 | using System.IO; 6 | 7 | 8 | namespace Northwind.ServiceInterface 9 | { 10 | using ServiceModel.Types; 11 | 12 | public class VCardFormat 13 | { 14 | private const string VCardContentType = "text/x-vcard"; 15 | 16 | public static void Register(IAppHost appHost) 17 | { 18 | appHost.ContentTypes.Register(VCardContentType, SerializeToStream, DeserializeFromStream); 19 | 20 | appHost.GlobalResponseFilters.Add((req, res, dto) => 21 | { 22 | if (req.ResponseContentType == VCardContentType) 23 | { 24 | res.AddHeader(HttpHeaders.ContentDisposition, 25 | string.Format("attachment;filename={0}.vcf", req.OperationName)); 26 | } 27 | }); 28 | } 29 | 30 | public static void SerializeToStream(IRequest req, object response, Stream stream) 31 | { 32 | var customerResponse = response as CustomerDetailsResponse; 33 | using (var sw = new StreamWriter(stream)) 34 | { 35 | if (customerResponse != null) 36 | { 37 | WriteCustomer(sw, customerResponse.Customer); 38 | } 39 | var customers = response as CustomersResponse; 40 | if (customers != null) 41 | { 42 | customers.Customers.ForEach(x => WriteCustomer(sw, x)); 43 | } 44 | } 45 | } 46 | 47 | public static void WriteCustomer(StreamWriter sw, Customer customer) 48 | { 49 | sw.WriteLine("BEGIN:VCARD"); 50 | sw.WriteLine("VERSION:2.1"); 51 | sw.WriteLine("FN:" + customer.ContactName); 52 | sw.WriteLine("ORG:" + customer.CompanyName); 53 | sw.WriteLine("TITLE:" + customer.ContactTitle); 54 | sw.WriteLine("EMAIL;TYPE=PREF,INTERNET:" + customer.Email); 55 | sw.WriteLine("TEL;HOME;VOICE:" + customer.Phone); 56 | sw.WriteLine("TEL;WORK;FAX:" + customer.Fax); 57 | sw.WriteLine("ADR;TYPE=HOME;" 58 | + new[] { customer.Address, customer.City, customer.PostalCode }.Join(";")); 59 | sw.WriteLine("END:VCARD"); 60 | } 61 | 62 | public static object DeserializeFromStream(Type type, Stream stream) 63 | { 64 | throw new NotImplementedException(); 65 | } 66 | } 67 | } -------------------------------------------------------------------------------- /src/Northwind/Northwind.ServiceInterface/Northwind.ServiceInterface.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | 9.0.30729 7 | 2.0 8 | {A724F80D-4341-4ECA-AC43-CF84A3F03779} 9 | Library 10 | Properties 11 | Northwind.ServiceInterface 12 | Northwind.ServiceInterface 13 | v4.7.2 14 | 512 15 | 16 | 17 | 3.5 18 | 19 | publish\ 20 | true 21 | Disk 22 | false 23 | Foreground 24 | 7 25 | Days 26 | false 27 | false 28 | true 29 | 0 30 | 1.0.0.%2a 31 | false 32 | false 33 | true 34 | ..\ 35 | true 36 | 37 | default 38 | 39 | 40 | true 41 | full 42 | false 43 | bin\Debug\ 44 | DEBUG;TRACE 45 | prompt 46 | 4 47 | AllRules.ruleset 48 | false 49 | 50 | 51 | pdbonly 52 | true 53 | bin\Release\ 54 | TRACE 55 | prompt 56 | 4 57 | AllRules.ruleset 58 | false 59 | 60 | 61 | 62 | 63 | 3.5 64 | 65 | 66 | 3.5 67 | 68 | 69 | 3.5 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | False 85 | .NET Framework 3.5 SP1 Client Profile 86 | false 87 | 88 | 89 | False 90 | .NET Framework 3.5 SP1 91 | true 92 | 93 | 94 | False 95 | Windows Installer 3.1 96 | true 97 | 98 | 99 | 100 | 101 | {14856482-95d3-4a02-968c-665f3d08f94d} 102 | Northwind.ServiceModel 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 124 | -------------------------------------------------------------------------------- /src/Northwind/Northwind.ServiceModel/Northwind.ServiceModel.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | 9.0.30729 7 | 2.0 8 | {14856482-95D3-4A02-968C-665F3D08F94D} 9 | Library 10 | Properties 11 | Northwind.ServiceModel 12 | Northwind.ServiceModel 13 | v4.7.2 14 | 512 15 | 16 | 17 | 3.5 18 | 19 | publish\ 20 | true 21 | Disk 22 | false 23 | Foreground 24 | 7 25 | Days 26 | false 27 | false 28 | true 29 | 0 30 | 1.0.0.%2a 31 | false 32 | false 33 | true 34 | ..\ 35 | true 36 | 37 | default 38 | 39 | 40 | true 41 | full 42 | false 43 | bin\Debug\ 44 | DEBUG;TRACE 45 | prompt 46 | 4 47 | AllRules.ruleset 48 | false 49 | 50 | 51 | pdbonly 52 | true 53 | bin\Release\ 54 | TRACE 55 | prompt 56 | 4 57 | AllRules.ruleset 58 | false 59 | 60 | 61 | 62 | 63 | 3.5 64 | 65 | 66 | 3.0 67 | 68 | 69 | 3.5 70 | 71 | 72 | 3.5 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | False 102 | .NET Framework 3.5 SP1 Client Profile 103 | false 104 | 105 | 106 | False 107 | .NET Framework 3.5 SP1 108 | true 109 | 110 | 111 | False 112 | Windows Installer 3.1 113 | true 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 135 | -------------------------------------------------------------------------------- /src/Northwind/Northwind/Northwind.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | 9.0.30729 8 | 2.0 9 | {3E968D84-7C23-42E9-A443-6355FAA845E2} 10 | {349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} 11 | Library 12 | Properties 13 | Northwind 14 | Northwind 15 | v4.7.2 16 | 17 | 18 | 4.0 19 | 20 | 21 | true 22 | 23 | 24 | 25 | 26 | ..\ 27 | true 28 | 29 | 30 | 31 | 32 | 33 | default 34 | 35 | 36 | true 37 | full 38 | false 39 | bin\ 40 | DEBUG;TRACE 41 | prompt 42 | 4 43 | AllRules.ruleset 44 | x86 45 | false 46 | 47 | 48 | pdbonly 49 | true 50 | bin\ 51 | TRACE 52 | prompt 53 | 4 54 | AllRules.ruleset 55 | x86 56 | false 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | Designer 88 | 89 | 90 | 91 | 92 | Global.asax 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | {a724f80d-4341-4eca-ac43-cf84a3f03779} 106 | Northwind.ServiceInterface 107 | 108 | 109 | {14856482-95d3-4a02-968c-665f3d08f94d} 110 | Northwind.ServiceModel 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 10.0 127 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 128 | 129 | 130 | 131 | 132 | 139 | 140 | 141 | 142 | 143 | false 144 | True 145 | 51340 146 | / 147 | http://localhost/ServiceStack.Northwind 148 | False 149 | false 150 | 151 | 152 | False 153 | 154 | 155 | 156 | 157 | 158 | -------------------------------------------------------------------------------- /src/Northwind/Northwind/vcard-format.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Custom media types vs data formats 5 | 141 | 142 | 143 | 144 | ServiceStack Home 146 | 147 |
148 | 149 |

Custom media types - Adding the VCard Format

150 |

151 | An often overlooked feature in ServiceStack is its ability to easily support custom media types and formats. 152 |

153 | 154 |

Specific Media Types vs Data Formats

155 |

156 | It's not given as much prominence as ServiceStack's other formats simply because supporting specific media types 157 | require more custom development effort so are unlike other built-in ServiceStack generic data formats 158 | (JSON, XML, CSV, JSV, HTML, SOAP) that are automatically available to all your services without any extra effort. 159 |

160 | 161 |

Creating the VCard Custom Media Type

162 | 163 |

164 | At times when your clients have built-in support for a specific media-type it can allow richer functionality and 165 | a deeper integration into users applications than what would otherwise be possible. An example of this is 166 | allowing users to import contact information directly into Outlook by providing contact information 167 | in the VCard Format, which you can make available for instance 168 | on the results page on an online contact directory search. 169 |

170 | 171 |

172 | So when it's beneficial to, adding Custom Media Types in Service Stack is easy where in just 1 Line of Code you 173 | can register your format and have it immediately availble in ServiceStack's REST pipeline and auto-generated 174 | /metadata pages. 175 |

176 | 177 |

178 | Below is a live example of what is possible when we add the VCard format to the Northwinds Customer web services. 179 | It allows us to provide the unusual relationship giving our MONO web server deep access into your Windows Outlook client :) 180 |

181 | 182 | Maria Anders VCard 183 | 184 |

Supporting the VCard Format in ServiceStack

185 |

186 | Like the 187 | HTML and 188 | CSV 189 | formats before it, the best way to add an additional Media Type in ServiceStack is to encapsulate it in a single 190 | class keeping it loosely-coupled from the rest of your system thus making it an easy drop-in or removal whenever you need it. 191 | The entire support for the format is contained in 192 | VCardFormat.cs 193 | and is explained below: 194 |

195 | 196 |

Registering a custom format in ServiceStack

197 |

198 | In the Register() method we simply tell ServiceStack that we have a new ContentType available and 199 | supply the Stream serialisers that it should use whenever processing that ContentType. 200 |

201 |

202 | With just this 1 line of config: 203 | appHost.ContentTypeFilters.Register(VCardContentType, SerializeToStream, DeserializeFromStream);
204 | We now have your custom format registered into ServiceStack who will now use the supplied Content serializers 205 | whenever this Content-Type is requested by the client in any of the following ways: 206 |

207 | 208 | 213 | 214 |

215 | Another benefit ServiceStack gives you is that this format is automatically provided on the auto-generated 216 | /metadata page.
217 | This is what the Customers X-VCARD metadata page looks like: /x-vcard/metadata?op=Customers 218 |

219 | 220 |

221 | The ResponseFilter is added to intercept the response and a Content-Disposition HTTP header added to signal to the 222 | browser that this resource is to be treated as an attachment using the prescribed filename. 223 |

224 | 225 | private const string VCardContentType = "text/x-vcard"; 226 | 227 | public static void Register(IAppHost appHost) 228 | { 229 | appHost.ContentTypeFilters.Register(VCardContentType, SerializeToStream, DeserializeFromStream); 230 | 231 | appHost.ResponseFilters.Add((req, res, dto) => 232 | { 233 | if (req.ResponseContentType == VCardContentType) 234 | { 235 | res.AddHeader(HttpHeaders.ContentDisposition, 236 | string.Format("attachment;filename={0}.vcf", req.OperationName)); 237 | } 238 | }); 239 | } 240 | 241 |

242 | With the x-vcard format now registered in ServiceStack, the only thing left to to is implement 243 | the Content-Type SerializeToStream routine. Unlike the data formats it is not as simple as just 244 | serioulizing the Respone DTO. In this case we need to detect if the response DTO contains a customer 245 | and if it does return its data in the VCard format. 246 |

247 | 248 | public static void SerializeToStream(IRequestContext requestContext, object response, Stream stream) 249 | { 250 | var customerDetailsResponse = response as CustomerDetailsResponse; 251 | using (var sw = new StreamWriter(stream)) 252 | { 253 | if (customerDetailsResponse != null) 254 | { 255 | WriteCustomer(sw, customerDetailsResponse.Customer); 256 | } 257 | var customers = response as CustomersResponse; 258 | if (customers != null) 259 | { 260 | customers.Customers.ForEach(x => WriteCustomer(sw, x)); 261 | } 262 | } 263 | } 264 | 265 | public static void WriteCustomer(StreamWriter sw, Customer customer) 266 | { 267 | sw.WriteLine("BEGIN:VCARD"); 268 | sw.WriteLine("VERSION:2.1"); 269 | sw.WriteLine("FN:" + customer.ContactName); 270 | sw.WriteLine("ORG:" + customer.CompanyName); 271 | sw.WriteLine("TITLE:" + customer.ContactTitle); 272 | sw.WriteLine("EMAIL;TYPE=PREF,INTERNET:" + customer.Email); 273 | sw.WriteLine("TEL;HOME;VOICE:" + customer.Phone); 274 | sw.WriteLine("TEL;WORK;FAX:" + customer.Fax); 275 | sw.WriteLine("ADR;TYPE=HOME;" 276 | + new[] { customer.Address, customer.City, customer.PostalCode }.Join(";")); 277 | sw.WriteLine("END:VCARD"); 278 | } 279 | 280 |

281 | And that's the entire VCard format in a single loosely-coupled class. 282 | No other concepts / artefacts are required to make this work, you can just simply plug it 283 | into ServiceStack the the following 1 Line of Code: 284 |

285 | 286 | public override void Configure(Container container) 287 | { 288 | VCardFormat.Register(this); 289 | } 290 | 291 |
292 | 293 | 294 | -------------------------------------------------------------------------------- /src/Northwind/Northwind/default.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Northwind Web Services 5 | 144 | 145 | 146 | 147 | ServiceStack Home 149 | 150 | Northwind project 151 | 152 |
153 |

Northwind Web Services

154 | 155 |

156 | The Northwind Web Services Example project explores different features of ServiceStack 157 | using data from Northwind SQlite Database. 158 |

159 | 160 |

Rest Services

161 |

162 | ServiceStack's REST Services, are just normal Web Services with the addition of a [Route] attribute 163 | that allows you to provide the canonical / permanent location for your web service. 164 |

165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 250 | 251 | 252 |
PathFormatsCode
All Customerscustomersjsonxmlhtmlcsvjsvx-vcardCustomersService.cs
Customer Maria Anderscustomers/ALFKIjsonxmlhtmlcsvjsvx-vcardCustomerDetailsService.cs
Customer Maria Anders Orderscustomers/ALFKI/ordersjsonxmlhtmlcsvjsvOrdersService.cs
Latest OrdersordersjsonxmlhtmlcsvjsvOrdersService.cs
Latest Orders - page 2orders/page/2jsonxmlhtmlcsvjsvOrdersService.cs
Northwind AutoQuery Services
Customers/query/customersjsonxmlhtmlcsvjsvAutoQuery.cs
Countries Starting With 'U'CountryStartsWith=UjsonxmlhtmlcsvjsvAutoQuery.cs
Customers IN (CHOPS,FRANK)Ids=CHOPS,FRANKjsonxmlhtmlcsvjsvAutoQuery.cs
Orders/query/ordersjsonxmlhtmlcsvjsvAutoQuery.cs
Freight more than $300Freight>=300jsonxmlhtmlcsvjsvAutoQuery.cs
Orders by Customer, Id DescOrderBy=CustomerId,-IdjsonxmlhtmlcsvjsvAutoQuery.cs
248 | AutoQuery UI for Northwind Services 249 |
253 | 254 |

255 | The entire datasource for the Northwind project is contained in this Northwind.sqlite database 256 | created by this unit test. 257 |

258 | 259 | VCard Custom MediaType 260 |

Adding Custom Media Types - The VCard format

261 |

262 | The Northwind database also includes the addition of the VCard custom media format.
263 | Checkout the walk thru to see how to create your own Custom Media Types with ServiceStack:
264 |

vcard-format.htm

265 |

266 | 267 | 268 |

Cached Rest Services

269 |

270 | As it's important for high-performance web services, ServiceStack includes a rich caching provider framework with 271 | Redis, Memcached, Memory and FileSystem-based cache providers 272 | available. 273 |

274 |

275 | To compare the difference with caching enabled, below are the 'cached versions' of the REST services above. 276 |

277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 |
PathFormatsCode
All Customerscached/customersjsonxmlhtmlcsvjsvCachedServices.cs
Customer Maria Anderscached/customers/ALFKIjsonxmlhtmlcsvjsvCachedServices.cs
Customer Maria Anders Orderscached/customers/ALFKI/ordersjsonxmlhtmlcsvjsvCachedServices.cs
Latest Orderscached/ordersjsonxmlhtmlcsvjsvCachedServices.cs
Latest Orders - page 2cached/orders/page/2jsonxmlhtmlcsvjsvCachedServices.cs
320 | 321 |

322 | Note: The most optimal result is cached, i.e. if your browser supports gzip/deflate it will cache the compressed output. 323 | Caching also supports all user-defined formats. 324 |

325 | 326 |

Advantages of a convention-based Web Services framework

327 |

Nothing but C#

328 |

329 | The Northwind project is also an example of how much can be achieved with a minimal amount of effort and code. 330 | This entire website literally just consists of 331 | 332 | these 333 | three 334 | classes 335 | . Everything else seen here is automatically provided by ServiceStack using a code-first, convention-based approach. 336 | ServiceStack can infer a richer intelligence about your services to better able to provide more generic and re-usable functionality for free! 337 |

338 |

339 | You're unlikley to ever see the same WCF SOAP service, generating a visually informative 340 | HTML view of your data, 341 | allow it to be exposed over REST-ful interfaces or be able to export it to a CSV data file. 342 | With ServiceStack not only is this possible - it comes out-of-the-box, config-pain-free :) 343 |

344 |

Config-free, convention-based, pure C# model-driven, web services

345 |

346 | No other config, code-gen are required and you do not need to learn any other artificial constructs and concepts to get started. 347 | The logic of your services simply live in a pure C#, dependency-free and testable class. 348 |

349 |

Get Started by un-learning WCF RPC

350 |

351 | The initial difficulty to new developers coming to ServiceStack is having to un-learn WCFs RPC approach to web services. 352 | In our opinion the problem with WCF is not that it's an abstract walled-interface forcing you to develop all your Network services in. 353 |

354 |

355 | The main problem is it forcing all network requests to marshal onto a C# method, we believe is an un-natural fit, leading to the creation of slow, chatty APIs. 356 | ServiceStack believes this is an anti-pattern which produces more friction then its preferred strong-typed DTO approach. 357 |

358 | 359 |
360 | 361 | 365 | 366 | 367 | 368 | --------------------------------------------------------------------------------