Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save stefan2410/cfdbae090f61ac81b257 to your computer and use it in GitHub Desktop.
Save stefan2410/cfdbae090f61ac81b257 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using Funq;
using ServiceStack;
using ServiceStack.Host;
using ServiceStack.Host.Handlers;
using ServiceStack.Web;
using ServiceStack.Text;
using ServiceStack.Api.Swagger;
namespace testService
{
using test.service.model;
class Program
{
static void Main(string[] args)
{
new AppHost().Init().Start("http://*:20801/");
"Test API listening at http://localhost:20801 ".Print();
Process.Start("http://localhost:20801/");
Console.ReadLine();
}
}
public class AppHost : AppSelfHostBase
{
/// <summary>
/// Default constructor.
/// Base constructor requires a name and assembly to locate web service classes.
/// </summary>
public AppHost()
: base("eps", typeof(AppHost).Assembly)
{ }
static AppHost()
{ /* ServiceStack.Licensing.RegisterLicense(@"");
*/
}
public override void Configure(Container container)
{
base.SetConfig(new HostConfig
{
DefaultContentType = MimeTypes.Json,
ReturnsInnerException = true,
EnableFeatures = Feature.All.Remove(Feature.Metadata)
});
JsConfig.EmitCamelCaseNames = true;
JsConfig.ExcludeTypeInfo = true;
JsConfig.EscapeUnicode = true;
Plugins.Add(new SwaggerFeature() { UseBootstrapTheme = true, UseCamelCaseModelPropertyNames = false });
Plugins.Add(new CorsFeature(allowedHeaders: "Content-Type, Authorization"));
}
}
[Route("/metadata/{cmds*}", "GET")]
public class RedirectToSwaggerRequest : IReturnVoid
{
public string cmds { get; set; }
}
[Restrict(VisibleLocalhostOnly = true)]
public class MetadataService : Service
{
public void Get(RedirectToSwaggerRequest request)
{
base.Response.Redirect("/swagger-ui");
}
}
}
namespace test.service.model
{
public class Customer
{
[ApiMember(Name = "displayName", Description = "The display name for the entity", ParameterType = "body", DataType = "string", IsRequired = true)]
public string displayName { get; set; }
[ApiMember(Name = "description", Description = "The description of the entity", ParameterType = "body", DataType = "string", IsRequired = false)]
public string description { get; set; }
[ApiMember(Name = "customerCode", Description = "Unique Code of the customer", ParameterType = "body", DataType = "string", IsRequired = true)]
public string customerCode { get; set; }
[ApiMember(Name = "reasonForCancel", Description = "The reason given for canceling service", ParameterType = "body", DataType = "string", IsRequired = false)]
public string reasonForCancel { get; set; }
[ApiMember(Name = "contactEmail", Description = "The email address of the main contact for the company", ParameterType = "body", DataType = "string", IsRequired = false)]
public string contactEmail { get; set; }
[ApiMember(Name = "contactPhone", Description = "The phone number of the main contact for the company", ParameterType = "body", DataType = "string", IsRequired = false)]
public string contactPhone { get; set; }
[ApiMember(Name = "contactName", Description = "The CN name of the main contact for the company", ParameterType = "body", DataType = "string", IsRequired = false)]
public string contactName { get; set; }
[ApiMember(Name = "signupDomain", Description = "The domain the customer entered into the system through (the resellers domain)", ParameterType = "body", DataType = "string", IsRequired = true)]
public string signupDomain { get; set; }
}
public class BaseResponse
{
public bool success { get; set; }
public string message { get; set; }
}
[Route("/Test/CustomersResponse", "POST")]
public class TestCustomersRequest : IReturn<TestCustomersResponse>
{
public string nameStartsWith { get; set; }
}
public class TestCustomersResponse : BaseResponse
{
public List<Customer> Customers { get; set; }
}
[Route("/Test/ListOfCustomers", "POST")]
public class TestCustomersWithListRequest : IReturn<List<Customer>>
{
public string nameStartsWith { get; set; }
}
public class TestService : Service
{
public TestCustomersResponse Post(TestCustomersRequest request)
{
return new TestCustomersResponse();
}
public List<Customer> Post(TestCustomersWithListRequest request)
{
return new List<Customer>();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment