Beispiel #1
0
        private void CheckBodyStyle(OperationDescription operationDescription, bool isRequest)
        {
            WebInvokeAttribute wia = operationDescription.Behaviors.Find <WebInvokeAttribute>();
            WebGetAttribute    wga = operationDescription.Behaviors.Find <WebGetAttribute>();

            CheckWebInvokeAndWebGet(wia, wga, operationDescription);

            WebMessageBodyStyle bodyStyle = this.DefaultBodyStyle;

            if (wia != null && wia.IsBodyStyleSetExplicitly)
            {
                bodyStyle = wia.BodyStyle;
            }
            else if (wga != null && wga.IsBodyStyleSetExplicitly)
            {
                bodyStyle = wga.BodyStyle;
            }

            if (isRequest)
            {
                if (wga == null && (bodyStyle == WebMessageBodyStyle.Wrapped || bodyStyle == WebMessageBodyStyle.WrappedRequest))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.FormEncodedMustBeBare));
                }
            }
            else
            {
                if (bodyStyle == WebMessageBodyStyle.Wrapped || bodyStyle == WebMessageBodyStyle.WrappedResponse)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.FormEncodedMustBeBare));
                }
            }
        }
Beispiel #2
0
 public WebHttpBehavior()
 {
     defaultOutgoingRequestFormat = WebMessageFormat.Xml;
     defaultOutgoingReplyFormat = WebMessageFormat.Xml;
     this.defaultBodyStyle = WebMessageBodyStyle.Bare;
     xmlSerializerManager = new UnwrappedTypesXmlSerializerManager();
 }
 internal static bool IsDefined(WebMessageBodyStyle style)
 {
     return (style == WebMessageBodyStyle.Bare
         || style == WebMessageBodyStyle.Wrapped
         || style == WebMessageBodyStyle.WrappedRequest
         || style == WebMessageBodyStyle.WrappedResponse);
 }
 internal static bool IsDefined(WebMessageBodyStyle style)
 {
     return(style == WebMessageBodyStyle.Bare ||
            style == WebMessageBodyStyle.Wrapped ||
            style == WebMessageBodyStyle.WrappedRequest ||
            style == WebMessageBodyStyle.WrappedResponse);
 }
Beispiel #5
0
        private void ValidateOperation(OperationDescription operation)
        {
            if (operation.Messages.Count > 1)
            {
                if (operation.Messages[1].Body.Parts.Count > 0)
                {
                    throw new InvalidOperationException("Operations cannot have out/ref parameters.");
                }
            }

            WebMessageBodyStyle bodyStyle = this.GetBodyStyle(operation);
            int inputParameterCount       = operation.Messages[0].Body.Parts.Count;

            if (!this.IsGetOperation(operation))
            {
                var wrappedRequest = bodyStyle == WebMessageBodyStyle.Wrapped || bodyStyle == WebMessageBodyStyle.WrappedRequest;
                if (inputParameterCount == 1 && wrappedRequest)
                {
                    throw new InvalidOperationException("Wrapped body style for single parameters not implemented in this behavior.");
                }
            }

            var wrappedResponse = bodyStyle == WebMessageBodyStyle.Wrapped || bodyStyle == WebMessageBodyStyle.WrappedResponse;
            var isVoidReturn    = operation.Messages.Count == 1 || operation.Messages[1].Body.ReturnValue.Type == typeof(void);

            if (!isVoidReturn && wrappedResponse)
            {
                throw new InvalidOperationException("Wrapped response not implemented in this behavior.");
            }
        }
Beispiel #6
0
        public void PropertiesTest()
        {
            WebHttpElement3 target = new WebHttpElement3();

            bool anyBool1 = AnyInstance.AnyBool;
            bool anyBool2 = !AnyInstance.AnyBool;
            bool anyBool3 = AnyInstance.AnyBool;
            WebMessageBodyStyle anyBodyStyle     = WebMessageBodyStyle.Bare;
            WebMessageFormat    anyMessageFormat = WebMessageFormat.Xml;

            target.AutomaticFormatSelectionEnabled = anyBool1;
            Assert.AreEqual(anyBool1, target.AutomaticFormatSelectionEnabled);

            target.DefaultBodyStyle = anyBodyStyle;
            Assert.AreEqual(anyBodyStyle, target.DefaultBodyStyle);

            target.DefaultOutgoingResponseFormat = anyMessageFormat;
            Assert.AreEqual(anyMessageFormat, target.DefaultOutgoingResponseFormat);

            target.FaultExceptionEnabled = anyBool2;
            Assert.AreEqual(anyBool2, target.FaultExceptionEnabled);

            target.HelpEnabled = anyBool3;
            Assert.AreEqual(anyBool3, target.HelpEnabled);
        }
        /// <summary>
        /// Valida a operação informada.
        /// </summary>
        /// <param name="operation"></param>
        protected void ValidateOperation(OperationDescription operation)
        {
            if (operation.Messages.Count > 1 && operation.Messages[1].Body.Parts.Count > 0)
            {
                throw new InvalidOperationException("Operations cannot have out/ref parameters.");
            }
            if (!this.enableUriTemplate)
            {
                string uriTemplate = this.GetUriTemplate(operation);
                if (uriTemplate != null)
                {
                    throw new InvalidOperationException("UriTemplate is not supported by this behavior.");
                }
            }
            var found = false;
            WebMessageBodyStyle bodyStyle = this.GetBodyStyle(operation, out found);

            if (!found)
            {
                return;
            }
            bool wrappedResponse = bodyStyle == WebMessageBodyStyle.Wrapped || bodyStyle == WebMessageBodyStyle.WrappedResponse;
            bool isVoidReturn    = operation.Messages.Count == 1 || operation.Messages[1].Body.ReturnValue.Type == typeof(void);

            if (!isVoidReturn && wrappedResponse)
            {
                throw new InvalidOperationException("Wrapped response not implemented in this behavior.");
            }
        }
Beispiel #8
0
 public WebHttp3Values(bool automaticFormatSelectionEnabledValue, WebMessageBodyStyle defaultBodyStyleValue, WebMessageFormat defaultOutgoingResponseFormatValue, bool faultExceptionEnabledValue, bool helpEnabledValue)
 {
     this.AutomaticFormatSelectionEnabledValue = automaticFormatSelectionEnabledValue;
     this.DefaultBodyStyleValue = defaultBodyStyleValue;
     this.DefaultOutgoingResponseFormatValue = defaultOutgoingResponseFormatValue;
     this.FaultExceptionEnabledValue         = faultExceptionEnabledValue;
     this.HelpEnabledValue = helpEnabledValue;
 }
Beispiel #9
0
 public JsonClientFormatter(Uri baseUri, OperationDescription operationDescription, WebMessageBodyStyle defaultBodyStyle)
 {
     this.baseUri = baseUri;
     this.operationDescription = operationDescription;
     this.defaultBodyStyle     = defaultBodyStyle;
     this.queryStringConverter = new QueryStringConverter();
     this.Initialize();
 }
Beispiel #10
0
        public WcfServiceHostFactory AddSecureRestfulEndPoint(
            string address,
            bool helpEnabled = false,
            bool automaticFormatSelectionEnabled           = false,
            WebMessageBodyStyle defaultBodyStyle           = WebMessageBodyStyle.Bare,
            WebMessageFormat defaultOutgoingRequestFormat  = WebMessageFormat.Xml,
            WebMessageFormat defaultOutgoingResponseFormat = WebMessageFormat.Xml,
            bool crossDomainScriptAccessEnabled            = false)
        {
            var endPointPrameters = new EndPointParameters
            {
                Address = address,
                Binding = new WebHttpBinding
                {
                    CrossDomainScriptAccessEnabled = crossDomainScriptAccessEnabled,
                    CloseTimeout           = new TimeSpan(0, 15, 0),
                    OpenTimeout            = new TimeSpan(0, 15, 0),
                    ReceiveTimeout         = new TimeSpan(0, 15, 0),
                    SendTimeout            = new TimeSpan(0, 15, 0),
                    AllowCookies           = false,
                    BypassProxyOnLocal     = false,
                    HostNameComparisonMode = HostNameComparisonMode.StrongWildcard,
                    MaxBufferSize          = int.MaxValue,
                    MaxBufferPoolSize      = int.MaxValue,
                    MaxReceivedMessageSize = int.MaxValue,
                    TransferMode           = TransferMode.Buffered,
                    UseDefaultWebProxy     = true,
                    ReaderQuotas           = new XmlDictionaryReaderQuotas
                    {
                        MaxDepth = 2000000,
                        MaxStringContentLength = int.MaxValue,
                        MaxArrayLength         = int.MaxValue,
                        MaxBytesPerRead        = int.MaxValue,
                        MaxNameTableCharCount  = int.MaxValue
                    },
                    Security =
                        new WebHttpSecurity
                    {
                        Mode      = WebHttpSecurityMode.Transport,
                        Transport = new HttpTransportSecurity {
                            ClientCredentialType = HttpClientCredentialType.None
                        }
                    }
                }
            };

            endPointPrameters.Behaviors
            .Add(new WebHttpBehavior
            {
                AutomaticFormatSelectionEnabled = true,
                DefaultOutgoingRequestFormat    = WebMessageFormat.Json,
                DefaultOutgoingResponseFormat   = WebMessageFormat.Json,
                DefaultBodyStyle = WebMessageBodyStyle.Bare,
                HelpEnabled      = true
            });
            _endPoints.Add(endPointPrameters);
            return(this);
        }
Beispiel #11
0
 internal override bool UseBareReplyFormatter(WebMessageBodyStyle style, OperationDescription operationDescription, WebMessageFormat responseFormat, out Type parameterType)
 {
     if (responseFormat == WebMessageFormat.Json)
     {
         parameterType = null;
         return(false);
     }
     return(base.UseBareReplyFormatter(style, operationDescription, responseFormat, out parameterType));
 }
Beispiel #12
0
        } //  do nothing

        internal WebMessageBodyStyle GetBodyStyleOrDefault(WebMessageBodyStyle defaultStyle)
        {
            if (this.IsBodyStyleSetExplicitly)
            {
                return(this.BodyStyle);
            }
            else
            {
                return(defaultStyle);
            }
        }
Beispiel #13
0
        public override void Validate(ServiceEndpoint endpoint)
        {
            base.Validate(endpoint);

#pragma warning disable 56506 // Microsoft, endpoint.Contract is never null
            foreach (OperationDescription operation in endpoint.Contract.Operations)
#pragma warning restore 56506
            {
                if (operation.Behaviors.Find <XmlSerializerOperationBehavior>() != null)
                {
                    throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(
                                                                                                      SR2.GetString(SR2.WebScriptNotSupportedForXmlSerializerFormat, typeof(XmlSerializerFormatAttribute).Name, this.GetType().ToString())));
                }
                string method = WebHttpBehavior.GetWebMethod(operation);
                if (method != WebHttpBehavior.GET &&
                    method != WebHttpBehavior.POST)
                {
                    throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(
                                                                                                      SR2.GetString(SR2.WebScriptInvalidHttpRequestMethod, operation.Name,
                                                                                                                    endpoint.Contract.Name, method, this.GetType().ToString())));
                }
                WebGetAttribute webGetAttribute = operation.Behaviors.Find <WebGetAttribute>();
                if (webGetAttribute != null && webGetAttribute.UriTemplate != null)
                {
                    throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(
                                                                                                      SR2.GetString(SR2.WebScriptNotSupportedForXmlSerializerFormat, typeof(UriTemplate).Name, this.GetType().ToString())));
                }
                WebInvokeAttribute webInvokeAttribute = operation.Behaviors.Find <WebInvokeAttribute>();
                if (webInvokeAttribute != null && webInvokeAttribute.UriTemplate != null)
                {
                    throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(
                                                                                                      SR2.GetString(SR2.WebScriptNotSupportedForXmlSerializerFormat, typeof(UriTemplate).Name, this.GetType().ToString())));
                }
                WebMessageBodyStyle bodyStyle = GetBodyStyle(operation);
                if (bodyStyle != webScriptBodyStyle)
                {
                    throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(SR2.GetString(SR2.BodyStyleNotSupportedByWebScript, bodyStyle, this.GetType().Name, webScriptBodyStyle)));
                }

                foreach (MessageDescription messageDescription in operation.Messages)
                {
                    if (!messageDescription.IsTypedMessage &&
                        (messageDescription.Direction == MessageDirection.Output) &&
                        (messageDescription.Body.Parts.Count > 0))
                    {
                        throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(
                                                                                                          SR2.GetString(SR2.WebScriptOutRefOperationsNotSupported, operation.Name,
                                                                                                                        endpoint.Contract.Name)));
                    }
                }
            }
        }
Beispiel #14
0
        public object DeserializeReply(Message message, object[] parameters)
        {
            if (this.operationDescription.Messages.Count == 1)
            {
                return(null);
            }

            if (parameters.Length == 0 && this.operationDescription.Messages[1].Body.ReturnValue.Type == typeof(void))
            {
                return(null);
            }

            XmlDictionaryReader reader = message.GetReaderAtBodyContents();

            byte[]              buffer     = reader.ReadElementContentAsBase64();
            MemoryStream        jsonStream = new MemoryStream(buffer);
            WebMessageBodyStyle bodyStyle  = GetBodyStyle(this.operationDescription);

            if (bodyStyle == WebMessageBodyStyle.Bare || bodyStyle == WebMessageBodyStyle.WrappedRequest)
            {
                DataContractJsonSerializer dcjs = new DataContractJsonSerializer(this.operationDescription.Messages[1].Body.ReturnValue.Type);
                return(dcjs.ReadObject(jsonStream));
            }
            else
            {
                JsonObject jo = JsonValue.Load(jsonStream) as JsonObject;
                if (jo == null)
                {
                    throw new InvalidOperationException("Response is not a JSON object");
                }

                for (int i = 0; i < this.operationDescription.Messages[1].Body.Parts.Count; i++)
                {
                    MessagePartDescription outPart = this.operationDescription.Messages[1].Body.Parts[i];
                    if (jo.ContainsKey(outPart.Name))
                    {
                        parameters[i] = Deserialize(outPart.Type, jo[outPart.Name]);
                    }
                }

                MessagePartDescription returnPart = this.operationDescription.Messages[1].Body.ReturnValue;
                if (returnPart != null && jo.ContainsKey(returnPart.Name))
                {
                    return(Deserialize(returnPart.Type, jo[returnPart.Name]));
                }
                else
                {
                    return(null);
                }
            }
        }
Beispiel #15
0
        public void ValuesTest()
        {
            bool anyBool1 = AnyInstance.AnyBool;
            bool anyBool2 = !AnyInstance.AnyBool;
            bool anyBool3 = AnyInstance.AnyBool;
            WebMessageBodyStyle anyBodyStyle     = WebMessageBodyStyle.Bare;
            WebMessageFormat    anyMessageFormat = WebMessageFormat.Xml;

            string configXml = CreateConfig(anyBool1, anyBodyStyle, anyMessageFormat, anyBool2, anyBool3);

            TestjQueryConfigurationSection configSection = TestjQueryConfigurationSection.GetWebHttpBehavior3Section(configXml);
            WebHttpElement3 element = configSection.WebHttpElement3;

            Assert.AreEqual(typeof(WebHttpBehavior3), element.BehaviorType);

            Assert.AreEqual(anyBool1, element.AutomaticFormatSelectionEnabled);
            Assert.AreEqual(anyBodyStyle, element.DefaultBodyStyle);
            Assert.AreEqual(anyMessageFormat, element.DefaultOutgoingResponseFormat);
            Assert.AreEqual(anyBool2, element.FaultExceptionEnabled);
            Assert.AreEqual(anyBool3, element.HelpEnabled);
        }
Beispiel #16
0
        private byte[] GetJsonBody(List <KeyValuePair <int, object> > bodyParameters)
        {
            WebMessageBodyStyle        bodyStyle = GetBodyStyle(this.operationDescription);
            DataContractJsonSerializer dcjs;
            MemoryStream ms;

            if (bodyParameters.Count == 0)
            {
                return(new byte[0]);
            }

            if (bodyStyle == WebMessageBodyStyle.Bare || bodyStyle == WebMessageBodyStyle.WrappedResponse)
            {
                ms   = new MemoryStream();
                dcjs = new DataContractJsonSerializer(this.operationDescription.Messages[0].Body.Parts[bodyParameters[0].Key].Type);
                dcjs.WriteObject(ms, bodyParameters[0].Value);
            }
            else
            {
                JsonObject jo = new JsonObject();
                for (int i = 0; i < bodyParameters.Count; i++)
                {
                    MessagePartDescription part = this.operationDescription.Messages[0].Body.Parts[bodyParameters[i].Key];
                    dcjs = new DataContractJsonSerializer(part.Type);
                    ms   = new MemoryStream();
                    dcjs.WriteObject(ms, bodyParameters[i].Value);
                    ms.Position = 0;
                    JsonValue jv = JsonValue.Load(ms);
                    jo.Add(part.Name, jv);
                }

                ms = new MemoryStream();
                jo.Save(ms);
            }

            return(ms.ToArray());
        }
Beispiel #17
0
 internal virtual bool UseBareRequestFormatter(WebMessageBodyStyle style, OperationDescription operationDescription, out Type parameterType)
 {
     parameterType = null;
     return IsBareRequest(style) && TryGetNonMessageParameterType(operationDescription.Messages[0], operationDescription, true, out parameterType);
 }
Beispiel #18
0
        //[WebGet(UriTemplate="help")]
        public Atom10FeedFormatter GetFeed()
        {
            List <SyndicationItem> items = new List <SyndicationItem>();

            foreach (OperationDescription od in this.Description.Operations)
            {
                WebGetAttribute    get           = od.Behaviors.Find <WebGetAttribute>();
                WebInvokeAttribute invoke        = od.Behaviors.Find <WebInvokeAttribute>();
                string             method        = GetMethod(get, invoke);
                string             requestFormat = null;
                if (invoke != null)
                {
                    requestFormat = GetRequestFormat(invoke, od);
                }
                string responseFormat         = GetResponseFormat(get, invoke, od);
                string uriTemplate            = GetUriTemplate(get, invoke, od);
                WebMessageBodyStyle bodyStyle = GetBodyStyle(get, invoke);

                string requestSchemaLink   = null;
                string responseSchemaLink  = null;
                string requestExampleLink  = null;
                string responseExampleLink = null;

                if (bodyStyle == WebMessageBodyStyle.Bare)
                {
                    UriTemplate responseSchemaTemplate = new UriTemplate(OperationResponseSchemaTemplate);
                    responseSchemaLink = responseSchemaTemplate.BindByPosition(this.BaseUri, od.Name).AbsoluteUri;

                    UriTemplate responseExampleTemplate = new UriTemplate(OperationResponseExampleTemplate);
                    responseExampleLink = responseExampleTemplate.BindByPosition(this.BaseUri, od.Name).AbsoluteUri;
                    if (invoke != null)
                    {
                        UriTemplate requestSchemaTemplate = new UriTemplate(OperationRequestSchemaTemplate);
                        requestSchemaLink = requestSchemaTemplate.BindByPosition(this.BaseUri, od.Name).AbsoluteUri;

                        UriTemplate requestExampleTemplate = new UriTemplate(OperationRequestExampleTemplate);
                        requestExampleLink = requestExampleTemplate.BindByPosition(this.BaseUri, od.Name).AbsoluteUri;
                    }
                }

                uriTemplate = String.Format("{0}/{1}", this.BaseUri.AbsoluteUri, uriTemplate);
                uriTemplate = HttpUtility.HtmlEncode(uriTemplate);

                string xhtmlDescription = String.Format("<div xmlns=\"http://www.w3.org/1999/xhtml\"><table border=\"5\"><tr><td>UriTemplate</td><td>{0}</td></tr><tr><td>Method</td><td>{1}</td></tr>", uriTemplate, method);
                if (!string.IsNullOrEmpty(requestFormat))
                {
                    xhtmlDescription += String.Format("<tr><td>Request Format</td><td>{0}</td></tr>", requestFormat);
                }
                if (requestSchemaLink != null)
                {
                    xhtmlDescription += String.Format("<tr><td>Request Schema</td><td><a href=\"{0}\">{0}</a></td></tr>", HttpUtility.HtmlEncode(requestSchemaLink));
                }
                if (requestExampleLink != null)
                {
                    xhtmlDescription += String.Format("<tr><td>Request Example</td><td><a href=\"{0}\">{0}</a></td></tr>", HttpUtility.HtmlEncode(requestExampleLink));
                }
                xhtmlDescription += String.Format("<tr><td>Response Format</td><td>{0}</td></tr>", responseFormat);
                if (responseSchemaLink != null)
                {
                    xhtmlDescription += String.Format("<tr><td>Response Schema</td><td><a href=\"{0}\">{0}</a></td></tr>", HttpUtility.HtmlEncode(responseSchemaLink));
                }
                if (responseExampleLink != null)
                {
                    xhtmlDescription += String.Format("<tr><td>Response Example</td><td><a href=\"{0}\">{0}</a></td></tr>", HttpUtility.HtmlEncode(responseExampleLink));
                }
                WebHelpAttribute help = od.Behaviors.Find <WebHelpAttribute>();
                if (help != null && !string.IsNullOrEmpty(help.Comment))
                {
                    xhtmlDescription += String.Format("<tr><td>Description</td><td>{0}</td></tr>", help.Comment);
                }
                xhtmlDescription += "</table></div>";
                SyndicationItem item = new SyndicationItem()
                {
                    Id              = "http://tmpuri.org/" + od.Name,
                    Content         = new TextSyndicationContent(xhtmlDescription, TextSyndicationContentKind.XHtml),
                    LastUpdatedTime = DateTime.UtcNow,
                    Title           = new TextSyndicationContent(String.Format("{0}: {1}", Description.Name, od.Name)),
                };
                items.Add(item);
            }

            SyndicationFeed feed = new SyndicationFeed()
            {
                Title           = new TextSyndicationContent("Service help page"),
                Id              = feedId,
                LastUpdatedTime = DateTime.UtcNow,
                Items           = items
            };

            WebOperationContext.Current.OutgoingResponse.ContentType = "application/atom+xml";
            return(feed.GetAtom10Formatter());
        }
Beispiel #19
0
 static bool IsBareResponse(WebMessageBodyStyle style)
 {
     return (style == WebMessageBodyStyle.Bare || style == WebMessageBodyStyle.WrappedRequest);
 }
Beispiel #20
0
        private void Initialize()
        {
            this.uriTemplate = GetUriTemplate(this.operationDescription);
            this.method      = GetHttpRequestMethod(this.operationDescription);
            List <string> pathVariables           = new List <string>(this.uriTemplate.PathSegmentVariableNames);
            List <string> queryVariables          = new List <string>(this.uriTemplate.QueryValueVariableNames);
            int           numberOfUriTemplateVars = pathVariables.Count + queryVariables.Count;

            this.pathMapping  = new Dictionary <int, string>();
            this.queryMapping = new Dictionary <int, KeyValuePair <Type, string> >();

            for (int i = 0; i < this.operationDescription.Messages[0].Body.Parts.Count; i++)
            {
                MessagePartDescription part = operationDescription.Messages[0].Body.Parts[i];
                string        parameterName = part.Name;
                List <string> pathCopy      = new List <string>(pathVariables);
                foreach (string pathVar in pathCopy)
                {
                    if (String.Compare(pathVar, parameterName, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        if (part.Type != typeof(string))
                        {
                            throw new InvalidOperationException(
                                      String.Format(
                                          "UriTemplate path variable '{0}' for operation '{1}' needs to be of type String",
                                          pathVar,
                                          operationDescription.Name));
                        }
                        pathMapping.Add(i, parameterName);
                        pathVariables.Remove(pathVar);
                    }
                }

                List <string> queryCopy = new List <string>(queryVariables);
                foreach (string queryVar in queryCopy)
                {
                    if (String.Compare(queryVar, parameterName, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        if (!queryStringConverter.CanConvert(part.Type))
                        {
                            throw new InvalidOperationException(
                                      String.Format(
                                          "Parameter '{0}' of type '{1}' cannot be converted to strings by the QueryStringConverter",
                                          parameterName,
                                          part.Type.FullName));
                        }

                        queryMapping.Add(i, new KeyValuePair <Type, string>(part.Type, parameterName));
                        queryVariables.Remove(queryVar);
                    }
                }
            }

            if (pathVariables.Count > 0)
            {
                throw new InvalidOperationException(
                          String.Format(
                              "Operation '{0}' expects a parameter named '{1}', but such parameter doesn't exist",
                              operationDescription.Name,
                              pathVariables[0]));
            }

            if (queryVariables.Count > 0)
            {
                throw new InvalidOperationException(
                          String.Format(
                              "Operation '{0}' expects a parameter named '{1}', but such parameter doesn't exist",
                              operationDescription.Name,
                              queryVariables[0]));
            }

            int numberOfUnmappedParameters = operationDescription.Messages[0].Body.Parts.Count - numberOfUriTemplateVars;

            if (numberOfUnmappedParameters > 0 && (this.method == HttpMethodGet || this.method == HttpMethodHead))
            {
                throw new InvalidOperationException(
                          String.Format(
                              "Operation '{0}' has parameters which are not mapped to the UriTemplate, but it cannot have a body (because of the HTTP verb)",
                              operationDescription.Name));
            }

            WebMessageBodyStyle bodyStyle = GetBodyStyle(operationDescription);

            if (numberOfUnmappedParameters > 1)
            {
                if (bodyStyle == WebMessageBodyStyle.Bare || bodyStyle == WebMessageBodyStyle.WrappedResponse)
                {
                    throw new InvalidOperationException(
                              String.Format(
                                  "Operation '{0}' has more than 1 parameter to be serialized without a wrapper element. Use BodyStyle.Wrapped (or WrappedRequest) for this operation",
                                  operationDescription.Name));
                }
            }

            if (operationDescription.Messages.Count > 1 && operationDescription.Messages[1].Body.Parts.Count > 1)
            {
                if (bodyStyle == WebMessageBodyStyle.Bare || bodyStyle == WebMessageBodyStyle.WrappedRequest)
                {
                    throw new InvalidOperationException(
                              String.Format(
                                  "Operation '{0}' has more than 1 output parameter to be serialized without a wrapper element. Use BodyStyle.Wrapped (or WrappedResponse) for this operation",
                                  operationDescription.Name));
                }
            }
        }
Beispiel #21
0
 internal WebMessageBodyStyle GetBodyStyleOrDefault(WebMessageBodyStyle defaultStyle)
 {
   if (this.IsBodyStyleSetExplicitly)
     return this.BodyStyle;
   else
     return defaultStyle;
 }
 /// <summary>
 /// Creates a new instance of the RawJsonWebHttpBehavior 
 /// class with a specificied default BodyStyle.
 /// </summary>
 /// <param name="messageBodyStyle">The WebMessageBodyStyle to use by default.</param>
 public RawJsonWebHttpBehavior(WebMessageBodyStyle messageBodyStyle)
 {
     this.DefaultBodyStyle = messageBodyStyle;
     this.DefaultOutgoingRequestFormat = WebMessageFormat.Json;
     this.DefaultOutgoingResponseFormat = WebMessageFormat.Json;
 }
Beispiel #23
0
        static string CreateConfig(bool? automaticFormatSelectionEnabled, WebMessageBodyStyle? defaultBodyStyle, WebMessageFormat? defaultOutgoingResponseFormat, bool? faultExceptionEnabled, bool? helpEnabled)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(@"<?xml version='1.0' encoding='utf-8' ?>
            <configuration>
              <configSections>
            <section name='jQueryConfigurationSection' type='Microsoft.ServiceModel.Web.UnitTests.TestjQueryConfigurationSection, Microsoft.ServiceModel.Web.jQuery.UnitTests' />
              </configSections>
              <jQueryConfigurationSection>
            <webHttp3 ");

            if (automaticFormatSelectionEnabled.HasValue)
            {
                sb.AppendFormat("automaticFormatSelectionEnabled='{0}' ", automaticFormatSelectionEnabled.Value);
            }

            if (defaultBodyStyle.HasValue)
            {
                sb.AppendFormat("defaultBodyStyle='{0}' ", defaultBodyStyle.Value);
            }

            if (defaultOutgoingResponseFormat.HasValue)
            {
                sb.AppendFormat("defaultOutgoingResponseFormat='{0}' ", defaultOutgoingResponseFormat.Value);
            }

            if (faultExceptionEnabled.HasValue)
            {
                sb.AppendFormat("faultExceptionEnabled='{0}' ", faultExceptionEnabled.Value);
            }

            if (helpEnabled.HasValue)
            {
                sb.AppendFormat("helpEnabled='{0}' ", helpEnabled.Value);
            }

            sb.Append(@"/>
              </jQueryConfigurationSection>
            </configuration>");

            return sb.ToString();
        }
        // Token: 0x06001674 RID: 5748 RVA: 0x00052B28 File Offset: 0x00050D28
        private static void ProcessMethod(MethodInfo methodInfo, Dictionary <string, MethodInfo> endMethodMap, Dictionary <string, ServiceMethodInfo> methodTable, List <Attribute> attributes)
        {
            OperationContractAttribute customAttribute = OwaServiceMethodMap.GetCustomAttribute <OperationContractAttribute>(attributes);

            if (customAttribute == null)
            {
                return;
            }
            WebInvokeAttribute              customAttribute2 = OwaServiceMethodMap.GetCustomAttribute <WebInvokeAttribute>(attributes);
            JsonRequestFormatAttribute      customAttribute3 = OwaServiceMethodMap.GetCustomAttribute <JsonRequestFormatAttribute>(attributes);
            WebGetAttribute                 customAttribute4 = OwaServiceMethodMap.GetCustomAttribute <WebGetAttribute>(attributes);
            OperationBehaviorAttribute      customAttribute5 = OwaServiceMethodMap.GetCustomAttribute <OperationBehaviorAttribute>(attributes);
            JsonResponseOptionsAttribute    customAttribute6 = OwaServiceMethodMap.GetCustomAttribute <JsonResponseOptionsAttribute>(attributes);
            JsonRequestWrapperTypeAttribute customAttribute7 = OwaServiceMethodMap.GetCustomAttribute <JsonRequestWrapperTypeAttribute>(attributes);
            AsyncStateMachineAttribute      customAttribute8 = OwaServiceMethodMap.GetCustomAttribute <AsyncStateMachineAttribute>(attributes);
            bool flag  = customAttribute != null && customAttribute.AsyncPattern;
            bool flag2 = customAttribute8 != null;
            bool flag3 = customAttribute5 == null || customAttribute5.AutoDisposeParameters;
            bool isResponseCacheable = customAttribute6 != null && customAttribute6.IsCacheable;
            WebMessageBodyStyle webMessageBodyStyle = (customAttribute2 != null) ? customAttribute2.BodyStyle : WebMessageBodyStyle.Bare;

            if (customAttribute2 != null)
            {
                WebMessageFormat requestFormat = customAttribute2.RequestFormat;
            }
            if (customAttribute2 != null)
            {
                WebMessageFormat responseFormat = customAttribute2.ResponseFormat;
            }
            JsonRequestFormat jsonRequestFormat = (customAttribute3 != null) ? customAttribute3.Format : JsonRequestFormat.Custom;
            bool             isHttpGet          = (customAttribute2 != null) ? customAttribute2.Method.Equals("GET", StringComparison.InvariantCultureIgnoreCase) : (customAttribute4 != null);
            string           text                    = (customAttribute2 != null) ? customAttribute2.UriTemplate : ((customAttribute4 != null) ? customAttribute4.UriTemplate : null);
            UriTemplate      uriTemplate             = (!string.IsNullOrEmpty(text)) ? new UriTemplate(text) : null;
            bool             flag4                   = webMessageBodyStyle == WebMessageBodyStyle.WrappedRequest || webMessageBodyStyle == WebMessageBodyStyle.Wrapped;
            bool             isWrappedResponse       = webMessageBodyStyle == WebMessageBodyStyle.WrappedResponse || webMessageBodyStyle == WebMessageBodyStyle.Wrapped;
            WebMessageFormat webMethodRequestFormat  = (customAttribute2 != null && customAttribute2.IsRequestFormatSetExplicitly) ? customAttribute2.RequestFormat : WebMessageFormat.Json;
            WebMessageFormat webMethodResponseFormat = (customAttribute2 != null && customAttribute2.IsResponseFormatSetExplicitly) ? customAttribute2.ResponseFormat : WebMessageFormat.Json;
            Type             type                    = (customAttribute7 != null) ? customAttribute7.Type : null;
            string           text2                   = methodInfo.Name;
            MethodInfo       beginMethod             = null;
            MethodInfo       methodInfo2             = null;
            MethodInfo       syncMethod              = null;
            MethodInfo       genericAsyncTaskMethod  = null;
            Type             type2                   = null;
            Type             type3;

            if (text2.StartsWith("Begin", StringComparison.InvariantCultureIgnoreCase) && flag)
            {
                type3       = ((methodInfo.GetParameters().Length > 0) ? methodInfo.GetParameters()[0].ParameterType : null);
                beginMethod = methodInfo;
                text2       = text2.Substring("Begin".Length);
                string key = "End" + text2;
                if (endMethodMap.TryGetValue(key, out methodInfo2))
                {
                    type2 = methodInfo2.ReturnType;
                }
            }
            else
            {
                syncMethod = methodInfo;
                type3      = ((methodInfo.GetParameters().Length > 0) ? methodInfo.GetParameters()[0].ParameterType : null);
                type2      = methodInfo.ReturnType;
                if (flag2 && type2 != null && type2.GenericTypeArguments != null && type2.GenericTypeArguments.Length > 0)
                {
                    genericAsyncTaskMethod = OwaServiceMethodMap.handleAsyncMethodInfo.MakeGenericMethod(type2.GenericTypeArguments);
                    type2 = type2.GenericTypeArguments[0];
                }
            }
            bool isStreamedResponse        = OwaServiceMethodMap.IsStreamResponse(type2);
            bool shouldAutoDisposeResponse = flag3 && OwaServiceMethodMap.ImplementsInterface <IDisposable>(type2);
            bool shouldAutoDisposeRequest  = flag3 && OwaServiceMethodMap.ImplementsInterface <IDisposable>(type3);

            if (flag4 && type == null)
            {
                string wrappedRequestTypeName = OwaServiceMethodMap.GetWrappedRequestTypeName(text2);
                type = OwaServiceMethodMap.thisAssembly.GetType(wrappedRequestTypeName, false);
            }
            ServiceMethodInfo value = new ServiceMethodInfo
            {
                BeginMethod            = beginMethod,
                EndMethod              = methodInfo2,
                GenericAsyncTaskMethod = genericAsyncTaskMethod,
                IsAsyncAwait           = flag2,
                IsAsyncPattern         = flag,
                IsHttpGet              = isHttpGet,
                IsResponseCacheable    = isResponseCacheable,
                IsStreamedResponse     = isStreamedResponse,
                IsWrappedRequest       = flag4,
                IsWrappedResponse      = isWrappedResponse,
                JsonRequestFormat      = jsonRequestFormat,
                Name                           = text2,
                RequestType                    = type3,
                ResponseType                   = type2,
                ShouldAutoDisposeRequest       = shouldAutoDisposeRequest,
                ShouldAutoDisposeResponse      = shouldAutoDisposeResponse,
                SyncMethod                     = syncMethod,
                UriTemplate                    = uriTemplate,
                WebMethodRequestFormat         = webMethodRequestFormat,
                WebMethodResponseFormat        = webMethodResponseFormat,
                WrappedRequestType             = type,
                WrappedRequestTypeParameterMap = OwaServiceMethodMap.BuildParameterMap(type)
            };

            methodTable.Add(text2, value);
        }
Beispiel #25
0
 public WebHttp3Values(bool automaticFormatSelectionEnabledValue, WebMessageBodyStyle defaultBodyStyleValue, WebMessageFormat defaultOutgoingResponseFormatValue, bool faultExceptionEnabledValue, bool helpEnabledValue)
 {
     this.AutomaticFormatSelectionEnabledValue = automaticFormatSelectionEnabledValue;
     this.DefaultBodyStyleValue = defaultBodyStyleValue;
     this.DefaultOutgoingResponseFormatValue = defaultOutgoingResponseFormatValue;
     this.FaultExceptionEnabledValue = faultExceptionEnabledValue;
     this.HelpEnabledValue = helpEnabledValue;
 }
Beispiel #26
0
 internal virtual bool UseBareReplyFormatter(WebMessageBodyStyle style, OperationDescription operationDescription, WebMessageFormat responseFormat, out Type parameterType)
 {
     parameterType = null;
     return IsBareResponse(style) && TryGetNonMessageParameterType(operationDescription.Messages[1], operationDescription, false, out parameterType);
 }
 internal override bool UseBareReplyFormatter(WebMessageBodyStyle style, OperationDescription operationDescription, WebMessageFormat responseFormat, out Type parameterType)
 {
     if (responseFormat == WebMessageFormat.Json)
     {
         parameterType = null;
         return false;
     }
     return base.UseBareReplyFormatter(style, operationDescription, responseFormat, out parameterType);
 }