Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Updated to shorten namespaces

  • Loading branch information...
commit c9138c9d78df9c40a0d5275764d737b880c9af9a 1 parent 5c2dc43
@mythz mythz authored
Showing with 358 additions and 355 deletions.
  1. +4 −3 src/ServiceStack.Northwind/ServiceStack.Northwind.ServiceInterface/CachedServices.cs
  2. +5 −4 src/ServiceStack.Northwind/ServiceStack.Northwind.ServiceInterface/CustomerDetailsService.cs
  3. +3 −3 src/ServiceStack.Northwind/ServiceStack.Northwind.ServiceInterface/CustomersService.cs
  4. +5 −4 src/ServiceStack.Northwind/ServiceStack.Northwind.ServiceInterface/OrdersService.cs
  5. +2 −2 src/ServiceStack.Northwind/ServiceStack.Northwind.ServiceInterface/Properties/AssemblyInfo.cs
  6. +3 −3 src/ServiceStack.Northwind/ServiceStack.Northwind.ServiceInterface/VCardFormat.cs
  7. +1 −1  src/ServiceStack.Northwind/ServiceStack.Northwind.ServiceModel/Operations/CachedOperations.cs
  8. +2 −2 src/ServiceStack.Northwind/ServiceStack.Northwind.ServiceModel/Operations/CustomerDetails.cs
  9. +2 −2 src/ServiceStack.Northwind/ServiceStack.Northwind.ServiceModel/Operations/Customers.cs
  10. +2 −2 src/ServiceStack.Northwind/ServiceStack.Northwind.ServiceModel/Operations/Orders.cs
  11. +4 −4 src/ServiceStack.Northwind/ServiceStack.Northwind.ServiceModel/Properties/AssemblyInfo.cs
  12. +1 −1  src/ServiceStack.Northwind/ServiceStack.Northwind.ServiceModel/Types/Category.cs
  13. +1 −1  src/ServiceStack.Northwind/ServiceStack.Northwind.ServiceModel/Types/Customer.cs
  14. +1 −1  src/ServiceStack.Northwind/ServiceStack.Northwind.ServiceModel/Types/CustomerCustomerDemo.cs
  15. +1 −1  src/ServiceStack.Northwind/ServiceStack.Northwind.ServiceModel/Types/CustomerDemographic.cs
  16. +1 −1  src/ServiceStack.Northwind/ServiceStack.Northwind.ServiceModel/Types/CustomerOrders.cs
  17. +1 −1  src/ServiceStack.Northwind/ServiceStack.Northwind.ServiceModel/Types/Employee.cs
  18. +1 −1  src/ServiceStack.Northwind/ServiceStack.Northwind.ServiceModel/Types/EmployeeTerritory.cs
  19. +1 −1  src/ServiceStack.Northwind/ServiceStack.Northwind.ServiceModel/Types/Order.cs
  20. +1 −1  src/ServiceStack.Northwind/ServiceStack.Northwind.ServiceModel/Types/OrderDetail.cs
  21. +1 −1  src/ServiceStack.Northwind/ServiceStack.Northwind.ServiceModel/Types/Product.cs
  22. +1 −1  src/ServiceStack.Northwind/ServiceStack.Northwind.ServiceModel/Types/Region.cs
  23. +1 −1  src/ServiceStack.Northwind/ServiceStack.Northwind.ServiceModel/Types/Shipper.cs
  24. +1 −1  src/ServiceStack.Northwind/ServiceStack.Northwind.ServiceModel/Types/Supplier.cs
  25. +1 −1  src/ServiceStack.Northwind/ServiceStack.Northwind.ServiceModel/Types/Territory.cs
  26. +1 −1  src/ServiceStack.Northwind/ServiceStack.Northwind/Global.asax
  27. +2 −2 src/ServiceStack.Northwind/ServiceStack.Northwind/Global.asax.cs
  28. +2 −2 src/ServiceStack.Northwind/ServiceStack.Northwind/Properties/AssemblyInfo.cs
  29. +159 −159 src/ServiceStack.Northwind/ServiceStack.Northwind/default.htm
  30. +147 −147 src/ServiceStack.Northwind/ServiceStack.Northwind/vcard-format.htm
View
7 src/ServiceStack.Northwind/ServiceStack.Northwind.ServiceInterface/CachedServices.cs
@@ -1,13 +1,14 @@
using ServiceStack.Common;
-using ServiceStack.Northwind.ServiceModel.Operations;
+using Northwind.ServiceModel.Operations;
using ServiceStack.ServiceHost;
+using ServiceStack.ServiceInterface;
-namespace ServiceStack.Northwind.ServiceInterface
+namespace Northwind.ServiceInterface
{
/// <summary>
/// Create your ServiceStack RESTful web service implementation.
/// </summary>
- public class CachedCustomersService : ServiceStack.ServiceInterface.Service
+ public class CachedCustomersService : Service
{
public object Get(CachedCustomers request)
{
View
9 src/ServiceStack.Northwind/ServiceStack.Northwind.ServiceInterface/CustomerDetailsService.cs
@@ -1,16 +1,17 @@
using System;
using System.Net;
using ServiceStack.Common.Web;
-using ServiceStack.Northwind.ServiceModel.Operations;
-using ServiceStack.Northwind.ServiceModel.Types;
+using Northwind.ServiceModel.Operations;
+using Northwind.ServiceModel.Types;
using ServiceStack.OrmLite;
+using ServiceStack.ServiceInterface;
-namespace ServiceStack.Northwind.ServiceInterface
+namespace Northwind.ServiceInterface
{
/// <summary>
/// Create your ServiceStack RESTful web service implementation.
/// </summary>
- public class CustomerDetailsService : ServiceStack.ServiceInterface.Service
+ public class CustomerDetailsService : Service
{
public CustomerDetailsResponse Get(CustomerDetails request)
{
View
6 src/ServiceStack.Northwind/ServiceStack.Northwind.ServiceInterface/CustomersService.cs
@@ -1,8 +1,8 @@
-using ServiceStack.Northwind.ServiceModel.Operations;
-using ServiceStack.Northwind.ServiceModel.Types;
+using Northwind.ServiceModel.Operations;
+using Northwind.ServiceModel.Types;
using ServiceStack.OrmLite;
-namespace ServiceStack.Northwind.ServiceInterface
+namespace Northwind.ServiceInterface
{
/// <summary>
/// Create your ServiceStack RESTful web service implementation.
View
9 src/ServiceStack.Northwind/ServiceStack.Northwind.ServiceInterface/OrdersService.cs
@@ -1,15 +1,16 @@
using System.Linq;
using ServiceStack.Common.Extensions;
-using ServiceStack.Northwind.ServiceModel.Operations;
-using ServiceStack.Northwind.ServiceModel.Types;
+using Northwind.ServiceModel.Operations;
+using Northwind.ServiceModel.Types;
using ServiceStack.OrmLite;
+using ServiceStack.ServiceInterface;
-namespace ServiceStack.Northwind.ServiceInterface
+namespace Northwind.ServiceInterface
{
/// <summary>
/// Create your ServiceStack RESTful web service implementation.
/// </summary>
- public class OrdersService : ServiceStack.ServiceInterface.Service
+ public class OrdersService : Service
{
private const int PageCount = 20;
View
4 src/ServiceStack.Northwind/ServiceStack.Northwind.ServiceInterface/Properties/AssemblyInfo.cs
@@ -5,11 +5,11 @@
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
-[assembly: AssemblyTitle("ServiceStack.Northwind.ServiceInterface")]
+[assembly: AssemblyTitle("Northwind.ServiceInterface")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
-[assembly: AssemblyProduct("ServiceStack.Northwind.ServiceInterface")]
+[assembly: AssemblyProduct("Northwind.ServiceInterface")]
[assembly: AssemblyCopyright("Copyright © 2011")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
View
6 src/ServiceStack.Northwind/ServiceStack.Northwind.ServiceInterface/VCardFormat.cs
@@ -1,13 +1,13 @@
using System;
using System.IO;
using ServiceStack.Common.Web;
-using ServiceStack.Northwind.ServiceModel.Operations;
-using ServiceStack.Northwind.ServiceModel.Types;
+using Northwind.ServiceModel.Operations;
+using Northwind.ServiceModel.Types;
using ServiceStack.ServiceHost;
using ServiceStack.Text;
using ServiceStack.WebHost.Endpoints;
-namespace ServiceStack.Northwind.ServiceInterface
+namespace Northwind.ServiceInterface
{
public class VCardFormat
{
View
2  src/ServiceStack.Northwind/ServiceStack.Northwind.ServiceModel/Operations/CachedOperations.cs
@@ -1,6 +1,6 @@
using ServiceStack.ServiceHost;
-namespace ServiceStack.Northwind.ServiceModel.Operations
+namespace Northwind.ServiceModel.Operations
{
[Route("/cached/customers")]
public class CachedCustomers {}
View
4 src/ServiceStack.Northwind/ServiceStack.Northwind.ServiceModel/Operations/CustomerDetails.cs
@@ -1,9 +1,9 @@
using System.Collections.Generic;
-using ServiceStack.Northwind.ServiceModel.Types;
+using Northwind.ServiceModel.Types;
using ServiceStack.ServiceHost;
using ServiceStack.ServiceInterface.ServiceModel;
-namespace ServiceStack.Northwind.ServiceModel.Operations
+namespace Northwind.ServiceModel.Operations
{
[Route("/customers/{Id}")]
public class CustomerDetails
View
4 src/ServiceStack.Northwind/ServiceStack.Northwind.ServiceModel/Operations/Customers.cs
@@ -1,9 +1,9 @@
using System.Collections.Generic;
-using ServiceStack.Northwind.ServiceModel.Types;
+using Northwind.ServiceModel.Types;
using ServiceStack.ServiceHost;
using ServiceStack.ServiceInterface.ServiceModel;
-namespace ServiceStack.Northwind.ServiceModel.Operations
+namespace Northwind.ServiceModel.Operations
{
[Route("/customers")]
public class Customers { }
View
4 src/ServiceStack.Northwind/ServiceStack.Northwind.ServiceModel/Operations/Orders.cs
@@ -1,9 +1,9 @@
using System.Collections.Generic;
-using ServiceStack.Northwind.ServiceModel.Types;
+using Northwind.ServiceModel.Types;
using ServiceStack.ServiceHost;
using ServiceStack.ServiceInterface.ServiceModel;
-namespace ServiceStack.Northwind.ServiceModel.Operations
+namespace Northwind.ServiceModel.Operations
{
[Route("/orders")]
[Route("/orders/page/{Page}")]
View
8 src/ServiceStack.Northwind/ServiceStack.Northwind.ServiceModel/Properties/AssemblyInfo.cs
@@ -6,11 +6,11 @@
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
-[assembly: AssemblyTitle("ServiceStack.Northwind.ServiceModel")]
+[assembly: AssemblyTitle("Northwind.ServiceModel")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
-[assembly: AssemblyProduct("ServiceStack.Northwind.ServiceModel")]
+[assembly: AssemblyProduct("Northwind.ServiceModel")]
[assembly: AssemblyCopyright("Copyright © 2011")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
@@ -36,6 +36,6 @@
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
-[assembly: ContractNamespace("http://schemas.servicestack.net/types", ClrNamespace = "ServiceStack.Northwind.ServiceModel")]
-[assembly: ContractNamespace("http://schemas.servicestack.net/types", ClrNamespace = "ServiceStack.Northwind.ServiceModel.Operations")]
+[assembly: ContractNamespace("http://schemas.servicestack.net/types", ClrNamespace = "Northwind.ServiceModel")]
+[assembly: ContractNamespace("http://schemas.servicestack.net/types", ClrNamespace = "Northwind.ServiceModel.Operations")]
View
2  src/ServiceStack.Northwind/ServiceStack.Northwind.ServiceModel/Types/Category.cs
@@ -1,6 +1,6 @@
using System.Runtime.Serialization;
-namespace ServiceStack.Northwind.ServiceModel.Types
+namespace Northwind.ServiceModel.Types
{
public class Category
{
View
2  src/ServiceStack.Northwind/ServiceStack.Northwind.ServiceModel/Types/Customer.cs
@@ -1,6 +1,6 @@
using System.Runtime.Serialization;
-namespace ServiceStack.Northwind.ServiceModel.Types
+namespace Northwind.ServiceModel.Types
{
public class Customer
{
View
2  src/ServiceStack.Northwind/ServiceStack.Northwind.ServiceModel/Types/CustomerCustomerDemo.cs
@@ -1,6 +1,6 @@
using System.Runtime.Serialization;
-namespace ServiceStack.Northwind.ServiceModel.Types
+namespace Northwind.ServiceModel.Types
{
public class CustomerCustomerDemo
{
View
2  src/ServiceStack.Northwind/ServiceStack.Northwind.ServiceModel/Types/CustomerDemographic.cs
@@ -1,6 +1,6 @@
using System.Runtime.Serialization;
-namespace ServiceStack.Northwind.ServiceModel.Types
+namespace Northwind.ServiceModel.Types
{
public class CustomerDemographic
{
View
2  src/ServiceStack.Northwind/ServiceStack.Northwind.ServiceModel/Types/CustomerOrders.cs
@@ -1,7 +1,7 @@
using System.Collections.Generic;
using System.Runtime.Serialization;
-namespace ServiceStack.Northwind.ServiceModel.Types
+namespace Northwind.ServiceModel.Types
{
public class CustomerOrder
{
View
2  src/ServiceStack.Northwind/ServiceStack.Northwind.ServiceModel/Types/Employee.cs
@@ -1,7 +1,7 @@
using System;
using System.Runtime.Serialization;
-namespace ServiceStack.Northwind.ServiceModel.Types
+namespace Northwind.ServiceModel.Types
{
public class Employee
{
View
2  src/ServiceStack.Northwind/ServiceStack.Northwind.ServiceModel/Types/EmployeeTerritory.cs
@@ -1,6 +1,6 @@
using System.Runtime.Serialization;
-namespace ServiceStack.Northwind.ServiceModel.Types
+namespace Northwind.ServiceModel.Types
{
public class EmployeeTerritory
{
View
2  src/ServiceStack.Northwind/ServiceStack.Northwind.ServiceModel/Types/Order.cs
@@ -1,7 +1,7 @@
using System;
using System.Runtime.Serialization;
-namespace ServiceStack.Northwind.ServiceModel.Types
+namespace Northwind.ServiceModel.Types
{
public class Order
{
View
2  src/ServiceStack.Northwind/ServiceStack.Northwind.ServiceModel/Types/OrderDetail.cs
@@ -1,6 +1,6 @@
using System.Runtime.Serialization;
-namespace ServiceStack.Northwind.ServiceModel.Types
+namespace Northwind.ServiceModel.Types
{
public class OrderDetail
{
View
2  src/ServiceStack.Northwind/ServiceStack.Northwind.ServiceModel/Types/Product.cs
@@ -1,6 +1,6 @@
using System.Runtime.Serialization;
-namespace ServiceStack.Northwind.ServiceModel.Types
+namespace Northwind.ServiceModel.Types
{
public class Product
{
View
2  src/ServiceStack.Northwind/ServiceStack.Northwind.ServiceModel/Types/Region.cs
@@ -1,6 +1,6 @@
using System.Runtime.Serialization;
-namespace ServiceStack.Northwind.ServiceModel.Types
+namespace Northwind.ServiceModel.Types
{
public class Region
{
View
2  src/ServiceStack.Northwind/ServiceStack.Northwind.ServiceModel/Types/Shipper.cs
@@ -1,6 +1,6 @@
using System.Runtime.Serialization;
-namespace ServiceStack.Northwind.ServiceModel.Types
+namespace Northwind.ServiceModel.Types
{
public class Shipper
{
View
2  src/ServiceStack.Northwind/ServiceStack.Northwind.ServiceModel/Types/Supplier.cs
@@ -1,6 +1,6 @@
using System.Runtime.Serialization;
-namespace ServiceStack.Northwind.ServiceModel.Types
+namespace Northwind.ServiceModel.Types
{
public class Supplier
{
View
2  src/ServiceStack.Northwind/ServiceStack.Northwind.ServiceModel/Types/Territory.cs
@@ -1,6 +1,6 @@
using System.Runtime.Serialization;
-namespace ServiceStack.Northwind.ServiceModel.Types
+namespace Northwind.ServiceModel.Types
{
public class Territory
{
View
2  src/ServiceStack.Northwind/ServiceStack.Northwind/Global.asax
@@ -1 +1 @@
-<%@ Application Codebehind="Global.asax.cs" Inherits="ServiceStack.Northwind.Global" Language="C#" %>
+<%@ Application Codebehind="Global.asax.cs" Inherits="Northwind.Global" Language="C#" %>
View
4 src/ServiceStack.Northwind/ServiceStack.Northwind/Global.asax.cs
@@ -3,11 +3,11 @@
using ServiceStack.CacheAccess;
using ServiceStack.CacheAccess.Providers;
using ServiceStack.Common.Utils;
-using ServiceStack.Northwind.ServiceInterface;
+using Northwind.ServiceInterface;
using ServiceStack.OrmLite;
using ServiceStack.WebHost.Endpoints;
-namespace ServiceStack.Northwind
+namespace Northwind
{
/// <summary>
/// Create your ServiceStack web service application with a singleton AppHost.
View
4 src/ServiceStack.Northwind/ServiceStack.Northwind/Properties/AssemblyInfo.cs
@@ -5,11 +5,11 @@
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
-[assembly: AssemblyTitle("ServiceStack.Northwind")]
+[assembly: AssemblyTitle("Northwind")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
-[assembly: AssemblyProduct("ServiceStack.Northwind")]
+[assembly: AssemblyProduct("Northwind")]
[assembly: AssemblyCopyright("Copyright © 2011")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
View
318 src/ServiceStack.Northwind/ServiceStack.Northwind/default.htm
@@ -1,159 +1,159 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml">
-<head>
- <title>Northwind Web Services</title>
- <link rel="stylesheet" type="text/css" href="Content/Css/default.css" />
-</head>
-<body>
- <a href="http://www.servicestack.net" style="display: block; position: absolute; top: 5px; left: 10px;">
- <img src="http://servicestack.net/icon-home.jpg" alt="ServiceStack Home" /></a>
- <div id="header-links">
- <a href="../ServiceStack.Hello/">Hello World</a> <a href="../Backbone.Todos/">Todos</a> <a href="../RedisStackOverflow/">Redis StackOverflow</a> <a href="../RestFiles/">REST Files</a> <a href="../ServiceStack.MovieRest/">REST Movies</a> <a href="../ServiceStack.Northwind/">Northwind Database</a> <a href="../ServiceStack.Examples.Clients/">Ajax Client</a> <a href="../ServiceStack.Examples.Clients/Soap12.aspx">Soap 1.2</a>
- </div>
- <a id="github" href="https://github.com/ServiceStack/ServiceStack.Examples">
- <img src="Content/Images/btn-github.png" alt="ServiceStack.Examples project" /></a>
- <div id="body">
- <h1>Northwind Web Services</h1>
- <p>
- The Northwind Web Services Example project explores different features of ServiceStack using data from Northwind SQlite Database.
- </p>
- <h3>Rest Services</h3>
- <p>
- ServiceStack's REST Services, are just normal Web Services with the addition of a [RestService] attribute that allows you to provide the canonical / permanent location for your web service.
- </p>
- <table id="rest">
- <thead>
- <tr>
- <th></th>
- <th>Path </th>
- <th>Formats </th>
- <th>Code </th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <th>All Customers </th>
- <td><a href="customers">customers</a> </td>
- <td class="c3"><a href="customers?format=json">json</a><a href="customers?format=xml">xml</a><a href="customers?format=html">html</a><a href="customers?format=csv">csv</a><a href="customers?format=jsv">jsv</a><a href="customers?format=x-vcard">x-vcard</a> </td>
- <td class="c4"><a href="https://github.com/ServiceStack/ServiceStack.Examples/blob/master/src/ServiceStack.Northwind/ServiceStack.Northwind.ServiceInterface/CustomersService.cs"><b>CustomersService.cs</b></a> </td>
- </tr>
- <tr>
- <th>Customer Maria Anders </th>
- <td><a href="customers/ALFKI">customers/ALFKI</a> </td>
- <td class="c3"><a href="customers/ALFKI?format=json">json</a><a href="customers/ALFKI?format=xml">xml</a><a href="customers/ALFKI?format=html">html</a><a href="customers/ALFKI?format=csv">csv</a><a href="customers/ALFKI?format=jsv">jsv</a><a href="customers/ALFKI?format=x-vcard">x-vcard</a> </td>
- <td class="c4"><a href="https://github.com/ServiceStack/ServiceStack.Examples/blob/master/src/ServiceStack.Northwind/ServiceStack.Northwind.ServiceInterface/CustomerDetailsService.cs"><b>CustomerDetailsService.cs</b></a> </td>
- </tr>
- <tr>
- <th>Customer Maria Anders Orders </th>
- <td><a href="customers/ALFKI/orders">customers/ALFKI/orders</a> </td>
- <td class="c3"><a href="customers/ALFKI/orders?format=json">json</a><a href="customers/ALFKI/orders?format=xml">xml</a><a href="customers/ALFKI/orders?format=html">html</a><a href="customers/ALFKI/orders?format=csv">csv</a><a href="customers/ALFKI/orders?format=jsv">jsv</a> </td>
- <td class="c4"><a href="https://github.com/ServiceStack/ServiceStack.Examples/blob/master/src/ServiceStack.Northwind/ServiceStack.Northwind.ServiceInterface/OrdersService.cs"><b>OrdersService.cs</b></a> </td>
- </tr>
- <tr>
- <th>Latest Orders </th>
- <td><a href="orders">orders</a> </td>
- <td class="c3"><a href="orders?format=json">json</a><a href="orders?format=xml">xml</a><a href="orders?format=html">html</a><a href="orders?format=csv">csv</a><a href="orders?format=jsv">jsv</a> </td>
- <td class="c4">OrdersService.cs </td>
- </tr>
- <tr>
- <th>Latest Orders - page 2 </th>
- <td><a href="orders/page/2">orders/page/2</a> </td>
- <td class="c3"><a href="orders/page/2?format=json">json</a><a href="orders/page/2?format=xml">xml</a><a href="orders/page/2?format=html">html</a><a href="orders/page/2?format=csv">csv</a><a href="orders/page/2?format=jsv">jsv</a> </td>
- <td class="c4">OrdersService.cs </td>
- </tr>
- </tbody>
- </table>
- <p>
- The entire data source for the Northwind project is contained in this <a href="Northwind.sqlite">
- <img src="Content/Images/database-18x18.jpg" align="absmiddle" hspace="3" />Northwind.sqlite</a> database created by this <a href="https://github.com/ServiceStack/ServiceStack.Benchmarks/blob/master/tests/ServiceStack.Northwind.Tests/PopulateDataTests.cs">unit test</a>.
- </p>
- <a href="vcard-format.htm">
- <img src="Content/Images/vcard-ALFKI-200.png" alt="VCard Custom MediaType" style="float: right; margin: 0 100px 10px 10px;" /></a>
- <h3>Adding Custom Media Types - The VCard format</h3>
- <p>
- The Northwind database also includes the addition of the VCard custom media format.<br />
- Checkout the walk thru to see how to create your own Custom Media Types with ServiceStack:
- <br />
- <h4><a href="vcard-format.htm">vcard-format.htm</a></h4>
- </p>
- <h3>Cached Rest Services</h3>
- <p>
- As it's important for high-performance web services, ServiceStack includes a rich caching provider framework with <a href="https://github.com/ServiceStack/ServiceStack/wiki/Caching">Redis, Memcached, Memory and FileSystem-based cache providers</a> available.
- </p>
- <p>
- To compare the difference with caching enabled, below are the 'cached versions' of the REST services above.
- </p>
- <table id="caching">
- <thead>
- <tr>
- <th></th>
- <th>Path </th>
- <th>Formats </th>
- <th>Code </th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <th>All Customers </th>
- <td><a href="cached/customers">cached/customers</a> </td>
- <td class="c3"><a href="cached/customers?format=json">json</a><a href="cached/customers?format=xml">xml</a><a href="cached/customers?format=html">html</a><a href="cached/customers?format=csv">csv</a><a href="cached/customers?format=jsv">jsv</a> </td>
- <td class="c4"><a href="https://github.com/ServiceStack/ServiceStack.Examples/blob/master/src/ServiceStack.Northwind/ServiceStack.Northwind.ServiceInterface/CachedServices.cs"><strong>CachedServices.cs</strong></a> </td>
- </tr>
- <tr>
- <th>Customer Maria Anders </th>
- <td><a href="cached/customers/ALFKI">cached/customers/ALFKI</a> </td>
- <td class="c3"><a href="cached/customers/ALFKI?format=json">json</a><a href="cached/customers/ALFKI?format=xml">xml</a><a href="cached/customers/ALFKI?format=html">html</a><a href="cached/customers/ALFKI?format=csv">csv</a><a href="cached/customers/ALFKI?format=jsv">jsv</a> </td>
- <td class="c4">CachedServices.cs </td>
- </tr>
- <tr>
- <th>Customer Maria Anders Orders </th>
- <td><a href="cached/customers/ALFKI/orders">cached/customers/ALFKI/orders</a> </td>
- <td class="c3"><a href="cached/customers/ALFKI/orders?format=json">json</a><a href="cached/customers/ALFKI/orders?format=xml">xml</a><a href="cached/customers/ALFKI/orders?format=html">html</a><a href="cached/customers/ALFKI/orders?format=csv">csv</a><a href="cached/customers/ALFKI/orders?format=jsv">jsv</a> </td>
- <td class="c4">CachedServices.cs </td>
- </tr>
- <tr>
- <th>Latest Orders </th>
- <td><a href="cached/orders">cached/orders</a> </td>
- <td class="c3"><a href="cached/orders?format=json">json</a><a href="cached/orders?format=xml">xml</a><a href="cached/orders?format=html">html</a><a href="cached/orders?format=csv">csv</a><a href="cached/orders?format=jsv">jsv</a> </td>
- <td class="c4">CachedServices.cs </td>
- </tr>
- <tr>
- <th>Latest Orders - page 2 </th>
- <td><a href="cached/orders/page/2">cached/orders/page/2</a> </td>
- <td class="c3"><a href="cached/orders/page/2?format=json">json</a><a href="cached/orders/page/2?format=xml">xml</a><a href="cached/orders/page/2?format=html">html</a><a href="cached/orders/page/2?format=csv">csv</a><a href="cached/orders/page/2?format=jsv">jsv</a> </td>
- <td class="c4">CachedServices.cs </td>
- </tr>
- </tbody>
- </table>
- <p>
- Note: The most optimal result is cached, i.e. if your browser supports gzip/deflate it will cache the compressed output. Caching also supports all user-defined formats.
- </p>
- <h2>Advantages of a convention-based Web Services framework</h2>
- <h4>Nothing but C#</h4>
- <p>
- The Northwind project is also an example of how much can be achieved with a minimal amount of effort and code. This entire website literally just consists of <strong><a href="https://github.com/ServiceStack/ServiceStack.Examples/blob/master/src/ServiceStack.Northwind/ServiceStack.Northwind.ServiceInterface/CustomersService.cs">these</a> <a href="https://github.com/ServiceStack/ServiceStack.Examples/blob/master/src/ServiceStack.Northwind/ServiceStack.Northwind.ServiceInterface/CustomerDetailsService.cs">three</a> <a href="https://github.com/ServiceStack/ServiceStack.Examples/blob/master/src/ServiceStack.Northwind/ServiceStack.Northwind.ServiceInterface/OrdersService.cs">classes</a> </strong>. Everything else seen here is automatically provided by <a href="http://www.servicestack.net">ServiceStack</a> using a code-first, convention-based approach. ServiceStack can infer a richer intelligence about your services to better able to provide more generic and re-usable functionality for free!
- </p>
- <p>
- You're unlikely to ever see the same WCF SOAP service, generating a visually informative <a href="https://github.com/ServiceStack/ServiceStack/wiki/HTML5ReportFormat">HTML view</a> of your data, allow it to be exposed over <a href="metadata">RESTful interfaces</a> or be able to export it to a <a href="https://github.com/ServiceStack/ServiceStack/wiki/ServiceStack-CSV-Format">CSV</a> data file. With ServiceStack not only is this possible - it comes out-of-the-box, config-pain-free :)
- </p>
- <h4>Config-free, convention-based, pure C# model-driven, web services</h4>
- <p>
- No other config, code-gen are required and you do not need to learn any other artificial constructs and concepts to get started. The logic of your services simply live in a pure C#, dependency-free and testable class.
- </p>
- <h4>Get Started by un-learning WCF RPC</h4>
- <p>
- The initial difficulty to new developers coming to ServiceStack is having to <b>un-learn WCFs RPC</b> approach to web services. 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.
- </p>
- <p>
- The main problem is it forcing all network requests to <b>marshal onto a C# method</b>, we believe is an un-natural fit, leading to the creation of slow, chatty APIs. ServiceStack believes this is an <a href="http://martinfowler.com/eaaCatalog/dataTransferObject.html">anti-pattern</a> which produces more friction then its preferred strong-typed DTO approach.
- </p>
- </div>
- <div id="footer">
- <a id="logo" href="http://www.servicestack.net">
- <img src="Content/Images/logo-txt-small.png" alt="ServiceStack" /></a> <a id="mono" href="http://www.mono-project.com">
- <img src="Content/Images/Mono-powered-big.png" /></a>
- <div id="demo">
- Live demo hosted on Linux (Cent OS) / <a href="http://wiki.nginx.org">Nginx</a> using <a href="http://www.mono-project.com">Mono</a></div>
- </div>
-</body>
-</html>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+ <title>Northwind Web Services</title>
+ <link rel="stylesheet" type="text/css" href="Content/Css/default.css" />
+</head>
+<body>
+ <a href="http://www.servicestack.net" style="display: block; position: absolute; top: 5px; left: 10px;">
+ <img src="http://servicestack.net/icon-home.jpg" alt="ServiceStack Home" /></a>
+ <div id="header-links">
+ <a href="../ServiceStack.Hello/">Hello World</a> <a href="../Backbone.Todos/">Todos</a> <a href="../RedisStackOverflow/">Redis StackOverflow</a> <a href="../RestFiles/">REST Files</a> <a href="../ServiceStack.MovieRest/">REST Movies</a> <a href="../Northwind/">Northwind Database</a> <a href="../ServiceStack.Examples.Clients/">Ajax Client</a> <a href="../ServiceStack.Examples.Clients/Soap12.aspx">Soap 1.2</a>
+ </div>
+ <a id="github" href="https://github.com/ServiceStack/ServiceStack.Examples">
+ <img src="Content/Images/btn-github.png" alt="ServiceStack.Examples project" /></a>
+ <div id="body">
+ <h1>Northwind Web Services</h1>
+ <p>
+ The Northwind Web Services Example project explores different features of ServiceStack using data from Northwind SQlite Database.
+ </p>
+ <h3>Rest Services</h3>
+ <p>
+ ServiceStack's REST Services, are just normal Web Services with the addition of a [RestService] attribute that allows you to provide the canonical / permanent location for your web service.
+ </p>
+ <table id="rest">
+ <thead>
+ <tr>
+ <th></th>
+ <th>Path </th>
+ <th>Formats </th>
+ <th>Code </th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <th>All Customers </th>
+ <td><a href="customers">customers</a> </td>
+ <td class="c3"><a href="customers?format=json">json</a><a href="customers?format=xml">xml</a><a href="customers?format=html">html</a><a href="customers?format=csv">csv</a><a href="customers?format=jsv">jsv</a><a href="customers?format=x-vcard">x-vcard</a> </td>
+ <td class="c4"><a href="https://github.com/ServiceStack/ServiceStack.Examples/blob/master/src/Northwind/Northwind.ServiceInterface/CustomersService.cs"><b>CustomersService.cs</b></a> </td>
+ </tr>
+ <tr>
+ <th>Customer Maria Anders </th>
+ <td><a href="customers/ALFKI">customers/ALFKI</a> </td>
+ <td class="c3"><a href="customers/ALFKI?format=json">json</a><a href="customers/ALFKI?format=xml">xml</a><a href="customers/ALFKI?format=html">html</a><a href="customers/ALFKI?format=csv">csv</a><a href="customers/ALFKI?format=jsv">jsv</a><a href="customers/ALFKI?format=x-vcard">x-vcard</a> </td>
+ <td class="c4"><a href="https://github.com/ServiceStack/ServiceStack.Examples/blob/master/src/Northwind/Northwind.ServiceInterface/CustomerDetailsService.cs"><b>CustomerDetailsService.cs</b></a> </td>
+ </tr>
+ <tr>
+ <th>Customer Maria Anders Orders </th>
+ <td><a href="customers/ALFKI/orders">customers/ALFKI/orders</a> </td>
+ <td class="c3"><a href="customers/ALFKI/orders?format=json">json</a><a href="customers/ALFKI/orders?format=xml">xml</a><a href="customers/ALFKI/orders?format=html">html</a><a href="customers/ALFKI/orders?format=csv">csv</a><a href="customers/ALFKI/orders?format=jsv">jsv</a> </td>
+ <td class="c4"><a href="https://github.com/ServiceStack/ServiceStack.Examples/blob/master/src/Northwind/Northwind.ServiceInterface/OrdersService.cs"><b>OrdersService.cs</b></a> </td>
+ </tr>
+ <tr>
+ <th>Latest Orders </th>
+ <td><a href="orders">orders</a> </td>
+ <td class="c3"><a href="orders?format=json">json</a><a href="orders?format=xml">xml</a><a href="orders?format=html">html</a><a href="orders?format=csv">csv</a><a href="orders?format=jsv">jsv</a> </td>
+ <td class="c4">OrdersService.cs </td>
+ </tr>
+ <tr>
+ <th>Latest Orders - page 2 </th>
+ <td><a href="orders/page/2">orders/page/2</a> </td>
+ <td class="c3"><a href="orders/page/2?format=json">json</a><a href="orders/page/2?format=xml">xml</a><a href="orders/page/2?format=html">html</a><a href="orders/page/2?format=csv">csv</a><a href="orders/page/2?format=jsv">jsv</a> </td>
+ <td class="c4">OrdersService.cs </td>
+ </tr>
+ </tbody>
+ </table>
+ <p>
+ The entire data source for the Northwind project is contained in this <a href="Northwind.sqlite">
+ <img src="Content/Images/database-18x18.jpg" align="absmiddle" hspace="3" />Northwind.sqlite</a> database created by this <a href="https://github.com/ServiceStack/ServiceStack.Benchmarks/blob/master/tests/Northwind.Tests/PopulateDataTests.cs">unit test</a>.
+ </p>
+ <a href="vcard-format.htm">
+ <img src="Content/Images/vcard-ALFKI-200.png" alt="VCard Custom MediaType" style="float: right; margin: 0 100px 10px 10px;" /></a>
+ <h3>Adding Custom Media Types - The VCard format</h3>
+ <p>
+ The Northwind database also includes the addition of the VCard custom media format.<br />
+ Checkout the walk thru to see how to create your own Custom Media Types with ServiceStack:
+ <br />
+ <h4><a href="vcard-format.htm">vcard-format.htm</a></h4>
+ </p>
+ <h3>Cached Rest Services</h3>
+ <p>
+ As it's important for high-performance web services, ServiceStack includes a rich caching provider framework with <a href="https://github.com/ServiceStack/ServiceStack/wiki/Caching">Redis, Memcached, Memory and FileSystem-based cache providers</a> available.
+ </p>
+ <p>
+ To compare the difference with caching enabled, below are the 'cached versions' of the REST services above.
+ </p>
+ <table id="caching">
+ <thead>
+ <tr>
+ <th></th>
+ <th>Path </th>
+ <th>Formats </th>
+ <th>Code </th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <th>All Customers </th>
+ <td><a href="cached/customers">cached/customers</a> </td>
+ <td class="c3"><a href="cached/customers?format=json">json</a><a href="cached/customers?format=xml">xml</a><a href="cached/customers?format=html">html</a><a href="cached/customers?format=csv">csv</a><a href="cached/customers?format=jsv">jsv</a> </td>
+ <td class="c4"><a href="https://github.com/ServiceStack/ServiceStack.Examples/blob/master/src/Northwind/Northwind.ServiceInterface/CachedServices.cs"><strong>CachedServices.cs</strong></a> </td>
+ </tr>
+ <tr>
+ <th>Customer Maria Anders </th>
+ <td><a href="cached/customers/ALFKI">cached/customers/ALFKI</a> </td>
+ <td class="c3"><a href="cached/customers/ALFKI?format=json">json</a><a href="cached/customers/ALFKI?format=xml">xml</a><a href="cached/customers/ALFKI?format=html">html</a><a href="cached/customers/ALFKI?format=csv">csv</a><a href="cached/customers/ALFKI?format=jsv">jsv</a> </td>
+ <td class="c4">CachedServices.cs </td>
+ </tr>
+ <tr>
+ <th>Customer Maria Anders Orders </th>
+ <td><a href="cached/customers/ALFKI/orders">cached/customers/ALFKI/orders</a> </td>
+ <td class="c3"><a href="cached/customers/ALFKI/orders?format=json">json</a><a href="cached/customers/ALFKI/orders?format=xml">xml</a><a href="cached/customers/ALFKI/orders?format=html">html</a><a href="cached/customers/ALFKI/orders?format=csv">csv</a><a href="cached/customers/ALFKI/orders?format=jsv">jsv</a> </td>
+ <td class="c4">CachedServices.cs </td>
+ </tr>
+ <tr>
+ <th>Latest Orders </th>
+ <td><a href="cached/orders">cached/orders</a> </td>
+ <td class="c3"><a href="cached/orders?format=json">json</a><a href="cached/orders?format=xml">xml</a><a href="cached/orders?format=html">html</a><a href="cached/orders?format=csv">csv</a><a href="cached/orders?format=jsv">jsv</a> </td>
+ <td class="c4">CachedServices.cs </td>
+ </tr>
+ <tr>
+ <th>Latest Orders - page 2 </th>
+ <td><a href="cached/orders/page/2">cached/orders/page/2</a> </td>
+ <td class="c3"><a href="cached/orders/page/2?format=json">json</a><a href="cached/orders/page/2?format=xml">xml</a><a href="cached/orders/page/2?format=html">html</a><a href="cached/orders/page/2?format=csv">csv</a><a href="cached/orders/page/2?format=jsv">jsv</a> </td>
+ <td class="c4">CachedServices.cs </td>
+ </tr>
+ </tbody>
+ </table>
+ <p>
+ Note: The most optimal result is cached, i.e. if your browser supports gzip/deflate it will cache the compressed output. Caching also supports all user-defined formats.
+ </p>
+ <h2>Advantages of a convention-based Web Services framework</h2>
+ <h4>Nothing but C#</h4>
+ <p>
+ The Northwind project is also an example of how much can be achieved with a minimal amount of effort and code. This entire website literally just consists of <strong><a href="https://github.com/ServiceStack/ServiceStack.Examples/blob/master/src/Northwind/Northwind.ServiceInterface/CustomersService.cs">these</a> <a href="https://github.com/ServiceStack/ServiceStack.Examples/blob/master/src/Northwind/Northwind.ServiceInterface/CustomerDetailsService.cs">three</a> <a href="https://github.com/ServiceStack/ServiceStack.Examples/blob/master/src/Northwind/Northwind.ServiceInterface/OrdersService.cs">classes</a> </strong>. Everything else seen here is automatically provided by <a href="http://www.servicestack.net">ServiceStack</a> using a code-first, convention-based approach. ServiceStack can infer a richer intelligence about your services to better able to provide more generic and re-usable functionality for free!
+ </p>
+ <p>
+ You're unlikely to ever see the same WCF SOAP service, generating a visually informative <a href="https://github.com/ServiceStack/ServiceStack/wiki/HTML5ReportFormat">HTML view</a> of your data, allow it to be exposed over <a href="metadata">RESTful interfaces</a> or be able to export it to a <a href="https://github.com/ServiceStack/ServiceStack/wiki/ServiceStack-CSV-Format">CSV</a> data file. With ServiceStack not only is this possible - it comes out-of-the-box, config-pain-free :)
+ </p>
+ <h4>Config-free, convention-based, pure C# model-driven, web services</h4>
+ <p>
+ No other config, code-gen are required and you do not need to learn any other artificial constructs and concepts to get started. The logic of your services simply live in a pure C#, dependency-free and testable class.
+ </p>
+ <h4>Get Started by un-learning WCF RPC</h4>
+ <p>
+ The initial difficulty to new developers coming to ServiceStack is having to <b>un-learn WCFs RPC</b> approach to web services. 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.
+ </p>
+ <p>
+ The main problem is it forcing all network requests to <b>marshal onto a C# method</b>, we believe is an un-natural fit, leading to the creation of slow, chatty APIs. ServiceStack believes this is an <a href="http://martinfowler.com/eaaCatalog/dataTransferObject.html">anti-pattern</a> which produces more friction then its preferred strong-typed DTO approach.
+ </p>
+ </div>
+ <div id="footer">
+ <a id="logo" href="http://www.servicestack.net">
+ <img src="Content/Images/logo-txt-small.png" alt="ServiceStack" /></a> <a id="mono" href="http://www.mono-project.com">
+ <img src="Content/Images/Mono-powered-big.png" /></a>
+ <div id="demo">
+ Live demo hosted on Linux (Cent OS) / <a href="http://wiki.nginx.org">Nginx</a> using <a href="http://www.mono-project.com">Mono</a></div>
+ </div>
+</body>
+</html>
View
294 src/ServiceStack.Northwind/ServiceStack.Northwind/vcard-format.htm
@@ -1,147 +1,147 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml">
-<head>
- <title>Custom media types vs. data formats</title>
- <link rel="stylesheet" type="text/css" href="Content/Css/vcard-format.css" />
-</head>
-<body>
- <a href="http://www.servicestack.net" style="display: block; position: absolute;
- top: 5px; left: 10px;">
- <img src="http://servicestack.net/icon-home.jpg" alt="ServiceStack Home" /></a>
- <div id="header-links">
- <a href="../ServiceStack.Hello/">Hello World</a> <a href="../Backbone.Todos/">Todos</a>
- <a href="../RedisStackOverflow/">Redis StackOverflow</a> <a href="../RestFiles/">REST
- Files</a> <a href="../ServiceStack.MovieRest/">REST Movies</a> <a href="../ServiceStack.Northwind/">
- Northwind Database</a> <a href="../ServiceStack.Examples.Clients/">Ajax Client</a>
- <a href="../ServiceStack.Examples.Clients/Soap12.aspx">Soap 1.2</a>
- </div>
- <a id="github" href="https://github.com/ServiceStack/ServiceStack.Examples">
- <img src="Content/Images/btn-github.png" alt="ServiceStack.Examples project" /></a>
- <div id="body">
- <h1>
- Custom media types - Adding the VCard Format</h1>
- <p>
- An often overlooked feature in ServiceStack is its ability to easily support custom
- media types and formats.
- </p>
- <h3>
- Specific Media Types vs. Data Formats</h3>
- <p>
- It's not given as much prominence as ServiceStack's other formats simply because
- supporting specific media types require more custom development effort so are unlike
- other built-in ServiceStack generic data formats (JSON, XML, CSV, JSV, HTML, SOAP)
- that are automatically available to all your services <b>without any extra effort</b>.
- </p>
- <h2>
- Creating the VCard Custom Media Type</h2>
- <p>
- At times when your clients have built-in support for a specific media-type it can
- allow richer functionality and a deeper integration into users applications than
- what would otherwise be possible. An example of this is allowing users to import
- contact information directly into Outlook by providing contact information in the
- <a href="http://en.wikipedia.org/wiki/VCard">VCard Format</a>, which you can make
- available for instance on the results page on an online contact directory search.
- </p>
- <p>
- So when it's beneficial to, adding Custom Media Types in Service Stack is easy where
- in just <b>1 Line of Code</b> you can register your format and have it immediately
- available in ServiceStack's REST pipeline and auto-generated <a href="metadata">/metadata</a>
- pages.
- </p>
- <p>
- Below is a live example of what is possible when we add the VCard format to the
- Northwind <b>Customer</b> web services. It allows us to provide the unusual relationship
- giving our MONO web server deep access into your Windows Outlook client :)
- </p>
- <a href="customers/ALFKI?format=x-vcard">
- <img src="Content/Images/vcard-ALFKI.png" alt="Maria Anders VCard" style="margin: 10px;" /></a>
- <h3>
- Supporting the VCard Format in ServiceStack</h3>
- <p>
- Like the <a href="https://github.com/ServiceStack/ServiceStack/wiki/HTML5ReportFormat">
- HTML</a> and <a href="https://github.com/ServiceStack/ServiceStack/wiki/ServiceStack-CSV-Format">
- CSV</a> formats before it, the best way to add an additional Media Type
- in ServiceStack is to encapsulate it in a single class keeping it loosely-coupled
- from the rest of your system thus making it an easy drop-in or removal whenever
- you need it. The entire support for the format is contained in <b><a href="https://github.com/ServiceStack/ServiceStack.Examples/blob/master/src/ServiceStack.Northwind/ServiceStack.Northwind.ServiceInterface/VCardFormat.cs">
- VCardFormat.cs</a></b> and is explained below:
- </p>
- <h4>
- Registering a custom format in ServiceStack</h4>
- <p>
- In the <b>Register()</b> method we simply tell ServiceStack that we have a new <b>ContentType</b>
- available and supply the Stream serializers that it should use whenever processing
- that ContentType.
- </p>
- <p>
- With just this 1 line of config: <b><code>appHost.ContentTypeFilters.Register(VCardContentType, SerializeToStream, DeserializeFromStream);</code></b><br />
- We now have your custom format registered into ServiceStack who will now use the
- supplied Content serializers whenever this Content-Type is requested by the client
- in any of the following ways:
- </p>
- <ul>
- <li>REST URL overriding response format using the QueryString: <a href="customers/ALFKI?format=x-vcard">
- /customers/ALFKI?format=x-vcard</a></li>
- <li>Auto generated format url: <a href="x-vcard/syncreply/customers/ALFKI">/x-vcard/syncreply/customers/ALFKI</a></li>
- <li>Using the <b>Accept: text/x-vcard</b> HTTP header at the REST URL: <a href="customers/ALFKI">
- /customers/ALFKI</a></li>
- </ul>
- <p>
- Another benefit ServiceStack gives you is that this format is automatically provided
- on the auto-generated <a href="metadata">/metadata</a> page.<br />
- This is what the Customers X-VCARD metadata page looks like: <a href="x-vcard/metadata?op=Customers">
- /x-vcard/metadata?op=Customers</a>
- </p>
- <p>
- The ResponseFilter is added to intercept the response and a Content-Disposition
- HTTP header added to signal to the browser that this resource is to be treated as
- an attachment using the prescribed filename.
- </p>
- <code>private const string VCardContentType = "text/x-vcard";
-public static void Register(IAppHost appHost) {
- appHost.ContentTypeFilters.Register(VCardContentType, SerializeToStream, DeserializeFromStream);
- appHost.ResponseFilters.Add((req, res, dto) =&gt; {
- if (req.ResponseContentType == VCardContentType) {
- res.AddHeader(HttpHeaders.ContentDisposition, string.Format("attachment;filename={0}.vcf", req.OperationName));
- }
- });
-}</code>
- <p>
- With the x-vcard format now registered in ServiceStack, the only thing left to to
- is implement the Content-Type SerializeToStream routine. Unlike the data formats
- it is not as simple as just serializing the Response DTO. In this case we need to
- detect if the response DTO contains a customer and if it does return its data in
- the <a href="http://en.wikipedia.org/wiki/VCard">VCard format</a>.
- </p>
- <code>public static void SerializeToStream(IRequestContext requestContext, object response, Stream stream) {
- var customerDetailsResponse = response as CustomerDetailsResponse;
- using (var sw = new StreamWriter(stream)) {
- if (customerDetailsResponse != null)
- {
- WriteCustomer(sw, customerDetailsResponse.Customer);
- }
- var customers = response as CustomersResponse;
- if (customers != null) {
- customers.Customers.ForEach(x => WriteCustomer(sw, x));
- }
- }
-}
-public static void WriteCustomer(StreamWriter sw, Customer customer) {
- sw.WriteLine("BEGIN:VCARD"); sw.WriteLine("VERSION:2.1");
- sw.WriteLine("FN:" + customer.ContactName); sw.WriteLine("ORG:" + customer.CompanyName);
- sw.WriteLine("TITLE:" + customer.ContactTitle); sw.WriteLine("EMAIL;TYPE=PREF,INTERNET:" + customer.Email);
- sw.WriteLine("TEL;HOME;VOICE:" + customer.Phone); sw.WriteLine("TEL;WORK;FAX:" + customer.Fax);
- sw.WriteLine("ADR;TYPE=HOME;" + new[] { customer.Address, customer.City, customer.PostalCode }.Join(";"));
- sw.WriteLine("END:VCARD");
-}</code>
- <p>
- And that's the entire VCard format in a single loosely-coupled class. No other concepts
- / artifacts are required to make this work, you can just simply plug it into ServiceStack
- the the following 1 Line of Code:
- </p>
- <code>public override void Configure(Container container) {
- VCardFormat.Register(this);
-}</code>
- </div>
-</body>
-</html>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+ <title>Custom media types vs. data formats</title>
+ <link rel="stylesheet" type="text/css" href="Content/Css/vcard-format.css" />
+</head>
+<body>
+ <a href="http://www.servicestack.net" style="display: block; position: absolute;
+ top: 5px; left: 10px;">
+ <img src="http://servicestack.net/icon-home.jpg" alt="ServiceStack Home" /></a>
+ <div id="header-links">
+ <a href="../ServiceStack.Hello/">Hello World</a> <a href="../Backbone.Todos/">Todos</a>
+ <a href="../RedisStackOverflow/">Redis StackOverflow</a> <a href="../RestFiles/">REST
+ Files</a> <a href="../ServiceStack.MovieRest/">REST Movies</a> <a href="../Northwind/">
+ Northwind Database</a> <a href="../ServiceStack.Examples.Clients/">Ajax Client</a>
+ <a href="../ServiceStack.Examples.Clients/Soap12.aspx">Soap 1.2</a>
+ </div>
+ <a id="github" href="https://github.com/ServiceStack/ServiceStack.Examples">
+ <img src="Content/Images/btn-github.png" alt="ServiceStack.Examples project" /></a>
+ <div id="body">
+ <h1>
+ Custom media types - Adding the VCard Format</h1>
+ <p>
+ An often overlooked feature in ServiceStack is its ability to easily support custom
+ media types and formats.
+ </p>
+ <h3>
+ Specific Media Types vs. Data Formats</h3>
+ <p>
+ It's not given as much prominence as ServiceStack's other formats simply because
+ supporting specific media types require more custom development effort so are unlike
+ other built-in ServiceStack generic data formats (JSON, XML, CSV, JSV, HTML, SOAP)
+ that are automatically available to all your services <b>without any extra effort</b>.
+ </p>
+ <h2>
+ Creating the VCard Custom Media Type</h2>
+ <p>
+ At times when your clients have built-in support for a specific media-type it can
+ allow richer functionality and a deeper integration into users applications than
+ what would otherwise be possible. An example of this is allowing users to import
+ contact information directly into Outlook by providing contact information in the
+ <a href="http://en.wikipedia.org/wiki/VCard">VCard Format</a>, which you can make
+ available for instance on the results page on an online contact directory search.
+ </p>
+ <p>
+ So when it's beneficial to, adding Custom Media Types in Service Stack is easy where
+ in just <b>1 Line of Code</b> you can register your format and have it immediately
+ available in ServiceStack's REST pipeline and auto-generated <a href="metadata">/metadata</a>
+ pages.
+ </p>
+ <p>
+ Below is a live example of what is possible when we add the VCard format to the
+ Northwind <b>Customer</b> web services. It allows us to provide the unusual relationship
+ giving our MONO web server deep access into your Windows Outlook client :)
+ </p>
+ <a href="customers/ALFKI?format=x-vcard">
+ <img src="Content/Images/vcard-ALFKI.png" alt="Maria Anders VCard" style="margin: 10px;" /></a>
+ <h3>
+ Supporting the VCard Format in ServiceStack</h3>
+ <p>
+ Like the <a href="https://github.com/ServiceStack/ServiceStack/wiki/HTML5ReportFormat">
+ HTML</a> and <a href="https://github.com/ServiceStack/ServiceStack/wiki/ServiceStack-CSV-Format">
+ CSV</a> formats before it, the best way to add an additional Media Type
+ in ServiceStack is to encapsulate it in a single class keeping it loosely-coupled
+ from the rest of your system thus making it an easy drop-in or removal whenever
+ you need it. The entire support for the format is contained in <b><a href="https://github.com/ServiceStack/ServiceStack.Examples/blob/master/src/Northwind/Northwind.ServiceInterface/VCardFormat.cs">
+ VCardFormat.cs</a></b> and is explained below:
+ </p>
+ <h4>
+ Registering a custom format in ServiceStack</h4>
+ <p>
+ In the <b>Register()</b> method we simply tell ServiceStack that we have a new <b>ContentType</b>
+ available and supply the Stream serializers that it should use whenever processing
+ that ContentType.
+ </p>
+ <p>
+ With just this 1 line of config: <b><code>appHost.ContentTypeFilters.Register(VCardContentType, SerializeToStream, DeserializeFromStream);</code></b><br />
+ We now have your custom format registered into ServiceStack who will now use the
+ supplied Content serializers whenever this Content-Type is requested by the client
+ in any of the following ways:
+ </p>
+ <ul>
+ <li>REST URL overriding response format using the QueryString: <a href="customers/ALFKI?format=x-vcard">
+ /customers/ALFKI?format=x-vcard</a></li>
+ <li>Auto generated format url: <a href="x-vcard/syncreply/customers/ALFKI">/x-vcard/syncreply/customers/ALFKI</a></li>
+ <li>Using the <b>Accept: text/x-vcard</b> HTTP header at the REST URL: <a href="customers/ALFKI">
+ /customers/ALFKI</a></li>
+ </ul>
+ <p>
+ Another benefit ServiceStack gives you is that this format is automatically provided
+ on the auto-generated <a href="metadata">/metadata</a> page.<br />
+ This is what the Customers X-VCARD metadata page looks like: <a href="x-vcard/metadata?op=Customers">
+ /x-vcard/metadata?op=Customers</a>
+ </p>
+ <p>
+ The ResponseFilter is added to intercept the response and a Content-Disposition
+ HTTP header added to signal to the browser that this resource is to be treated as
+ an attachment using the prescribed filename.
+ </p>
+ <code>private const string VCardContentType = "text/x-vcard";
+public static void Register(IAppHost appHost) {
+ appHost.ContentTypeFilters.Register(VCardContentType, SerializeToStream, DeserializeFromStream);
+ appHost.ResponseFilters.Add((req, res, dto) =&gt; {
+ if (req.ResponseContentType == VCardContentType) {
+ res.AddHeader(HttpHeaders.ContentDisposition, string.Format("attachment;filename={0}.vcf", req.OperationName));
+ }
+ });
+}</code>
+ <p>
+ With the x-vcard format now registered in ServiceStack, the only thing left to to
+ is implement the Content-Type SerializeToStream routine. Unlike the data formats
+ it is not as simple as just serializing the Response DTO. In this case we need to
+ detect if the response DTO contains a customer and if it does return its data in
+ the <a href="http://en.wikipedia.org/wiki/VCard">VCard format</a>.
+ </p>
+ <code>public static void SerializeToStream(IRequestContext requestContext, object response, Stream stream) {
+ var customerDetailsResponse = response as CustomerDetailsResponse;
+ using (var sw = new StreamWriter(stream)) {
+ if (customerDetailsResponse != null)
+ {
+ WriteCustomer(sw, customerDetailsResponse.Customer);
+ }
+ var customers = response as CustomersResponse;
+ if (customers != null) {
+ customers.Customers.ForEach(x => WriteCustomer(sw, x));
+ }
+ }
+}
+public static void WriteCustomer(StreamWriter sw, Customer customer) {
+ sw.WriteLine("BEGIN:VCARD"); sw.WriteLine("VERSION:2.1");
+ sw.WriteLine("FN:" + customer.ContactName); sw.WriteLine("ORG:" + customer.CompanyName);
+ sw.WriteLine("TITLE:" + customer.ContactTitle); sw.WriteLine("EMAIL;TYPE=PREF,INTERNET:" + customer.Email);
+ sw.WriteLine("TEL;HOME;VOICE:" + customer.Phone); sw.WriteLine("TEL;WORK;FAX:" + customer.Fax);
+ sw.WriteLine("ADR;TYPE=HOME;" + new[] { customer.Address, customer.City, customer.PostalCode }.Join(";"));
+ sw.WriteLine("END:VCARD");
+}</code>
+ <p>
+ And that's the entire VCard format in a single loosely-coupled class. No other concepts
+ / artifacts are required to make this work, you can just simply plug it into ServiceStack
+ the the following 1 Line of Code:
+ </p>
+ <code>public override void Configure(Container container) {
+ VCardFormat.Register(this);
+}</code>
+ </div>
+</body>
+</html>
Please sign in to comment.
Something went wrong with that request. Please try again.