using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http;
using System.Web.Http.SelfHost;
using System.Web.Http.Routing;
using System.Web.Http.Dispatcher;
using System.Net;
using System.Net.Http;
using System.Reflection;
using System.IO;
using System.Configuration;
using System.ServiceModel;
/***********************************************************
** 作者: dl
** 创始时间:2014年4月21日
** 描述:
** windows服务 用于weipAPI 寄宿
************************************************************/
namespace Legal.Api.Service
{
partial class LSHMobileService : ServiceBase
{
private HttpSelfHostServer _server;
private HttpSelfHostConfiguration _config;
public static readonly int port = Convert.ToInt32(ConfigurationManager.AppSettings["ServicePort"]);
private static readonly string logPath = ConfigurationManager.AppSettings["LogPath"];
private static readonly bool hasClientTest = Convert.ToBoolean( ConfigurationManager.AppSettings["hasClientTest"]);
/// <summary>
/// 服务初始化
/// </summary>
public LSHMobileService()
{
InitializeComponent();
Uri urlBase = new UriBuilder("HTTP", Dns.GetHostName(), port).Uri; //获取本地地址绑定端口
_config = new HttpSelfHostConfiguration(urlBase);
_config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}", new { id = RouteParameter.Optional });
_config.TransferMode = TransferMode.Streamed;
_config.Formatters.XmlFormatter.SupportedMediaTypes.Clear(); //清除xml格式数据 返回json格式
_config.Filters.Add(new ModelValidationFilterAttribute());//添加全局模型验证
if (hasClientTest)
{
_config.MessageHandlers.Add(new MessageHandler());
}
}