示例#1
0
        internal Request ParseIncomingRequest()
        {
            // Steps:
            // 1. Parse and validate request URI format (/syncscope/syncoperation)
            // 2. Validate QueryString using the HttpContextServiceHost.VerifyQueryParameters method.
            // 3. Parse and save query string parameters
            // 4. Identify and save request type, scopename, syncblob, request body.

            // throw BadRequest if duplicates are found.

            /*
             * string[] RelativeUriSegments = new string[_serviceHost.RelativeUriSegments.Length - 1];
             * for (int i = 1; i < _serviceHost.RelativeUriSegments.Length; i++)
             *  RelativeUriSegments[i - 1] = _serviceHost.RelativeUriSegments[i];
             */
            string[] RelativeUriSegments = _serviceHost.RelativeUriSegments;


            _serviceHost.VerifyQueryParameters();
            SyncSerializationFormat outputSerializationFormat = _serviceHost.GetOutputSerializationFormat(_configuration.SerializationFormat);

            SyncTracer.Verbose("Output Serialization format: {0}", outputSerializationFormat);

            RequestCommand requestCommand = GetRequestCommandType(RelativeUriSegments);

            SyncTracer.Verbose("RequestCommand type: {0}", requestCommand);

            List <IOfflineEntity> entities = null;
            Dictionary <CommandParamType, object> commandParameters = null;

            // Get command paramaters (filter params, scope name etc.) for all request types except $syncScopes
            if (requestCommand != RequestCommand.SyncScopes)
            {
                commandParameters = GetCommandParameters(_serviceHost.QueryStringCollection, RelativeUriSegments);
            }

            // Read the payload, headers etc for upload and download request types.
            if (requestCommand == RequestCommand.DownloadChanges || requestCommand == RequestCommand.UploadChanges)
            {
                ReadIncomingRequestDetails();
                entities = GetEntityListFromRequest(requestCommand);
            }

            var request = new Request(requestCommand, _serviceHost, commandParameters, _syncBlob, entities, outputSerializationFormat)
            {
                IdToTempIdMapping = _idToTempIdMapping
            };

            return(request);
        }
示例#2
0
        /// <summary>
        /// Create a new instance of the WCF Message class that has the correct content type (xml/json) and has a serialized
        /// instance of the SyncError class which is a representation of the error message.
        /// </summary>
        /// <param name="httpStatusCode">Status code to be used for the outgoing response.</param>
        /// <param name="errorDescription">A description of the error.</param>
        /// <returns>An instance of the WCF Message class that is sent as response.</returns>
        private Message CreateExceptionMessage(HttpStatusCode httpStatusCode, string errorDescription)
        {
            var error = new ServiceError {
                ErrorDescription = errorDescription
            };

            Message message;

            if (_syncConfiguration.SerializationFormat == SyncSerializationFormat.ODataJson)
            {
                message = Message.CreateMessage(MessageVersion.None, String.Empty, error, new DataContractJsonSerializer(typeof(ServiceError)));
                message.Properties.Add(WebBodyFormatMessageProperty.Name, new WebBodyFormatMessageProperty(WebContentFormat.Json));
            }
            else
            {
                message = Message.CreateMessage(MessageVersion.None, String.Empty, error, new DataContractSerializer(typeof(ServiceError)));
                message.Properties.Add(WebBodyFormatMessageProperty.Name, new WebBodyFormatMessageProperty(WebContentFormat.Xml));
            }

            var property = new HttpResponseMessageProperty {
                StatusCode = httpStatusCode
            };

            property.Headers.Add(HttpResponseHeader.ContentType, WebUtil.GetContentType(_serviceHost.GetOutputSerializationFormat(_syncConfiguration.SerializationFormat)));

            message.Properties.Add(HttpResponseMessageProperty.Name, property);

            return(message);
        }