public static object CreateRequest(HttpListenerHost host, IRequest httpReq, RestPath restPath, Dictionary <string, string> requestParams) { var requestDto = CreateContentTypeRequest(host, httpReq, restPath.RequestType, httpReq.ContentType); return(CreateRequest(httpReq, restPath, requestParams, requestDto)); }
public override void Dispose() { _host.Close(); _host = null; }
public override void Initialize() { _host = new HttpListenerHostWithConfiguration(new Configurator()); _host.Initialize(new[] { "http://+:" + Port + "/" }, "/", null); _host.StartListening(); }
private static void ListenerCallback(IAsyncResult result) { HttpListener listener = (HttpListener)result.AsyncState; //process another request listener.BeginGetContext(new AsyncCallback(ListenerCallback), listener); try { HttpListenerContext context = listener.EndGetContext(result); HttpListenerHost host = new HttpListenerHost(context, uriBaseAddress); object hostWrapper; if (useV2Host) hostWrapper = new IDSH2Wrapper(host); else hostWrapper = new IDSHWrapper(host); object service = Activator.CreateInstance(serviceType); MethodInfo attachMethod = serviceType.GetMethod("AttachHost", new Type[] { typeof(IDataServiceHost) }); attachMethod.Invoke(service, new object[] { hostWrapper }); MethodInfo processRequestMethod = serviceType.GetMethod("ProcessRequest", BindingFlags.Public | BindingFlags.Instance); try { processRequestMethod.Invoke(service, new object[0]); } catch (Exception e) { if (!host.processExceptionCalled) throw e; } if (host.processExceptionCalled) { if (context.Request.HasEntityBody) { context.Request.InputStream.Close(); context.Request.InputStream.Dispose(); } } context.Response.Close(); } catch (Exception e) { Console.WriteLine("An exception occurred:"); Console.WriteLine(e.ToString()); listener.Abort(); Console.ReadLine(); } }