public HtmlFormRequestDispatchFormatter(OperationDescription operation, UriTemplate uriTemplate, QueryStringConverter converter, IDispatchMessageFormatter innerFormatter)
            : base(operation, uriTemplate, converter, innerFormatter)
        {
            // This formatter will only support deserializing form post data to a type if:
            //  (1) The type can be converted via the QueryStringConverter or...
            //  (2) The type meets the following requirements:
            //      (A) The type is decorated with the DataContractAttribute
            //      (B) Every public field or property that is decorated with the DataMemberAttribute is of a type that
            //          can be converted by the QueryStringConverter

            this.canConvertBodyType = this.QueryStringConverter.CanConvert(this.BodyParameterType);

            if (!this.canConvertBodyType)
            {
                if (this.BodyParameterType.GetCustomAttributes(typeof(DataContractAttribute), false).Length == 0)
                {
                    throw new NotSupportedException(
                        string.Format("Body parameter '{0}' from operation '{1}' is of type '{2}', which is not decorated with a DataContractAttribute.  " +
                                      "Only body parameter types decorated with the DataContractAttribute are supported.",
                        this.BodyParameterName,
                        operation.Name,
                        this.BodyParameterType));
                }

                // For the body type, we'll need to cache information about each of the public fields/properties
                //  that is decorated with the DataMemberAttribute; we'll store this info in the bodyMembers dictionary
                //  where the member name is the dictionary key
                bodyMembers = new Dictionary<string, BodyMemberData>();

                GetBobyMemberDataForFields(operation.Name);
                GetBodyMemberDataForProperties(operation.Name);

                requiredBodyMembers = bodyMembers.Where(p => p.Value.IsRequired == true).Select(p => p.Key).ToArray();
            }
        }
 public FormsPostDispatchMessageFormatter(OperationDescription od, IDispatchMessageFormatter inner, QueryStringConverter queryStringConverter)
 {
     this.inner = inner;
     this.od = od;
     this.queryStringConverter = queryStringConverter;
     MessageDescription request = null;
     foreach (MessageDescription message in od.Messages)
     {
         if (message.Direction == MessageDirection.Input)
         {
             request = message;
             break;
         }
     }
     if (request != null && request.MessageType == null)
     {
         for (int i = 0; i < request.Body.Parts.Count; ++i)
         {
             if (request.Body.Parts[i].Type == typeof(NameValueCollection))
             {
                 this.nvcIndex = i;
                 break;
             }
         }
     }
 }
		public WebMessageFormatter (OperationDescription operation, ServiceEndpoint endpoint, QueryStringConverter converter, WebHttpBehavior behavior)
		{
			this.operation = operation;
			this.endpoint = endpoint;
			this.converter = converter;
			this.behavior = behavior;
			ApplyWebAttribute ();
			// This is a hack for WebScriptEnablingBehavior
			var jqc = converter as JsonQueryStringConverter;
			if (jqc != null)
				BodyName = jqc.CustomWrapperName;
		}
 public UriTemplateDispatchFormatter(OperationDescription operationDescription, IDispatchMessageFormatter inner, QueryStringConverter qsc, string contractName, Uri baseAddress)
 {
     this.inner         = inner;
     this.qsc           = qsc;
     this.baseAddress   = baseAddress;
     this.operationName = operationDescription.Name;
     UriTemplateClientFormatter.Populate(out this.pathMapping,
                                         out this.queryMapping,
                                         out this.totalNumUTVars,
                                         out this.uriTemplate,
                                         operationDescription,
                                         qsc,
                                         contractName);
 }
 public UriTemplateDispatchFormatter(OperationDescription operationDescription, IDispatchMessageFormatter inner, QueryStringConverter qsc, string contractName, Uri baseAddress)
 {
     this.inner = inner;
     this.qsc = qsc;
     this.baseAddress = baseAddress;
     this.operationName = operationDescription.Name;
     UriTemplateClientFormatter.Populate(out this.pathMapping,
         out this.queryMapping,
         out this.totalNumUTVars,
         out this.uriTemplate,
         operationDescription,
         qsc,
         contractName);
 }
예제 #6
0
        private Func<ParameterInfo, object> CreateParameterBinder(UriTemplateMatch match)
        {
            QueryStringConverter converter = new QueryStringConverter();

            return delegate( ParameterInfo pi )
            {
                string value = match.BoundVariables[pi.Name];

                if (converter.CanConvert(pi.ParameterType) && value != null)
                    return converter.ConvertStringToValue(value, pi.ParameterType);
                else

                return value;
            };
        }
 public UriTemplateClientFormatter(OperationDescription operationDescription, IClientMessageFormatter inner, QueryStringConverter qsc, Uri baseUri, bool innerIsUntypedMessage, string contractName)
 {
     this.inner = inner;
     this.qsc = qsc;
     this.baseUri = baseUri;
     this.innerIsUntypedMessage = innerIsUntypedMessage;
     Populate(out this.pathMapping,
         out this.queryMapping,
         out this.totalNumUTVars,
         out this.uriTemplate,
         operationDescription,
         qsc,
         contractName);
     this.method = WebHttpBehavior.GetWebMethod(operationDescription);
     isGet = this.method == WebHttpBehavior.GET;
 }
 public UriTemplateClientFormatter(OperationDescription operationDescription, IClientMessageFormatter inner, QueryStringConverter qsc, Uri baseUri, bool innerIsUntypedMessage, string contractName)
 {
     this.inner   = inner;
     this.qsc     = qsc;
     this.baseUri = baseUri;
     this.innerIsUntypedMessage = innerIsUntypedMessage;
     Populate(out this.pathMapping,
              out this.queryMapping,
              out this.totalNumUTVars,
              out this.uriTemplate,
              operationDescription,
              qsc,
              contractName);
     this.method = WebHttpBehavior.GetWebMethod(operationDescription);
     isGet       = this.method == WebHttpBehavior.GET;
 }
        public WebMessageFormatter(OperationDescription operation, ServiceEndpoint endpoint, QueryStringConverter converter, WebHttpBehavior behavior)
        {
            this.operation = operation;
            this.endpoint  = endpoint;
            this.converter = converter;
            this.behavior  = behavior;
            ApplyWebAttribute();
#if !NET_2_1
            // This is a hack for WebScriptEnablingBehavior
            var jqc = converter as JsonQueryStringConverter;
            if (jqc != null)
            {
                BodyName = jqc.CustomWrapperName;
            }
#endif
        }
예제 #10
0
        public JsonValueFormatter(OperationDescription operationDescription, ServiceEndpoint endpoint, QueryStringConverter queryStringConverter, int jsonValuePosition)
        {
            this.operationDescription = operationDescription;
            this.queryStringConverter = queryStringConverter;
            this.jsonValuePosition = jsonValuePosition;

            BindingElementCollection bindingElements = endpoint.Binding.CreateBindingElements();
            WebMessageEncodingBindingElement webEncoding = bindingElements.Find<WebMessageEncodingBindingElement>();

            this.charset = CharsetFromEncoding(webEncoding);
            this.readerQuotas = new XmlDictionaryReaderQuotas();
            XmlDictionaryReaderQuotas.Max.CopyTo(this.readerQuotas);
            if (webEncoding != null)
            {
                webEncoding.ReaderQuotas.CopyTo(this.readerQuotas);
            }
        }
        /// <summary>
        /// Initializes a new instance of the EVDispatchFormatter class
        /// </summary>
        /// <param name="od">OperationDescription object</param>
        /// <param name="inner">DispatchMessageFormatter object</param>
        /// <param name="queryStringConverter">QueryStringConverter object</param>
        public EVDispatchFormatter(OperationDescription od, IDispatchMessageFormatter inner, QueryStringConverter queryStringConverter)
        {
            this.inner = inner;
            this.od = od;
            this.queryStringConverter = queryStringConverter;
            MessageDescription request = od.Messages.FirstOrDefault(message => message.Direction == MessageDirection.Input);

            if (request != null && request.MessageType == null)
            {
                for (int i = 0; i < request.Body.Parts.Count; ++i)
                {
                    if (request.Body.Parts[i].Type == typeof(NameValueCollection))
                    {
                        this.nvcIndex = i;
                        break;
                    }
                }
            }
        }
 public MultiDispatchFormatter(OperationDescription operation, QueryStringConverter q, ServiceEndpoint e, bool isRequest)
 {
     this.operation = operation;
     if (isRequest)
     {
         int operationParameterCount = operation.Messages[0].Body.Parts.Count;
         if (operationParameterCount > 1)
         {
             this.parameterNames = new Dictionary<string, int>();
             for (int i = 0; i < operationParameterCount; i++)
             {
                 this.parameterNames.Add(operation.Messages[0].Body.Parts[i].Name, i);
             }
         }
     }
     ep = e;
     qsc = q;
     this.baseAddress = ep.Address.Uri;
     Populate(out this.pathMapping, out this.queryMapping, out this.totalNumUTVars, out this.uriTemplate, operation, qsc);
 }
 public ReplyDispatchFormatter(OperationDescription operation, ServiceEndpoint endpoint, QueryStringConverter converter, WebHttpBehavior behavior)
     : base(operation, endpoint, converter, behavior)
 {
 }
예제 #14
0
			protected WebDispatchMessageFormatter (OperationDescription operation, ServiceEndpoint endpoint, QueryStringConverter converter, WebHttpBehavior behavior)
				: base (operation, endpoint, converter, behavior)
			{
			}
예제 #15
0
			public ReplyDispatchFormatter (OperationDescription operation, ServiceEndpoint endpoint, QueryStringConverter converter, WebHttpBehavior behavior)
				: base (operation, endpoint, converter, behavior)
			{
			}
       private static void Populate(out Dictionary<int, string> pathMapping, out Dictionary<int, KeyValuePair<string, Type>> queryMapping, out int totalNumUTVars, out UriTemplate uriTemplate,
 OperationDescription operationDescription, QueryStringConverter qsc)
       {
           pathMapping = new Dictionary<int, string>();
           queryMapping = new Dictionary<int, KeyValuePair<string, Type>>();
           string utString = GetUTStringOrDefault(operationDescription);
           uriTemplate = new UriTemplate(utString);
           List<string> neededPathVars = new List<string>(uriTemplate.PathSegmentVariableNames);
           List<string> neededQueryVars = new List<string>(uriTemplate.QueryValueVariableNames);
           Dictionary<string, byte> alreadyGotVars = new Dictionary<string, byte>(StringComparer.OrdinalIgnoreCase);
           totalNumUTVars = neededPathVars.Count + neededQueryVars.Count;
           for (int i = 0; i < operationDescription.Messages[0].Body.Parts.Count; ++i)
           {
               MessagePartDescription mpd = operationDescription.Messages[0].Body.Parts[i];
               string parameterName = XmlConvert.DecodeName(mpd.Name);
               if (alreadyGotVars.ContainsKey(parameterName))
               {
                   throw new InvalidOperationException();
               }
               List<string> neededPathCopy = new List<string>(neededPathVars);
               foreach (string pathVar in neededPathCopy)
               {
                   if (string.Compare(parameterName, pathVar, StringComparison.OrdinalIgnoreCase) == 0)
                   {
                       if (mpd.Type != typeof(string))
                       {
                           throw new InvalidOperationException();
                       }
                       pathMapping.Add(i, parameterName);
                       alreadyGotVars.Add(parameterName, 0);
                       neededPathVars.Remove(pathVar);
                   }
               }
               List<string> neededQueryCopy = new List<string>(neededQueryVars);
               foreach (string queryVar in neededQueryCopy)
               {
                   if (string.Compare(parameterName, queryVar, StringComparison.OrdinalIgnoreCase) == 0)
                   {
                       if (!qsc.CanConvert(mpd.Type))
                       {
                           throw new InvalidOperationException();
                       }
                       queryMapping.Add(i, new KeyValuePair<string, Type>(parameterName, mpd.Type));
                       alreadyGotVars.Add(parameterName, 0);
                       neededQueryVars.Remove(queryVar);
                   }
               }
           }
           if (neededPathVars.Count != 0)
           {
               throw new InvalidOperationException();
           }
           if (neededQueryVars.Count != 0)
           {
               throw new InvalidOperationException();
           }
       }
 internal static void Populate(out Dictionary<int, string> pathMapping,
     out Dictionary<int, KeyValuePair<string, Type>> queryMapping,
     out int totalNumUTVars,
     out UriTemplate uriTemplate,
     OperationDescription operationDescription,
     QueryStringConverter qsc,
     string contractName)
 {
     pathMapping = new Dictionary<int, string>();
     queryMapping = new Dictionary<int, KeyValuePair<string, Type>>();
     string utString = GetUTStringOrDefault(operationDescription);
     uriTemplate = new UriTemplate(utString);
     List<string> neededPathVars = new List<string>(uriTemplate.PathSegmentVariableNames);
     List<string> neededQueryVars = new List<string>(uriTemplate.QueryValueVariableNames);
     Dictionary<string, byte> alreadyGotVars = new Dictionary<string, byte>(StringComparer.OrdinalIgnoreCase);
     totalNumUTVars = neededPathVars.Count + neededQueryVars.Count;
     for (int i = 0; i < operationDescription.Messages[0].Body.Parts.Count; ++i)
     {
         MessagePartDescription mpd = operationDescription.Messages[0].Body.Parts[i];
         string parameterName = mpd.XmlName.DecodedName;
         if (alreadyGotVars.ContainsKey(parameterName))
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(
                 SR2.GetString(SR2.UriTemplateVarCaseDistinction, operationDescription.XmlName.DecodedName, contractName, parameterName)));
         }
         List<string> neededPathCopy = new List<string>(neededPathVars);
         foreach (string pathVar in neededPathCopy)
         {
             if (string.Compare(parameterName, pathVar, StringComparison.OrdinalIgnoreCase) == 0)
             {
                 if (mpd.Type != typeof(string))
                 {
                     throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(
                         SR2.GetString(SR2.UriTemplatePathVarMustBeString, operationDescription.XmlName.DecodedName, contractName, parameterName)));
                 }
                 pathMapping.Add(i, parameterName);
                 alreadyGotVars.Add(parameterName, 0);
                 neededPathVars.Remove(pathVar);
             }
         }
         List<string> neededQueryCopy = new List<string>(neededQueryVars);
         foreach (string queryVar in neededQueryCopy)
         {
             if (string.Compare(parameterName, queryVar, StringComparison.OrdinalIgnoreCase) == 0)
             {
                 if (!qsc.CanConvert(mpd.Type))
                 {
                     throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(
                         SR2.GetString(SR2.UriTemplateQueryVarMustBeConvertible, operationDescription.XmlName.DecodedName, contractName, parameterName, mpd.Type, qsc.GetType().Name)));
                 }
                 queryMapping.Add(i, new KeyValuePair<string, Type>(parameterName, mpd.Type));
                 alreadyGotVars.Add(parameterName, 0);
                 neededQueryVars.Remove(queryVar);
             }
         }
     }
     if (neededPathVars.Count != 0)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR2.GetString(
             SR2.UriTemplateMissingVar, operationDescription.XmlName.DecodedName, contractName, neededPathVars[0])));
     }
     if (neededQueryVars.Count != 0)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR2.GetString
             (SR2.UriTemplateMissingVar, operationDescription.XmlName.DecodedName, contractName, neededQueryVars[0])));
     }
 }
 protected WebDispatchMessageFormatter(OperationDescription operation, ServiceEndpoint endpoint, QueryStringConverter converter, WebHttpBehavior behavior)
     : base(operation, endpoint, converter, behavior)
 {
 }
예제 #19
0
		public void Setup ()
		{
			c = new QueryStringConverter ();
		}
        internal static void Populate(out Dictionary <int, string> pathMapping,
                                      out Dictionary <int, KeyValuePair <string, Type> > queryMapping,
                                      out int totalNumUTVars,
                                      out UriTemplate uriTemplate,
                                      OperationDescription operationDescription,
                                      QueryStringConverter qsc,
                                      string contractName)
        {
            pathMapping  = new Dictionary <int, string>();
            queryMapping = new Dictionary <int, KeyValuePair <string, Type> >();
            string utString = GetUTStringOrDefault(operationDescription);

            uriTemplate = new UriTemplate(utString);
            List <string>             neededPathVars  = new List <string>(uriTemplate.PathSegmentVariableNames);
            List <string>             neededQueryVars = new List <string>(uriTemplate.QueryValueVariableNames);
            Dictionary <string, byte> alreadyGotVars  = new Dictionary <string, byte>(StringComparer.OrdinalIgnoreCase);

            totalNumUTVars = neededPathVars.Count + neededQueryVars.Count;
            for (int i = 0; i < operationDescription.Messages[0].Body.Parts.Count; ++i)
            {
                MessagePartDescription mpd = operationDescription.Messages[0].Body.Parts[i];
                string parameterName       = mpd.XmlName.DecodedName;
                if (alreadyGotVars.ContainsKey(parameterName))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(
                                                                                  SR2.GetString(SR2.UriTemplateVarCaseDistinction, operationDescription.XmlName.DecodedName, contractName, parameterName)));
                }
                List <string> neededPathCopy = new List <string>(neededPathVars);
                foreach (string pathVar in neededPathCopy)
                {
                    if (string.Compare(parameterName, pathVar, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        if (mpd.Type != typeof(string))
                        {
                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(
                                                                                          SR2.GetString(SR2.UriTemplatePathVarMustBeString, operationDescription.XmlName.DecodedName, contractName, parameterName)));
                        }
                        pathMapping.Add(i, parameterName);
                        alreadyGotVars.Add(parameterName, 0);
                        neededPathVars.Remove(pathVar);
                    }
                }
                List <string> neededQueryCopy = new List <string>(neededQueryVars);
                foreach (string queryVar in neededQueryCopy)
                {
                    if (string.Compare(parameterName, queryVar, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        if (!qsc.CanConvert(mpd.Type))
                        {
                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(
                                                                                          SR2.GetString(SR2.UriTemplateQueryVarMustBeConvertible, operationDescription.XmlName.DecodedName, contractName, parameterName, mpd.Type, qsc.GetType().Name)));
                        }
                        queryMapping.Add(i, new KeyValuePair <string, Type>(parameterName, mpd.Type));
                        alreadyGotVars.Add(parameterName, 0);
                        neededQueryVars.Remove(queryVar);
                    }
                }
            }
            if (neededPathVars.Count != 0)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR2.GetString(
                                                                                                            SR2.UriTemplateMissingVar, operationDescription.XmlName.DecodedName, contractName, neededPathVars[0])));
            }
            if (neededQueryVars.Count != 0)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR2.GetString
                                                                                                            (SR2.UriTemplateMissingVar, operationDescription.XmlName.DecodedName, contractName, neededQueryVars[0])));
            }
        }