public bool CanAccess(EndpointAttributes reqAttrs, Format format, string operationName) { if (EndpointHost.Config != null && !EndpointHost.Config.EnableAccessRestrictions) { return(true); } Operation operation; OperationNameMap.TryGetValue(operationName.ToLower(), out operation); if (operation == null) { return(false); } if (operation.RestrictTo == null) { return(true); } var allow = operation.RestrictTo.HasAccessTo(reqAttrs); if (!allow) { return(false); } var allowsFormat = operation.RestrictTo.HasAccessTo((EndpointAttributes)(long)format); return(allowsFormat); }
public HttpRequestContext(object dto, EndpointAttributes endpointAttributes, IFactoryProvider factory) { this.Dto = dto; this.EndpointAttributes = endpointAttributes; this.Factory = factory; this.RequestAttributes = new RequestAttributes(HttpContext.Current); }
/// <summary>Print enum result.</summary> /// /// <param name="actual"> The actual.</param> /// <param name="required">The required.</param> public void PrintEnumResult(EndpointAttributes actual, EndpointAttributes required) { Console.WriteLine(string.Format("({0} | {1}): {2}", actual, required, (actual | required))); Console.WriteLine(string.Format("({0} & {1}): {2}", actual, required, (actual & required))); Console.WriteLine(string.Format("({0} ^ {1}): {2}", actual, required, (actual ^ required))); Console.WriteLine(); }
public GenericHandler(string contentType, EndpointAttributes handlerAttributes, Feature format) { this.HandlerContentType = contentType; this.ContentTypeAttribute = ContentType.GetEndpointAttributes(contentType); this.HandlerAttributes = handlerAttributes; this.format = format; }
public static ICacheTextManager Create(EndpointAttributes endpointAttributes, ICacheClient cacheClient) { var isXml = (endpointAttributes & EndpointAttributes.Xml) == EndpointAttributes.Xml; if (isXml) { return(new XmlCacheManager(cacheClient)); } var isJson = (endpointAttributes & EndpointAttributes.Json) == EndpointAttributes.Json; if (isJson) { return(new JsonCacheManager(cacheClient)); } var isJsv = (endpointAttributes & EndpointAttributes.Jsv) == EndpointAttributes.Jsv; if (isJsv) { return(new JsvCacheManager(cacheClient)); } throw new NotSupportedException("Only Xml, Json and Jsv CachTextManagers are supported"); }
public void AssertServiceRestrictions(Type requestType, EndpointAttributes actualAttributes) { ServiceAttribute serviceAttr; var hasNoAccessRestrictions = !requestServiceAttrs.TryGetValue(requestType, out serviceAttr) || serviceAttr.HasNoAccessRestrictions; if (hasNoAccessRestrictions) { return; } var failedScenarios = new StringBuilder(); foreach (var requiredScenario in serviceAttr.RestrictAccessToScenarios) { var allServiceRestrictionsMet = (requiredScenario & actualAttributes) == actualAttributes; if (allServiceRestrictionsMet) { return; } var passed = requiredScenario & actualAttributes; var failed = requiredScenario & ~(passed); failedScenarios.AppendFormat("\n -[{0}]", failed); } var internalDebugMsg = (EndpointAttributes.InternalNetworkAccess & actualAttributes) != 0 ? "\n Unauthorized call was made from: " + actualAttributes : ""; throw new UnauthorizedAccessException( string.Format("Could not execute service '{0}', The following restrictions were not met: '{1}'" + internalDebugMsg, requestType.Name, failedScenarios)); }
public GenericHandler(string contentType, EndpointAttributes handlerAttributes, Feature usesFeature) { this.HandlerContentType = contentType; this.ContentTypeAttribute = ContentType.GetEndpointAttributes(contentType); this.HandlerAttributes = handlerAttributes; this.usesFeature = usesFeature; }
public static MethodInfo GetRunTimeExecMethod(Type serviceType, Type requestType, EndpointAttributes attrs) { if ((attrs & EndpointAttributes.AsyncOneWay) == EndpointAttributes.AsyncOneWay) { var mi = serviceType.GetMethod(ExecuteAsync, new[] { requestType }); if (mi != null) return mi; } else if ((attrs & EndpointAttributes.HttpGet) == EndpointAttributes.HttpGet) { var mi = serviceType.GetMethod(RestGet, new[] { requestType }); if (mi != null) return mi; } else if ((attrs & EndpointAttributes.HttpPost) == EndpointAttributes.HttpPost) { var mi = serviceType.GetMethod(RestPost, new[] { requestType }); if (mi != null) return mi; } else if ((attrs & EndpointAttributes.HttpPut) == EndpointAttributes.HttpPut) { var mi = serviceType.GetMethod(RestPut, new[] { requestType }); if (mi != null) return mi; } else if ((attrs & EndpointAttributes.HttpDelete) == EndpointAttributes.HttpDelete) { var mi = serviceType.GetMethod(RestDelete, new[] { requestType }); if (mi != null) return mi; } else if ((attrs & EndpointAttributes.HttpPatch) == EndpointAttributes.HttpPatch) { var mi = serviceType.GetMethod(RestPatch, new[] { requestType }); if (mi != null) return mi; } return serviceType.GetMethod(Execute, new[] { requestType }); }
public GenericHandler(string contentType, EndpointAttributes handlerAttributes, Feature usesFeature) { this.HandlerContentType = contentType; this.ContentTypeAttribute = ContentType.GetEndpointAttributes(contentType); this.HandlerAttributes = handlerAttributes; this.usesFeature = usesFeature; }
public GenericHandler(string contentType, EndpointAttributes handlerAttributes, Feature format) { this.HandlerContentType = contentType; this.ContentTypeAttribute = ContentFormat.GetEndpointAttributes(contentType); this.HandlerAttributes = handlerAttributes; this.format = format; }
protected Message ExecuteMessage(Message requestMsg, EndpointAttributes endpointAttributes) { string requestXml; using (var reader = requestMsg.GetReaderAtBodyContents()) { requestXml = reader.ReadOuterXml(); } var requestType = GetRequestType(requestMsg, requestXml); try { var request = DataContractDeserializer.Instance.Parse(requestXml, requestType); var response = ExecuteService(request, endpointAttributes, null); return(requestMsg.Headers.Action == null ? Message.CreateMessage(requestMsg.Version, null, response) : Message.CreateMessage(requestMsg.Version, requestType.Name + "Response", response)); } catch (Exception ex) { throw new SerializationException("3) Error trying to deserialize requestType: " + requestType + ", xml body: " + requestXml, ex); } }
public static object Execute(IService <TReq> service, TReq request, EndpointAttributes attrs) { if ((attrs & EndpointAttributes.OneWay) == EndpointAttributes.OneWay) { var asyncService = service as IAsyncService <TReq>; if (asyncService != null) { return(asyncService.ExecuteAsync(request)); } } else if ((attrs & EndpointAttributes.HttpGet) == EndpointAttributes.HttpGet) { var restService = service as IRestGetService <TReq>; if (restService != null) { return(restService.Get(request)); } } else if ((attrs & EndpointAttributes.HttpPost) == EndpointAttributes.HttpPost) { var restService = service as IRestPostService <TReq>; if (restService != null) { return(restService.Post(request)); } } else if ((attrs & EndpointAttributes.HttpPut) == EndpointAttributes.HttpPut) { var restService = service as IRestPutService <TReq>; if (restService != null) { return(restService.Put(request)); } } else if ((attrs & EndpointAttributes.HttpDelete) == EndpointAttributes.HttpDelete) { var restService = service as IRestDeleteService <TReq>; if (restService != null) { return(restService.Delete(request)); } } else if ((attrs & EndpointAttributes.HttpOptions) == EndpointAttributes.HttpOptions) { var restService = service as IRestOptionsService <TReq>; if (restService != null) { return(restService.Options(request)); } } else if ((attrs & EndpointAttributes.HttpPatch) == EndpointAttributes.HttpPatch) { var restService = service as IRestPatchService <TReq>; if (restService != null) { return(restService.Patch(request)); } } return(service.Execute(request)); }
public HttpRequestContext(object dto, EndpointAttributes endpointAttributes) { this.Dto = dto; this.EndpointAttributes = endpointAttributes; this.RequestAttributes = new RequestAttributes(HttpContext.Current); this.Files = new IFile[0]; }
internal static object ExecuteService(object request, EndpointAttributes endpointAttributes, IHttpRequest httpReq, IHttpResponse httpRes) { using (Profiler.Current.Step("Execute Service")) { return(config.ServiceController.Execute(request, new HttpRequestContext(httpReq, httpRes, request, endpointAttributes))); } }
public HttpRequestContext(IHttpRequest httpReq, object dto, EndpointAttributes endpointAttributes) : this(dto, endpointAttributes, null) { this.httpReq = httpReq; if (this.httpReq != null) { this.Files = httpReq.Files; } }
internal static object ExecuteService(object request, EndpointAttributes endpointAttributes, IHttpRequest httpReq, IHttpResponse httpRes) { if (String.IsNullOrEmpty(httpReq.OperationName)) { throw new ArgumentNullException("No operation name was supplied"); } return(Config.ServiceController.Execute(httpReq.OperationName, request, new HttpRequestContext(httpReq, httpRes, request, endpointAttributes))); }
public void GetEndpointAttributes_AcceptsUserHostAddressFormats(string format, EndpointAttributes expected) { var handler = new TestHandler(); var request = new Mock<IHttpRequest>(); request.Expect(req => req.UserHostAddress).Returns(format); request.Expect(req => req.IsSecureConnection).Returns(false); request.Expect(req => req.HttpMethod).Returns("GET"); Assert.AreEqual(expected | EndpointAttributes.HttpGet | EndpointAttributes.InSecure, request.Object.GetAttributes()); }
protected Message ExecuteMessage(Message requestMsg, EndpointAttributes endpointAttributes) { if ((EndpointAttributes.Soap11 & this.HandlerAttributes) == EndpointAttributes.Soap11) { EndpointHost.Config.AssertFeatures(Feature.Soap11); } else if ((EndpointAttributes.Soap12 & this.HandlerAttributes) == EndpointAttributes.Soap12) { EndpointHost.Config.AssertFeatures(Feature.Soap12); } string requestXml; using (var reader = requestMsg.GetReaderAtBodyContents()) { requestXml = reader.ReadOuterXml(); } var requestType = GetRequestType(requestMsg, requestXml); try { var request = DataContractDeserializer.Instance.Parse(requestXml, requestType); IHttpRequest httpReq = null; IHttpResponse httpRes = null; var hasRequestFilters = EndpointHost.RequestFilters.Count > 0; var hasResponseFilters = EndpointHost.ResponseFilters.Count > 0; if (hasRequestFilters || hasResponseFilters) { httpReq = HttpContext.Current != null ? new HttpRequestWrapper(requestType.Name, HttpContext.Current.Request) : null; httpRes = HttpContext.Current != null ? new HttpResponseWrapper(HttpContext.Current.Response) : null; } EndpointHost.ApplyRequestFilters(httpReq, httpRes, request); var response = ExecuteService(request, endpointAttributes, null); EndpointHost.ApplyResponseFilters(httpReq, httpRes, response); return(requestMsg.Headers.Action == null ? Message.CreateMessage(requestMsg.Version, null, response) : Message.CreateMessage(requestMsg.Version, requestType.Name + "Response", response)); } catch (Exception ex) { throw new SerializationException("3) Error trying to deserialize requestType: " + requestType + ", xml body: " + requestXml, ex); } }
public static Feature ToSoapFeature(this EndpointAttributes attributes) { if ((EndpointAttributes.Soap11 & attributes) == EndpointAttributes.Soap11) { return(Feature.Soap11); } if ((EndpointAttributes.Soap12 & attributes) == EndpointAttributes.Soap12) { return(Feature.Soap12); } return(Feature.None); }
public HttpRequestContext(IHttpRequest httpReq, object dto, EndpointAttributes endpointAttributes) : this(dto, endpointAttributes, null) { this.httpReq = httpReq; if (this.httpReq != null) { this.Files = httpReq.Files; } if (HttpContext.Current == null) { this.RequestAttributes = new RequestAttributes(httpReq); } }
private static bool CanShowToNetwork(Operation operation, EndpointAttributes reqAttrs) { if (reqAttrs.IsLocalhost()) { return(operation.RestrictTo.CanShowTo(EndpointAttributes.Localhost) || operation.RestrictTo.CanShowTo(EndpointAttributes.LocalSubnet)); } return(operation.RestrictTo.CanShowTo( reqAttrs.IsLocalSubnet() ? EndpointAttributes.LocalSubnet : EndpointAttributes.External)); }
protected override void ProcessRequest(HttpListenerContext context) { if (string.IsNullOrEmpty(context.Request.RawUrl)) { return; } var operationName = context.Request.GetOperationName(); var request = CreateRequest(context.Request, operationName); const EndpointAttributes endpointAttributes = EndpointAttributes.SyncReply | EndpointAttributes.Xml; var result = ExecuteService(request, endpointAttributes); var response = new HttpListenerResponseWrapper(context.Response); response.WriteToResponse(result, x => DataContractSerializer.Instance.Parse(result), ContentType.Xml); }
public static ICacheTextManager Create(EndpointAttributes endpointAttributes, ICacheClient cacheClient) { var isXml = (endpointAttributes & EndpointAttributes.Xml) == EndpointAttributes.Xml; if (isXml) return new XmlCacheManager(cacheClient); var isJson = (endpointAttributes & EndpointAttributes.Json) == EndpointAttributes.Json; if (isJson) return new JsonCacheManager(cacheClient); var isJsv = (endpointAttributes & EndpointAttributes.Jsv) == EndpointAttributes.Jsv; if (isJsv) return new JsvCacheManager(cacheClient); throw new NotSupportedException("Only Xml, Json and Jsv CachTextManagers are supported"); }
public void AssertServiceRestrictions(string operationName, EndpointAttributes actualAttributes) { if (EndpointHost.Config != null && !EndpointHost.Config.EnableAccessRestrictions) { return; } RestrictAttribute restrictAttr; var hasNoAccessRestrictions = !operationServiceAttrs.TryGetValue(operationName.ToLower(), out restrictAttr) || restrictAttr.HasNoAccessRestrictions; if (hasNoAccessRestrictions) { return; } var failedScenarios = new StringBuilder(); foreach (var requiredScenario in restrictAttr.AccessibleToAny) { var allServiceRestrictionsMet = (requiredScenario & actualAttributes) == actualAttributes; if (allServiceRestrictionsMet) { return; } var passed = requiredScenario & actualAttributes; var failed = requiredScenario & ~(passed); failedScenarios.AppendFormat("\n -[{0}]", failed); } var internalDebugMsg = (EndpointAttributes.InternalNetworkAccess & actualAttributes) != 0 ? "\n Unauthorized call was made from: " + actualAttributes : ""; throw new UnauthorizedAccessException( string.Format("Could not execute service method '{0}', The following restrictions were not met: '{1}'" + internalDebugMsg, operationName, failedScenarios)); }
public static void WriteErrorToResponse(this IHttpResponse response, EndpointAttributes contentType, string operationName, string errorMessage, Exception ex) { switch (contentType) { case EndpointAttributes.Xml: WriteXmlErrorToResponse(response, operationName, errorMessage, ex); break; case EndpointAttributes.Json: WriteJsonErrorToResponse(response, operationName, errorMessage, ex); break; case EndpointAttributes.Jsv: WriteJsvErrorToResponse(response, operationName, errorMessage, ex); break; default: WriteXmlErrorToResponse(response, operationName, errorMessage, ex); break; } }
public static void WriteErrorToResponse(this IHttpResponse response, EndpointAttributes contentType, string operationName, string errorMessage, Exception ex) { switch (contentType) { case EndpointAttributes.Xml: WriteXmlErrorToResponse(response, operationName, errorMessage, ex); break; case EndpointAttributes.Json: WriteJsonErrorToResponse(response, operationName, errorMessage, ex); break; case EndpointAttributes.Jsv: WriteJsvErrorToResponse(response, operationName, errorMessage, ex); break; default: WriteXmlErrorToResponse(response, operationName, errorMessage, ex); break; } }
public bool CanShowTo(EndpointAttributes restrictions) { return this.VisibleToAny.Any(scenario => (restrictions & scenario) == restrictions); }
public Soap12Handler(EndpointAttributes soapType) : base(soapType) { }
internal static object ExecuteService(object request, EndpointAttributes endpointAttributes, IHttpRequest httpReq) { return(config.ServiceController.Execute(request, new HttpRequestContext(httpReq, request, endpointAttributes))); }
public virtual object ExecuteService(object request, EndpointAttributes endpointAttributes) { return EndpointHost.Config.ServiceController.Execute( request, new HttpRequestContext(request, endpointAttributes)); }
public bool HasAccessTo(EndpointAttributes restrictions) { return this.AccessibleToAny.Any(scenario => (restrictions & scenario) == restrictions); }
public static bool IsLocalSubnet(this EndpointAttributes attrs) { return((EndpointAttributes.LocalSubnet & attrs) == EndpointAttributes.LocalSubnet); }
internal static string ExecuteXmlService(string xmlRequest, EndpointAttributes endpointAttributes) { AssertConfig(); return (string)Config.ServiceController.ExecuteText(xmlRequest, new HttpRequestContext(xmlRequest, endpointAttributes)); }
//Execute SOAP requests protected static string ExecuteXmlService(string xmlRequest, EndpointAttributes endpointAttributes) { return EndpointHost.ExecuteXmlService(xmlRequest, endpointAttributes); }
protected GenericHandler(string contentType, EndpointAttributes handlerAttributes) { this.HandlerContentType = contentType; this.ContentTypeAttribute = ContentType.GetEndpointAttributes(contentType); this.HandlerAttributes = handlerAttributes; }
protected Message ExecuteMessage(Message message, EndpointAttributes endpointAttributes, IHttpRequest httpRequest, IHttpResponse httpResponse) { var soapFeature = endpointAttributes.ToSoapFeature(); EndpointHost.Config.AssertFeatures(soapFeature); var httpReq = HttpContext.Current != null && httpRequest == null ? new HttpRequestWrapper(HttpContext.Current.Request) : httpRequest; var httpRes = HttpContext.Current != null && httpResponse == null ? new HttpResponseWrapper(HttpContext.Current.Response) : httpResponse; if (httpReq == null) throw new ArgumentNullException("httpRequest"); if (httpRes == null) throw new ArgumentNullException("httpResponse"); if (EndpointHost.ApplyPreRequestFilters(httpReq, httpRes)) return PrepareEmptyResponse(message, httpReq); var requestMsg = message ?? GetRequestMessageFromStream(httpReq.InputStream); string requestXml = GetRequestXml(requestMsg); var requestType = GetRequestType(requestMsg, requestXml); if (!EndpointHost.Metadata.CanAccess(endpointAttributes, soapFeature.ToFormat(), requestType.Name)) throw EndpointHost.Config.UnauthorizedAccess(endpointAttributes); try { var request = DataContractDeserializer.Instance.Parse(requestXml, requestType); var requiresSoapMessage = request as IRequiresSoapMessage; if (requiresSoapMessage != null) { requiresSoapMessage.Message = requestMsg; } httpReq.OperationName = requestType.Name; httpReq.SetItem("SoapMessage", requestMsg); var hasRequestFilters = EndpointHost.RequestFilters.Count > 0 || FilterAttributeCache.GetRequestFilterAttributes(request.GetType()).Any(); if (hasRequestFilters && EndpointHost.ApplyRequestFilters(httpReq, httpRes, request)) return EmptyResponse(requestMsg, requestType); var response = ExecuteService(request, endpointAttributes, httpReq, httpRes); var hasResponseFilters = EndpointHost.ResponseFilters.Count > 0 || FilterAttributeCache.GetResponseFilterAttributes(response.GetType()).Any(); if (hasResponseFilters && EndpointHost.ApplyResponseFilters(httpReq, httpRes, response)) return EmptyResponse(requestMsg, requestType); var httpResult = response as IHttpResult; if (httpResult != null) response = httpResult.Response; return requestMsg.Headers.Action == null ? Message.CreateMessage(requestMsg.Version, null, response) : Message.CreateMessage(requestMsg.Version, requestType.Name + "Response", response); } catch (Exception ex) { throw new SerializationException("3) Error trying to deserialize requestType: " + requestType + ", xml body: " + requestXml, ex); } }
/// <summary> /// Restrict access and metadata visibility to any of the specified access scenarios /// </summary> /// <value>The restrict access to scenarios.</value> public RestrictAttribute(EndpointAttributes[] allowedAccessScenarios, EndpointAttributes[] visibleToScenarios) : this() { this.AccessibleToAny = ToAllowedFlagsSet(allowedAccessScenarios); this.VisibleToAny = ToAllowedFlagsSet(visibleToScenarios); }
public PortAttribute(Type operationType, EndpointAttributes endpointAttributes) : this(operationType) { this.OperationType = operationType; this.PortRestrictions = endpointAttributes; }
public UnauthorizedAccessException UnauthorizedAccess(EndpointAttributes requestAttrs) { return new UnauthorizedAccessException( String.Format("Request with '{0}' is not allowed", requestAttrs)); }
protected Message ExecuteMessage(Message requestMsg, EndpointAttributes endpointAttributes, IHttpRequest httpRequest, IHttpResponse httpResponse) { if ((EndpointAttributes.Soap11 & this.HandlerAttributes) == EndpointAttributes.Soap11) EndpointHost.Config.AssertFeatures(Feature.Soap11); else if ((EndpointAttributes.Soap12 & this.HandlerAttributes) == EndpointAttributes.Soap12) EndpointHost.Config.AssertFeatures(Feature.Soap12); string requestXml; using (var reader = requestMsg.GetReaderAtBodyContents()) { requestXml = reader.ReadOuterXml(); } var requestType = GetRequestType(requestMsg, requestXml); try { var request = DataContractDeserializer.Instance.Parse(requestXml, requestType); var requiresSoapMessage = request as IRequiresSoapMessage; if (requiresSoapMessage != null) { requiresSoapMessage.Message = requestMsg; } var httpReq = HttpContext.Current != null ? new HttpRequestWrapper(requestType.Name, HttpContext.Current.Request) : httpRequest; var httpRes = HttpContext.Current != null ? new HttpResponseWrapper(HttpContext.Current.Response) : httpResponse; if (EndpointHost.ApplyPreRequestFilters(httpReq, httpRes)) return EmptyResponse(requestMsg, requestType); var hasRequestFilters = EndpointHost.RequestFilters.Count > 0 || FilterAttributeCache.GetRequestFilterAttributes(request.GetType()).Any(); if (hasRequestFilters && EndpointHost.ApplyRequestFilters(httpReq, httpRes, request)) return EmptyResponse(requestMsg, requestType); var response = ExecuteService(request, endpointAttributes, httpReq, httpRes); var hasResponseFilters = EndpointHost.ResponseFilters.Count > 0 || FilterAttributeCache.GetResponseFilterAttributes(response.GetType()).Any(); if (hasResponseFilters && EndpointHost.ApplyResponseFilters(httpReq, httpRes, response)) return EmptyResponse(requestMsg, requestType); var httpResult = response as IHttpResult; if (httpResult != null) response = httpResult.Response; return requestMsg.Headers.Action == null ? Message.CreateMessage(requestMsg.Version, null, response) : Message.CreateMessage(requestMsg.Version, requestType.Name + "Response", response); } catch (Exception ex) { throw new SerializationException("3) Error trying to deserialize requestType: " + requestType + ", xml body: " + requestXml, ex); } }
internal static object ExecuteService(object request, EndpointAttributes endpointAttributes) { AssertConfig(); return Config.ServiceController.Execute(request, new HttpRequestContext(request, endpointAttributes)); }
public SoapHandler(EndpointAttributes soapType) { this.HandlerAttributes = soapType; }
protected static object ExecuteService(object request, EndpointAttributes endpointAttributes, IHttpRequest httpReq, IHttpResponse httpRes) { return(EndpointHost.ExecuteService(request, endpointAttributes, httpReq, httpRes)); }
/// <summary>Gets run time execute method.</summary> /// /// <param name="serviceType">Type of the service.</param> /// <param name="requestType">Type of the request.</param> /// <param name="attrs"> The attributes.</param> /// /// <returns>The run time execute method.</returns> public static MethodInfo GetRunTimeExecMethod(Type serviceType, Type requestType, EndpointAttributes attrs) { if ((attrs & EndpointAttributes.OneWay) == EndpointAttributes.OneWay) { var mi = serviceType.GetMethod(ExecuteAsync, new[] { requestType }); if (mi != null) { return(mi); } } else if ((attrs & EndpointAttributes.HttpGet) == EndpointAttributes.HttpGet) { var mi = serviceType.GetMethod(RestGet, new[] { requestType }); if (mi != null) { return(mi); } } else if ((attrs & EndpointAttributes.HttpPost) == EndpointAttributes.HttpPost) { var mi = serviceType.GetMethod(RestPost, new[] { requestType }); if (mi != null) { return(mi); } } else if ((attrs & EndpointAttributes.HttpPut) == EndpointAttributes.HttpPut) { var mi = serviceType.GetMethod(RestPut, new[] { requestType }); if (mi != null) { return(mi); } } else if ((attrs & EndpointAttributes.HttpDelete) == EndpointAttributes.HttpDelete) { var mi = serviceType.GetMethod(RestDelete, new[] { requestType }); if (mi != null) { return(mi); } } else if ((attrs & EndpointAttributes.HttpPatch) == EndpointAttributes.HttpPatch) { var mi = serviceType.GetMethod(RestPatch, new[] { requestType }); if (mi != null) { return(mi); } } return(serviceType.GetMethod(Execute, new[] { requestType })); }
public static bool IsExternal(this EndpointAttributes attrs) { return((EndpointAttributes.External & attrs) == EndpointAttributes.External); }
protected Message ExecuteMessage(Message message, EndpointAttributes endpointAttributes, IHttpRequest httpRequest, IHttpResponse httpResponse) { var soapFeature = endpointAttributes.ToSoapFeature(); EndpointHost.Config.AssertFeatures(soapFeature); var httpReq = HttpContext.Current != null && httpRequest == null ? new HttpRequestWrapper(HttpContext.Current.Request) : httpRequest; var httpRes = HttpContext.Current != null && httpResponse == null ? new HttpResponseWrapper(HttpContext.Current.Response) : httpResponse; if (httpReq == null) { throw new ArgumentNullException("httpRequest"); } if (httpRes == null) { throw new ArgumentNullException("httpResponse"); } if (EndpointHost.ApplyPreRequestFilters(httpReq, httpRes)) { return(PrepareEmptyResponse(message, httpReq)); } var requestMsg = message ?? GetRequestMessageFromStream(httpReq.InputStream); string requestXml = GetRequestXml(requestMsg); var requestType = GetRequestType(requestMsg, requestXml); if (!EndpointHost.Metadata.CanAccess(endpointAttributes, soapFeature.ToFormat(), requestType.Name)) { throw EndpointHost.Config.UnauthorizedAccess(endpointAttributes); } try { var useXmlSerializerRequest = requestType.HasAttribute <XmlSerializerFormatAttribute>(); var request = useXmlSerializerRequest ? XmlSerializableDeserializer.Instance.Parse(requestXml, requestType) : DataContractDeserializer.Instance.Parse(requestXml, requestType); var requiresSoapMessage = request as IRequiresSoapMessage; if (requiresSoapMessage != null) { requiresSoapMessage.Message = requestMsg; } httpReq.OperationName = requestType.Name; httpReq.SetItem("SoapMessage", requestMsg); var hasRequestFilters = EndpointHost.RequestFilters.Count > 0 || FilterAttributeCache.GetRequestFilterAttributes(request.GetType()).Any(); if (hasRequestFilters && EndpointHost.ApplyRequestFilters(httpReq, httpRes, request)) { return(EmptyResponse(requestMsg, requestType)); } var response = ExecuteService(request, endpointAttributes, httpReq, httpRes); var hasResponseFilters = EndpointHost.ResponseFilters.Count > 0 || FilterAttributeCache.GetResponseFilterAttributes(response.GetType()).Any(); if (hasResponseFilters && EndpointHost.ApplyResponseFilters(httpReq, httpRes, response)) { return(EmptyResponse(requestMsg, requestType)); } var httpResult = response as IHttpResult; if (httpResult != null) { response = httpResult.Response; } var useXmlSerializerResponse = response.GetType().HasAttribute <XmlSerializerFormatAttribute>(); if (useXmlSerializerResponse) { return(requestMsg.Headers.Action == null ? Message.CreateMessage(requestMsg.Version, null, response, new XmlSerializerWrapper(response.GetType())) : Message.CreateMessage(requestMsg.Version, requestType.Name + "Response", response, new XmlSerializerWrapper(response.GetType()))); } return(requestMsg.Headers.Action == null ? Message.CreateMessage(requestMsg.Version, null, response) : Message.CreateMessage(requestMsg.Version, requestType.Name + "Response", response)); } catch (Exception ex) { throw new SerializationException("3) Error trying to deserialize requestType: " + requestType + ", xml body: " + requestXml, ex); } }
internal static object ExecuteService(object request, EndpointAttributes endpointAttributes, IHttpRequest httpReq) { return config.ServiceController.Execute(request, new HttpRequestContext(httpReq, request, endpointAttributes)); }
public static bool HasAnyRestrictionsOf(EndpointAttributes allRestrictions, EndpointAttributes restrictions) { return (allRestrictions & restrictions) != 0; }
public virtual string ExecuteXmlService(string xmlRequest, EndpointAttributes endpointAttributes) { return (string)EndpointHost.Config.ServiceController.ExecuteText( xmlRequest, new HttpRequestContext(xmlRequest, endpointAttributes)); }
private static bool CanShowToNetwork(Operation operation, EndpointAttributes reqAttrs) { if (reqAttrs.IsLocalhost()) return operation.RestrictTo.CanShowTo(EndpointAttributes.Localhost) || operation.RestrictTo.CanShowTo(EndpointAttributes.LocalSubnet); return operation.RestrictTo.CanShowTo( reqAttrs.IsLocalSubnet() ? EndpointAttributes.LocalSubnet : EndpointAttributes.External); }
public static bool HasAnyRestrictionsOf(EndpointAttributes allRestrictions, EndpointAttributes restrictions) { return((allRestrictions & restrictions) != 0); }
public PortAttribute(Type operationType, EndpointAttributes endpointAttributes, int version) : this(operationType, endpointAttributes) { this.Version = version; }
public SoapHandler(EndpointAttributes soapType) { this.HandlerAttributes = soapType; }
internal static object ExecuteService(object request, EndpointAttributes endpointAttributes, IHttpRequest httpReq) { using (Profiler.Current.Step("Execute Service")) { return config.ServiceController.Execute(request, new HttpRequestContext(httpReq, request, endpointAttributes)); } }
protected static object ExecuteService(object request, EndpointAttributes endpointAttributes, IHttpRequest httpReq, IHttpResponse httpRes) { return EndpointHost.ExecuteService(request, endpointAttributes, httpReq, httpRes); }
protected static object ExecuteService(object request, EndpointAttributes endpointAttributes) { return EndpointHost.ExecuteService(request, endpointAttributes); }
public bool CanAccess(EndpointAttributes reqAttrs, Format format, string operationName) { if (EndpointHost.Config != null && !EndpointHost.Config.EnableAccessRestrictions) return true; Operation operation; OperationNamesMap.TryGetValue(operationName.ToLower(), out operation); if (operation == null) return false; var canCall = HasImplementation(operation, format); if (!canCall) return false; if (operation.RestrictTo == null) return true; var allow = operation.RestrictTo.HasAccessTo(reqAttrs); if (!allow) return false; var allowsFormat = operation.RestrictTo.HasAccessTo((EndpointAttributes)(long)format); return allowsFormat; }
public void GetEndpointAttributes_AcceptsUserHostAddressFormats(string format, EndpointAttributes expected) { var handler = new TestHandler(); var request = new Mock <IHttpRequest>(); request.Expect(req => req.UserHostAddress).Returns(format); request.Expect(req => req.IsSecureConnection).Returns(false); request.Expect(req => req.HttpMethod).Returns("GET"); Assert.AreEqual(expected | EndpointAttributes.HttpGet | EndpointAttributes.InSecure, handler.GetEndpointAttributes(request.Object)); }
public object ExecuteService(object requestDto, EndpointAttributes endpointAttributes) { return(EndpointHost.Config.ServiceController.Execute(requestDto, new HttpRequestContext(requestDto, endpointAttributes))); }
/// <summary> /// Returns the allowed set of scenarios based on the user-specified restrictions /// </summary> /// <param name="restrictToAny"></param> /// <returns></returns> private static EndpointAttributes[] ToAllowedFlagsSet(EndpointAttributes[] restrictToAny) { if (restrictToAny.Length == 0) return new[] { EndpointAttributes.Any }; var scenarios = new List<EndpointAttributes>(); foreach (var restrictToScenario in restrictToAny) { var restrictTo = restrictToScenario.ToAllowedFlagsSet(); scenarios.Add(restrictTo); } return scenarios.ToArray(); }