protected internal NetHttpChannelDispatcher(NetHttpChannelManager instance, WADLMethod method, NetHttpUriTemplate template) { Method = method; Instance = instance; Template = template; MatchType = MatchType.None; }
protected internal NetHttpChannelDispatcher(NetHttpChannelManager instance, WADLMethod method, NetHttpUriTemplate template) { Method = method; Instance = instance; Template = template; MatchType = MatchType.None; }
//TODO: Method needs to be evaluated //deserialize parameters public void Invoke(NetHttpContext context) { List <object> parameters = new List <object>(); ParameterInfo[] @params = Method.MethodInfo.GetParameters(); Array.ForEach(@params, delegate(ParameterInfo param) { WADLParam[] attributes = WADLParam.GetWADLParams(param); if (param.ParameterType.IsArray) { Type type = Type.GetType(param.ParameterType.AssemblyQualifiedName.Replace("[]", "")); Array array = Array.CreateInstance(type, attributes.Length); IList list = Activator.CreateInstance(typeof(List <>).MakeGenericType(type)) as IList; Resolve(context, list, attributes); list.CopyTo(array, 0); parameters.Add(array); } else { if (attributes.Length == 0) { WADLParam wadlParam = WADLParam.CreateWADLParam(param); parameters.Add(Resolve(context, wadlParam)); } else { parameters.Add(Resolve(context, attributes.Single())); } } }); NetHttpChannelManager instanceToInvoke = Instance; if (Instance.GetInstancingModeAttribute() == InstancingMode.PerCall) { instanceToInvoke = Activator.CreateInstance(Instance.GetType()) as NetHttpChannelManager; } var result = Method.MethodInfo.Invoke(instanceToInvoke, parameters.ToArray()); if (result == null) { WebOperationContext.Current.OutgoingResponse.SetStatusAsNotFound(); WebOperationContext.Current.OutgoingResponse.SuppressEntityBody = true; } else { var outputs = (from representation in Method.Representations select representation).Where <WADLRepresentation>(delegate(WADLRepresentation rep) { return(rep.Status == System.Net.HttpStatusCode.OK); }); WADLRepresentation output; if (outputs.Count() == 1) { output = outputs.Single(); context.Response.ContentType = output.ContentType; } else { output = outputs.DefaultIfEmpty(null).SingleOrDefault(o => o.ContentType == context.Response.ContentType); if (output == null) { output = new WADLRepresentation(ContentTypes.unknown); context.Response.ContentType = output.ContentType; } } Encode(context.Response.Buffer, output, result); } }