System.ServiceModel.Dispatcher.OperationFormatter.Validate C# (CSharp) Method

Validate() private method

private Validate ( OperationDescription od, bool isRpc, bool isEncoded ) : void
od System.ServiceModel.Description.OperationDescription
isRpc bool
isEncoded bool
return void
		void Validate (OperationDescription od, bool isRpc, bool isEncoded)
		{
			bool hasParameter = false, hasVoid = false;
			foreach (var md in od.Messages) {
				if (md.IsTypedMessage || md.IsUntypedMessage) {
					if (isRpc && !isEncoded)
						throw new InvalidOperationException ("Message with action {0} is either strongly-typed or untyped, but defined as RPC and encoded.");
					if (hasParameter && !md.IsVoid)
						throw new InvalidOperationException (String.Format ("Operation '{0}' contains a message with parameters. Strongly-typed or untyped message can be paired only with strongly-typed, untyped or void message.", od.Name));
					if (isRpc && hasVoid)
						throw new InvalidOperationException (String.Format ("This operation '{0}' is defined as RPC and contains a message with void, which is not allowed.", od.Name));
				} else {
					hasParameter |= !md.IsVoid;
					hasVoid |= md.IsVoid;
				}
			}
		}

Usage Example

Example #1
0
        public PrimitiveOperationFormatter(OperationDescription description, bool isRpc)
        {
            if (description == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("description");
            }

            OperationFormatter.Validate(description, isRpc, false /*isEncoded*/);

            this.operation = description;
#pragma warning suppress 56506 // Microsoft, OperationDescription.Messages never be null
            this.requestMessage = description.Messages[0];
            if (description.Messages.Count == 2)
            {
                this.responseMessage = description.Messages[1];
            }

            int stringCount = 3 + requestMessage.Body.Parts.Count;
            if (responseMessage != null)
            {
                stringCount += 2 + responseMessage.Body.Parts.Count;
            }

            XmlDictionary dictionary = new XmlDictionary(stringCount * 2);

            xsiNilLocalName = dictionary.Add("nil");
            xsiNilNamespace = dictionary.Add(System.Xml.Schema.XmlSchema.InstanceNamespace);

            OperationFormatter.GetActions(description, dictionary, out this.action, out this.replyAction);

            if (requestMessage.Body.WrapperName != null)
            {
                requestWrapperName      = AddToDictionary(dictionary, requestMessage.Body.WrapperName);
                requestWrapperNamespace = AddToDictionary(dictionary, requestMessage.Body.WrapperNamespace);
            }

            requestParts = AddToDictionary(dictionary, requestMessage.Body.Parts, isRpc);

            if (responseMessage != null)
            {
                if (responseMessage.Body.WrapperName != null)
                {
                    responseWrapperName      = AddToDictionary(dictionary, responseMessage.Body.WrapperName);
                    responseWrapperNamespace = AddToDictionary(dictionary, responseMessage.Body.WrapperNamespace);
                }

                responseParts = AddToDictionary(dictionary, responseMessage.Body.Parts, isRpc);

                if (responseMessage.Body.ReturnValue != null && responseMessage.Body.ReturnValue.Type != typeof(void))
                {
                    returnPart = AddToDictionary(dictionary, responseMessage.Body.ReturnValue, isRpc);
                }
            }
        }
All Usage Examples Of System.ServiceModel.Dispatcher.OperationFormatter::Validate