Ejemplo n.º 1
0
        protected virtual void ProcessOperations(HtmlTextWriter writer, IHttpRequest httpReq)
        {
            EndpointHost.Config.AssertFeatures(Feature.Metadata);

            if (EndpointHost.Config.MetadataVisibility != EndpointAttributes.All)
            {
                var actualAttributes = EndpointHandlerBase.GetEndpointAttributesFromRequest(httpReq);
                if ((actualAttributes & EndpointHost.Config.MetadataVisibility) != EndpointHost.Config.MetadataVisibility)
                {
                    throw new UnauthorizedAccessException("Access to metadata is unauthorized.");
                }
            }

            var operations    = EndpointHost.ServiceOperations;
            var operationName = httpReq.QueryString["op"];

            if (operationName != null)
            {
                var    allTypes        = operations.AllOperations.Types;
                var    operationType   = allTypes.Single(x => x.Name == operationName);
                var    requestMessage  = CreateMessage(operationType);
                var    restPaths       = CreateRestPaths(operationType);
                string responseMessage = null;

                Type operationResponseType = null;
                if (!operations.OperationResponseTypesMap.TryGetValue(operationType, out operationResponseType))
                {
                    if (allTypes.Any(x => x.Name == operationName + ResponseSuffix))
                    {
                        operationResponseType = allTypes.Single(x => x.Name == operationName + ResponseSuffix);
                    }
                }
                if (operationResponseType != null)
                {
                    responseMessage = CreateMessage(operationResponseType);
                }

                var description = GetDescriptionFromOperationType(operationType);
                if (!description.IsNullOrEmpty())
                {
                    description = "<div id='desc'>"
                                  + "<p>" + description
                                  .Replace("<", "&lt;")
                                  .Replace(">", "&gt;")
                                  .Replace("\n", "<br />\n")
                                  + "</p>"
                                  + "</div>";
                }


                RenderOperation(writer, httpReq, operationName, requestMessage, responseMessage, restPaths, description);
                return;
            }

            RenderOperations(writer, httpReq, operations.AllOperations);
        }
Ejemplo n.º 2
0
        public AsyncOperation(AsyncCallback callback, HttpContext context, Object state, EndpointHandlerBase endpointHandler, string servicePath, string operationName)
        {
            _callback        = callback;
            _context         = context;
            _state           = state;
            _completed       = false;
            _endpointHandler = endpointHandler;
            ServicePath      = servicePath;
            OperationName    = operationName.ToLower();
            _operation       = EndpointHost.MetadataMap[ServicePath].OperationNameMap[OperationName];
            _isAsync         = _operation.IsAsync;

            Initialize();
        }
        private static IHttpHandler GetHandlerForPathParts(string servicePath, string[] pathParts)
        {
            var pathController = string.Intern(pathParts[0].ToLower());

            if (pathParts.Length == 1)
            {
                return(null);
            }

            var requestName = string.Intern(pathParts[1]).ToLower(); // aka. operation name

            if (string.IsNullOrWhiteSpace(requestName))
            {
                return(null);
                //throw new ArgumentNullException("No operation name was provided");
            }
            if (requestName == "metadata")
            {
                return(null);                            // leave for metadata handler
            }
            EndpointHandlerBase rpcHandler = null;

            switch (pathController)
            {
            case "json":
                rpcHandler = new JsonSyncReplyHandler(servicePath)
                {
                    RequestName = requestName
                };
                break;

            case "xml":
                rpcHandler = new XmlSyncReplyHandler(servicePath)
                {
                    RequestName = requestName
                };
                break;

            case "jsv":
                rpcHandler = new JsvSyncReplyHandler(servicePath)
                {
                    RequestName = requestName
                };
                break;

            case "soap":
            case "soap11":
                rpcHandler = new Soap11Handler(servicePath)
                {
                    RequestName = requestName
                };
                break;

            default:
                string contentType;
                if (EndpointHost.ContentTypeFilter.ContentTypeFormats.TryGetValue(pathController, out contentType))
                {
                    var feature = Common.Web.ContentType.ToFeature(contentType);
                    if (feature == Feature.None)
                    {
                        feature = Feature.CustomFormat;
                    }

                    rpcHandler = new GenericHandler(servicePath, contentType, EndpointAttributes.Reply, feature)
                    {
                        RequestName = requestName
                    };
                }
                break;
            }

            // Centralized operation name validation
            if (rpcHandler != null)
            {
                if (!EndpointHost.Config.MetadataMap[servicePath].HasOperation(requestName))
                {
                    return(null);
                }
            }

            return(rpcHandler);
        }