Пример #1
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)));
                    }
                }
            }
        }