示例#1
0
        /// <summary>
        /// Add the Ping method to the existing contract
        /// </summary>
        private void AddPingToContractDescription(ContractDescription contractDescription)
        {
            OperationDescription pingOperationDescription = new OperationDescription(PingOperationName, contractDescription);

            MessageDescription inputMessageDescription = new MessageDescription(
                GetAction(contractDescription, PingOperationName),
                MessageDirection.Input);

            MessageDescription outputMessageDescription = new MessageDescription(
                GetAction(contractDescription, PingResponse),
                MessageDirection.Output);

            MessagePartDescription returnValue = new MessagePartDescription("PingResult", contractDescription.Namespace);

            returnValue.Type = typeof(DateTime);
            outputMessageDescription.Body.ReturnValue = returnValue;

            inputMessageDescription.Body.WrapperName = PingOperationName;
            inputMessageDescription.Body.WrapperNamespace = contractDescription.Namespace;
            outputMessageDescription.Body.WrapperName = PingResponse;
            outputMessageDescription.Body.WrapperNamespace = contractDescription.Namespace;

            pingOperationDescription.Messages.Add(inputMessageDescription);
            pingOperationDescription.Messages.Add(outputMessageDescription);

            pingOperationDescription.Behaviors.Add(new DataContractSerializerOperationBehavior(pingOperationDescription));
            pingOperationDescription.Behaviors.Add(new PingOperationBehavior());

            contractDescription.Operations.Add(pingOperationDescription);
        }
 protected override void AddHeadersToMessage(Message message, MessageDescription messageDescription, object[] parameters, bool isRequest)
 {
     MessageInfo info = isRequest ? this.requestMessageInfo : this.replyMessageInfo;
     PartInfo[] headerParts = info.HeaderParts;
     if ((headerParts != null) && (headerParts.Length != 0))
     {
         MessageHeaders headers = message.Headers;
         for (int i = 0; i < headerParts.Length; i++)
         {
             PartInfo headerPart = headerParts[i];
             MessageHeaderDescription description = (MessageHeaderDescription) headerPart.Description;
             object parameterValue = parameters[description.Index];
             if (description.Multiple)
             {
                 if (parameterValue != null)
                 {
                     bool isXmlElement = description.Type == typeof(XmlElement);
                     foreach (object obj3 in (IEnumerable) parameterValue)
                     {
                         this.AddMessageHeaderForParameter(headers, headerPart, message.Version, obj3, isXmlElement);
                     }
                 }
             }
             else
             {
                 this.AddMessageHeaderForParameter(headers, headerPart, message.Version, parameterValue, false);
             }
         }
     }
 }
 protected void AddParameterOrder(MessageDescription message)
 {
     if (this.operation != null)
     {
         Operation operation = this.contractContext.GetOperation(this.operation);
         if (operation != null)
         {
             if (operation.ParameterOrder == null)
             {
                 operation.ParameterOrder = new string[this.GetParameterCount()];
             }
             if (operation.ParameterOrder.Length != 0)
             {
                 foreach (MessagePartDescription description in message.Body.Parts)
                 {
                     ParameterInfo additionalAttributesProvider = description.AdditionalAttributesProvider as ParameterInfo;
                     if ((additionalAttributesProvider != null) && (additionalAttributesProvider.Position >= 0))
                     {
                         operation.ParameterOrder[additionalAttributesProvider.Position] = description.Name;
                     }
                 }
             }
         }
     }
 }
示例#4
0
 internal static StreamFormatter Create(MessageDescription messageDescription, string operationName, bool isRequest)
 {
     MessagePartDescription streamPart = ValidateAndGetStreamPart(messageDescription, isRequest, operationName);
     if (streamPart == null)
         return null;
     return new StreamFormatter(messageDescription, streamPart, operationName, isRequest);
 }
示例#5
0
		protected override object [] MessageToParts (MessageDescription md, Message message)
		{
			if (message.IsEmpty)
				return null;
				
			XmlDictionaryReader r = message.GetReaderAtBodyContents ();
			return (object []) GetSerializer (md.Body).Deserialize (r);
		}
示例#6
0
 private static KeyValuePair<string, ComplexType> getExistingElement(XmlTypeExtractor schemaImporter, MessageDescription message)
 {
     Func<KeyValuePair<string, ComplexType>, bool> existingElementPredicate =
         _ => _.Key == message.Body.WrapperNamespace && _.Value.Name == message.Body.WrapperName;
     if (!schemaImporter.Elements.Any(existingElementPredicate))
     {
         throw new InvalidOperationException("Couldn't find the element definition");
     }
     var existingElement = schemaImporter.Elements.Single(existingElementPredicate);
     return existingElement;
 }
示例#7
0
 private static bool IsUntypedMessage(MessageDescription message)
 {
     if (message == null)
     {
         return false;
     }
     return ((((message.Body.ReturnValue != null) &&
         (message.Body.Parts.Count == 0)) &&
         (message.Body.ReturnValue.Type == typeof(Message))) ||
         (((message.Body.ReturnValue == null) && (message.Body.Parts.Count == 1)) &&
         (message.Body.Parts[0].Type == typeof(Message))));
 }
示例#8
0
 private StreamFormatter(MessageDescription messageDescription, MessagePartDescription streamPart, string operationName, bool isRequest)
 {
     if ((object)streamPart == (object)messageDescription.Body.ReturnValue)
         _streamIndex = returnValueIndex;
     else
         _streamIndex = streamPart.Index;
     _wrapperName = messageDescription.Body.WrapperName;
     _wrapperNS = messageDescription.Body.WrapperNamespace;
     _partName = streamPart.Name;
     _partNS = streamPart.Namespace;
     _isRequest = isRequest;
     _operationName = operationName;
 }
 private static MessagePartDescription GetStreamPart(MessageDescription messageDescription)
 {
     if (OperationFormatter.IsValidReturnValue(messageDescription.Body.ReturnValue))
     {
         if ((messageDescription.Body.Parts.Count == 0) && (messageDescription.Body.ReturnValue.Type == typeof(Stream)))
         {
             return messageDescription.Body.ReturnValue;
         }
     }
     else if ((messageDescription.Body.Parts.Count == 1) && (messageDescription.Body.Parts[0].Type == typeof(Stream)))
     {
         return messageDescription.Body.Parts[0];
     }
     return null;
 }
 private static bool HasStream(MessageDescription messageDescription)
 {
     if ((messageDescription.Body.ReturnValue != null) && (messageDescription.Body.ReturnValue.Type == typeof(Stream)))
     {
         return true;
     }
     foreach (MessagePartDescription description in messageDescription.Body.Parts)
     {
         if (description.Type == typeof(Stream))
         {
             return true;
         }
     }
     return false;
 }
        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);
                }
            }
        }
示例#12
0
		public static void AssertMessageAndBodyDescription (
			string action, MessageDirection dir,
			Type messageType, string bodyWrapperName,
			string bodyWrapperNS, bool bodyHasReturn,
			MessageDescription md, string label)
		{
			Assert.AreEqual (action, md.Action, label + " Action");
			Assert.AreEqual (dir, md.Direction, label + " Direction");
			Assert.AreEqual (messageType, md.MessageType, label + " MessageType");
			Assert.AreEqual (bodyWrapperName, md.Body.WrapperName,
				label + " Body.WrapperName");
			Assert.AreEqual (bodyWrapperNS, md.Body.WrapperNamespace,
				label + " Body.WrapperNamespace");
			Assert.AreEqual (bodyHasReturn, md.Body.ReturnValue != null,
				label + "Body hasReturn");
		}
示例#13
0
 static void ShowMessageBody(MessageDescription message)
 {
     Console.WriteLine(message.Direction == MessageDirection.Input ?"请求消息:" : "回复消息:");
     MessageBodyDescription body = message.Body;
     Console.WriteLine("<tns:{0} xmlns:tns=\"{1}\">", body.WrapperName,body.WrapperNamespace);
     foreach (var part in body.Parts)
     {
         Console.WriteLine("\t<tns:{0}>...</tns:{0}>", part.Name);
     }
     if (null != body.ReturnValue)
     {
         Console.WriteLine("\t<tns:{0}>...</tns:{0}>",
             body.ReturnValue.Name);
     }
     Console.WriteLine("</tns:{0}>", body.WrapperName);
 }
        public PrimitiveOperationFormatter(OperationDescription description, bool isRpc)
        {
            if (description == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("description");

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

            _operation = description;
            _requestMessage = description.Messages[0];
            if (description.Messages.Count == 2)
                _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(EndpointAddressProcessor.XsiNs);

            OperationFormatter.GetActions(description, dictionary, out _action, out _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);
                }
            }
        }
        private static OperationDescription CreatePreflightOperation(OperationDescription operation)
        {
            ContractDescription contract = operation.DeclaringContract;
            var preflightOperation = new OperationDescription(operation.Name + CorsConstants.PreflightSuffix, contract);
            var inputMessage = new MessageDescription(
                operation.Messages[0].Action + CorsConstants.PreflightSuffix, MessageDirection.Input);
            inputMessage.Body.Parts.Add(
                new MessagePartDescription("input", contract.Namespace) { Index = 0, Type = typeof(Message) });
            preflightOperation.Messages.Add(inputMessage);
            var outputMessage = new MessageDescription(
                operation.Messages[1].Action + CorsConstants.PreflightSuffix, MessageDirection.Output);
            outputMessage.Body.ReturnValue = new MessagePartDescription(
                preflightOperation.Name + "Return", contract.Namespace) { Type = typeof(Message) };
            preflightOperation.Messages.Add(outputMessage);

            return preflightOperation;
        }
 private StreamFormatter(MessageDescription messageDescription, MessagePartDescription streamPart, string operationName, bool isRequest)
 {
     if (streamPart == messageDescription.Body.ReturnValue)
     {
         this.streamIndex = -1;
     }
     else
     {
         this.streamIndex = streamPart.Index;
     }
     this.wrapperName = messageDescription.Body.WrapperName;
     this.wrapperNS = messageDescription.Body.WrapperNamespace;
     this.partName = streamPart.Name;
     this.partNS = streamPart.Namespace;
     this.isRequest = isRequest;
     this.operationName = operationName;
 }
 public static void AddMessagePartDescription(OperationDescription operation, bool isResponse, MessageDescription message, string[] argumentNames, Type[] argumentTypes)
 {
     string ns = operation.DeclaringContract.Namespace;
     for (int i = 0; i < argumentNames.Length; i++)
     {
         string name = argumentNames[i];
         MessagePartDescription item = new MessagePartDescription(NamingHelper.XmlName(name), ns) {
             Index = i,
             Type = argumentTypes[i]
         };
         message.Body.Parts.Add(item);
     }
     if (isResponse)
     {
         SetReturnValue(message, operation);
     }
 }
 internal MessageDescription(MessageDescription other)
 {
     this.action = other.action;
     this.direction = other.direction;
     this.Items.Body = other.Items.Body.Clone();
     foreach (MessageHeaderDescription description in other.Items.Headers)
     {
         this.Items.Headers.Add(description.Clone() as MessageHeaderDescription);
     }
     foreach (MessagePropertyDescription description2 in other.Items.Properties)
     {
         this.Items.Properties.Add(description2.Clone() as MessagePropertyDescription);
     }
     this.MessageName = other.MessageName;
     this.MessageType = other.MessageType;
     this.XsdTypeName = other.XsdTypeName;
     this.hasProtectionLevel = other.hasProtectionLevel;
     this.ProtectionLevel = other.ProtectionLevel;
 }
 internal MessageDescription(MessageDescription other)
 {
     _action = other._action;
     _direction = other._direction;
     this.Items.Body = other.Items.Body.Clone();
     foreach (MessageHeaderDescription mhd in other.Items.Headers)
     {
         this.Items.Headers.Add(mhd.Clone() as MessageHeaderDescription);
     }
     foreach (MessagePropertyDescription mpd in other.Items.Properties)
     {
         this.Items.Properties.Add(mpd.Clone() as MessagePropertyDescription);
     }
     this.MessageName = other.MessageName;
     this.MessageType = other.MessageType;
     this.XsdTypeName = other.XsdTypeName;
     _hasProtectionLevel = other._hasProtectionLevel;
     this.ProtectionLevel = other.ProtectionLevel;
 }
 public PrimitiveOperationFormatter(OperationDescription description, bool isRpc)
 {
     if (description == null)
     {
         throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("description");
     }
     OperationFormatter.Validate(description, isRpc, false);
     this.operation = description;
     this.requestMessage = description.Messages[0];
     if (description.Messages.Count == 2)
     {
         this.responseMessage = description.Messages[1];
     }
     int num = 3 + this.requestMessage.Body.Parts.Count;
     if (this.responseMessage != null)
     {
         num += 2 + this.responseMessage.Body.Parts.Count;
     }
     XmlDictionary dictionary = new XmlDictionary(num * 2);
     this.xsiNilLocalName = dictionary.Add("nil");
     this.xsiNilNamespace = dictionary.Add("http://www.w3.org/2001/XMLSchema-instance");
     OperationFormatter.GetActions(description, dictionary, out this.action, out this.replyAction);
     if (this.requestMessage.Body.WrapperName != null)
     {
         this.requestWrapperName = AddToDictionary(dictionary, this.requestMessage.Body.WrapperName);
         this.requestWrapperNamespace = AddToDictionary(dictionary, this.requestMessage.Body.WrapperNamespace);
     }
     this.requestParts = AddToDictionary(dictionary, this.requestMessage.Body.Parts, isRpc);
     if (this.responseMessage != null)
     {
         if (this.responseMessage.Body.WrapperName != null)
         {
             this.responseWrapperName = AddToDictionary(dictionary, this.responseMessage.Body.WrapperName);
             this.responseWrapperNamespace = AddToDictionary(dictionary, this.responseMessage.Body.WrapperNamespace);
         }
         this.responseParts = AddToDictionary(dictionary, this.responseMessage.Body.Parts, isRpc);
         if ((this.responseMessage.Body.ReturnValue != null) && (this.responseMessage.Body.ReturnValue.Type != typeof(void)))
         {
             this.returnPart = AddToDictionary(dictionary, this.responseMessage.Body.ReturnValue, isRpc);
         }
     }
 }
 public static void AddMessagePartDescription(OperationDescription operation, bool isResponse, MessageDescription message, Type type, SerializerOption serializerOption)
 {
     if (type != null)
     {
         string name;
         string str2;
         if (serializerOption == SerializerOption.DataContractSerializer)
         {
             XmlQualifiedName rootElementName = XsdDataContractExporter.GetRootElementName(type);
             if (rootElementName == null)
             {
                 rootElementName = XsdDataContractExporter.GetSchemaTypeName(type);
             }
             if (!rootElementName.IsEmpty)
             {
                 name = rootElementName.Name;
                 str2 = rootElementName.Namespace;
             }
             else
             {
                 name = type.Name;
                 str2 = operation.DeclaringContract.Namespace;
             }
         }
         else
         {
             XmlTypeMapping mapping = XmlReflectionImporter.ImportTypeMapping(type);
             name = mapping.ElementName;
             str2 = mapping.Namespace;
         }
         MessagePartDescription item = new MessagePartDescription(NamingHelper.XmlName(name), str2) {
             Index = 0,
             Type = type
         };
         message.Body.Parts.Add(item);
     }
     if (isResponse)
     {
         SetReturnValue(message, operation);
     }
 }
 internal void AddMessage(MessageDescription messageDescription, WsdlNS.OperationMessage wsdlOperationMessage)
 {
     this.wsdlOperationMessages.Add(messageDescription, wsdlOperationMessage);
     this.messageDescriptions.Add(wsdlOperationMessage, messageDescription);
 }
示例#23
0
 public OperationMessage GetOperationMessage(
     MessageDescription message)
 {
     throw new NotImplementedException();
 }
示例#24
0
        ContractDescription DoImportContract(PortType wsdlPortType)
        {
            BeforeImport();

            ContractDescription cd = new ContractDescription(wsdlPortType.Name, wsdlPortType.ServiceDescription.TargetNamespace);

            foreach (Operation op in wsdlPortType.Operations)
            {
                OperationDescription op_descr = new OperationDescription(op.Name, cd);

                foreach (OperationMessage opmsg in op.Messages)
                {
                    /* OperationMessageCollection */
                    MessageDescription msg_descr;
                    MessageDirection   dir    = MessageDirection.Input;
                    string             action = "";

                    if (opmsg.GetType() == typeof(OperationInput))
                    {
                        dir = MessageDirection.Input;
                    }
                    else if (opmsg.GetType() == typeof(OperationOutput))
                    {
                        dir = MessageDirection.Output;
                    }
                    /* FIXME: OperationFault--> OperationDescription.Faults ? */

                    if (opmsg.ExtensibleAttributes != null)
                    {
                        for (int i = 0; i < opmsg.ExtensibleAttributes.Length; i++)
                        {
                            if (opmsg.ExtensibleAttributes [i].LocalName == "Action" &&
                                opmsg.ExtensibleAttributes [i].NamespaceURI == "http://www.w3.org/2006/05/addressing/wsdl")
                            {
                                /* addressing:Action */
                                action = opmsg.ExtensibleAttributes [i].Value;
                            }
                            /* FIXME: other attributes ? */
                        }
                    }

                    // fill Action from operation binding if required.
                    if (action == "")
                    {
                        if (dir != MessageDirection.Input)
                        {
                            action = GetActionFromOperationBinding(wsdlPortType, op.Name);
                        }
                        else
                        {
                            action = "*";
                        }
                    }

                    msg_descr = new MessageDescription(action, dir);
                    /* FIXME: Headers ? */

                    op_descr.Messages.Add(msg_descr);
                }

                cd.Operations.Add(op_descr);
            }

            WsdlContractConversionContext context = new WsdlContractConversionContext(cd, wsdlPortType);

            foreach (IWsdlImportExtension extension in wsdl_extensions)
            {
                extension.ImportContract(this, context);
            }

            return(cd);
        }
示例#25
0
 public override PolicyAssertionCollection GetMessageBindingAssertions(MessageDescription message)
 {
     return(s_noPolicy);
 }
 public MessageBinding GetMessageBinding(
     MessageDescription message)
 {
     throw new NotImplementedException();
 }
示例#27
0
		protected object DeserializeObject (XmlObjectSerializer serializer, Message message, MessageDescription md, bool isWrapped, WebContentFormat fmt)
		{
			// FIXME: handle ref/out parameters

			var reader = message.GetReaderAtBodyContents ();
			reader.MoveToContent ();

			bool wasEmptyElement = reader.IsEmptyElement;

			if (isWrapped) {
				if (fmt == WebContentFormat.Json)
					reader.ReadStartElement ("root", String.Empty); // note that the wrapper name is passed to the serializer.
				else
					reader.ReadStartElement (md.Body.WrapperName, md.Body.WrapperNamespace);
			}

			var ret = (serializer == null) ? null : ReadObjectBody (serializer, reader);

			if (isWrapped && !wasEmptyElement)
				reader.ReadEndElement ();

			return ret;
		}
        private static OperationDescription GetCopyOfOperationDescription(OperationDescription other)
        {
            OperationDescription operationDecription = new OperationDescription(other.Name, other.DeclaringContract)
            {
                BeginMethod = other.BeginMethod,
                EndMethod = other.EndMethod,
                IsInitiating = other.IsInitiating,
                IsTerminating = other.IsTerminating,
                ProtectionLevel = other.ProtectionLevel,
                SyncMethod = other.SyncMethod,
            };

            // copy Behaviors, Known Types, Faults
            foreach (IOperationBehavior behavior in other.Behaviors)
            {
                operationDecription.Behaviors.Add(behavior);
            }

            foreach (Type knownType in other.KnownTypes)
            {
                operationDecription.KnownTypes.Add(knownType);
            }

            foreach (FaultDescription fault in other.Faults)
            {
                operationDecription.Faults.Add(fault);
            }

            // copy the Messages from the original OperationDescription
            foreach (MessageDescription messageDescription in other.Messages)
            {
                MessageDescription newMessageDescription = new MessageDescription(messageDescription.Action, messageDescription.Direction);
                operationDecription.Messages.Add(newMessageDescription);
            }

            return operationDecription;
        }
 public abstract PolicyAssertionCollection GetMessageBindingAssertions(MessageDescription message);
        protected override void AddHeadersToMessage(Message message, MessageDescription messageDescription, object[] parameters, bool isRequest)
        {
            XmlSerializer serializer;
            MessageHeaderDescriptionTable headerDescriptionTable;
            MessageHeaderDescription unknownHeaderDescription;
            bool mustUnderstand;
            bool relay;
            string actor;
            try
            {
                if (isRequest)
                {
                    serializer = _requestMessageInfo.HeaderSerializer;
                    headerDescriptionTable = _requestMessageInfo.HeaderDescriptionTable;
                    unknownHeaderDescription = _requestMessageInfo.UnknownHeaderDescription;
                }
                else
                {
                    serializer = _replyMessageInfo.HeaderSerializer;
                    headerDescriptionTable = _replyMessageInfo.HeaderDescriptionTable;
                    unknownHeaderDescription = _replyMessageInfo.UnknownHeaderDescription;
                }
                if (serializer != null)
                {
                    object[] headerValues = new object[headerDescriptionTable.Count];
                    MessageHeaderOfTHelper messageHeaderOfTHelper = null;
                    int headerIndex = 0;

                    foreach (MessageHeaderDescription headerDescription in messageDescription.Headers)
                    {
                        object parameterValue = parameters[headerDescription.Index];
                        if (!headerDescription.IsUnknownHeaderCollection)
                        {
                            if (headerDescription.TypedHeader)
                            {
                                if (messageHeaderOfTHelper == null)
                                    messageHeaderOfTHelper = new MessageHeaderOfTHelper(parameters.Length);
                                headerValues[headerIndex++] = messageHeaderOfTHelper.GetContentAndSaveHeaderAttributes(parameters[headerDescription.Index], headerDescription);
                            }
                            else
                                headerValues[headerIndex++] = parameterValue;
                        }
                    }

                    MemoryStream memoryStream = new MemoryStream();
                    XmlDictionaryWriter bufferWriter = XmlDictionaryWriter.CreateTextWriter(memoryStream);
                    bufferWriter.WriteStartElement("root");
                    serializer.Serialize(bufferWriter, headerValues, null);
                    bufferWriter.WriteEndElement();
                    bufferWriter.Flush();
                    XmlDocument doc = new XmlDocument();
                    memoryStream.Position = 0;
                    doc.Load(memoryStream);
                    //doc.Save(Console.Out);
                    foreach (XmlElement element in doc.DocumentElement.ChildNodes)
                    {
                        MessageHeaderDescription matchingHeaderDescription = headerDescriptionTable.Get(element.LocalName, element.NamespaceURI);
                        if (matchingHeaderDescription == null)
                            message.Headers.Add(new XmlElementMessageHeader(this, message.Version, element.LocalName, element.NamespaceURI,
                                                                            false/*mustUnderstand*/, null/*actor*/, false/*relay*/, element));
                        else
                        {
                            if (matchingHeaderDescription.TypedHeader)
                                messageHeaderOfTHelper.GetHeaderAttributes(matchingHeaderDescription, out mustUnderstand, out relay, out actor);
                            else
                            {
                                mustUnderstand = matchingHeaderDescription.MustUnderstand;
                                relay = matchingHeaderDescription.Relay;
                                actor = matchingHeaderDescription.Actor;
                            }
                            message.Headers.Add(new XmlElementMessageHeader(this, message.Version, element.LocalName, element.NamespaceURI,
                                                                            mustUnderstand, actor, relay, element));
                        }
                    }
                }
                if (unknownHeaderDescription != null && parameters[unknownHeaderDescription.Index] != null)
                {
                    foreach (object unknownHeader in (IEnumerable)parameters[unknownHeaderDescription.Index])
                    {
                        XmlElement element = (XmlElement)GetContentOfMessageHeaderOfT(unknownHeaderDescription, unknownHeader, out mustUnderstand, out relay, out actor);
                        if (element != null)
                            message.Headers.Add(new XmlElementMessageHeader(this, message.Version, element.LocalName, element.NamespaceURI,
                                                                  mustUnderstand, actor, relay, element));
                    }
                }
            }
            catch (InvalidOperationException e)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(
                    SR.Format(SR.SFxErrorSerializingHeader, messageDescription.MessageName, e.Message), e));
            }
        }
示例#31
0
        public static MessageDescription CreateMessageDescription(
            OperationContractAttribute oca, ParameterInfo[] plist, string name, string defaultNamespace, string action, bool isRequest, bool isCallback, Type retType, ICustomAttributeProvider retTypeAttributes)
        {
            var dir = isRequest ^ isCallback ? MessageDirection.Input : MessageDirection.Output;
            MessageDescription md = new MessageDescription(action, dir)
            {
                IsRequest = isRequest
            };

            MessageBodyDescription mb = md.Body;

            mb.WrapperName      = name + (isRequest ? String.Empty : "Response");
            mb.WrapperNamespace = defaultNamespace;

            if (oca.HasProtectionLevel)
            {
                md.ProtectionLevel = oca.ProtectionLevel;
            }

            // Parts
            int index = 0;

            foreach (ParameterInfo pi in plist)
            {
                // AsyncCallback and state are extraneous.
                if (oca.AsyncPattern && pi.Position == plist.Length - 2)
                {
                    break;
                }

                // They are ignored:
                // - out parameter in request
                // - neither out nor ref parameter in reply
                if (isRequest && pi.IsOut)
                {
                    continue;
                }
                if (!isRequest && !pi.IsOut && !pi.ParameterType.IsByRef)
                {
                    continue;
                }

                MessagePartDescription pd = CreatePartCore(GetMessageParameterAttribute(pi), pi.Name, defaultNamespace);
                pd.Index = index++;
                pd.Type  = MessageFilterOutByRef(pi.ParameterType);
                mb.Parts.Add(pd);
            }

            // ReturnValue
            if (!isRequest)
            {
                MessagePartDescription mp = CreatePartCore(GetMessageParameterAttribute(retTypeAttributes), name + "Result", mb.WrapperNamespace);
                mp.Index       = 0;
                mp.Type        = retType;
                mb.ReturnValue = mp;
            }

            // FIXME: fill properties.

            return(md);
        }
示例#32
0
        public static MessageDescription CreateMessageDescription(
            Type messageType, string defaultNamespace, string action, bool isRequest, bool isCallback, MessageContractAttribute mca)
        {
            MessageDescription md = new MessageDescription(action, isRequest ^ isCallback ? MessageDirection.Input : MessageDirection.Output)
            {
                IsRequest = isRequest
            };

            md.MessageType = MessageFilterOutByRef(messageType);
            if (mca.HasProtectionLevel)
            {
                md.ProtectionLevel = mca.ProtectionLevel;
            }

            MessageBodyDescription mb = md.Body;

            if (mca.IsWrapped)
            {
                mb.WrapperName      = mca.WrapperName ?? messageType.Name;
                mb.WrapperNamespace = mca.WrapperNamespace ?? defaultNamespace;
            }

            int index = 0;

            foreach (MemberInfo bmi in messageType.GetMembers(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
            {
                Type   mtype = null;
                string mname = null;
                if (bmi is FieldInfo)
                {
                    FieldInfo fi = (FieldInfo)bmi;
                    mtype = fi.FieldType;
                    mname = fi.Name;
                }
                else if (bmi is PropertyInfo)
                {
                    PropertyInfo pi = (PropertyInfo)bmi;
                    mtype = pi.PropertyType;
                    mname = pi.Name;
                }
                else
                {
                    continue;
                }

                var mha = bmi.GetCustomAttribute <MessageHeaderAttribute> (false);
                if (mha != null)
                {
                    var pd = CreateHeaderDescription(mha, mname, defaultNamespace);
                    pd.Type       = MessageFilterOutByRef(mtype);
                    pd.MemberInfo = bmi;
                    md.Headers.Add(pd);
                }
                var mba = GetMessageBodyMemberAttribute(bmi);
                if (mba != null)
                {
                    var pd = CreatePartCore(mba, mname, defaultNamespace);
                    if (pd.Index <= 0)
                    {
                        pd.Index = index++;
                    }
                    pd.Type       = MessageFilterOutByRef(mtype);
                    pd.MemberInfo = bmi;
                    mb.Parts.Add(pd);
                }
            }

            // FIXME: fill headers and properties.
            return(md);
        }
 public WsdlNS.OperationMessage GetOperationMessage(MessageDescription message)
 {
     return(this.wsdlOperationMessages[message]);
 }
示例#34
0
 public System.Web.Services.Description.MessageBinding GetMessageBinding(MessageDescription message)
 {
     return(default(System.Web.Services.Description.MessageBinding));
 }
示例#35
0
		void CreateInputBinding (ServiceEndpoint endpoint, OperationBinding op_binding,
		                         MessageDescription sm_md)
		{
			var in_binding = new InputBinding ();
			op_binding.Input = in_binding;

			var message_version = endpoint.Binding.MessageVersion ?? MessageVersion.None;
			if (message_version == MessageVersion.None)
				return;

			SoapBodyBinding soap_body_binding;
			SoapOperationBinding soap_operation_binding;
			if (message_version.Envelope == EnvelopeVersion.Soap11) {
				soap_body_binding = new SoapBodyBinding ();
				soap_operation_binding = new SoapOperationBinding ();
			} else if (message_version.Envelope == EnvelopeVersion.Soap12) {
				soap_body_binding = new Soap12BodyBinding ();
				soap_operation_binding = new Soap12OperationBinding ();
			} else {
				throw new InvalidOperationException ();
			}

			soap_body_binding.Use = SoapBindingUse.Literal;
			in_binding.Extensions.Add (soap_body_binding);
				
			//Set Action
			//<operation > <soap:operation soapAction .. >
			soap_operation_binding.SoapAction = sm_md.Action;
			soap_operation_binding.Style = SoapBindingStyle.Document;
			op_binding.Extensions.Add (soap_operation_binding);
		}
        protected override object DeserializeBody(XmlDictionaryReader reader, MessageVersion version, string action, MessageDescription messageDescription, object[] parameters, bool isRequest)
        {
            MessageInfo messageInfo;
            if (isRequest)
                messageInfo = _requestMessageInfo;
            else
                messageInfo = _replyMessageInfo;
            if (messageInfo.RpcEncodedTypedMessageBodyParts == null)
                return DeserializeBody(reader, version, messageInfo.BodySerializer, messageDescription.Body.ReturnValue, messageDescription.Body.Parts, parameters, isRequest);

            object[] bodyPartValues = new object[messageInfo.RpcEncodedTypedMessageBodyParts.Count];
            DeserializeBody(reader, version, messageInfo.BodySerializer, null/*returnPart*/, messageInfo.RpcEncodedTypedMessageBodyParts, bodyPartValues, isRequest);
            object bodyObject = Activator.CreateInstance(messageDescription.Body.Parts[0].Type);
            int i = 0;
            foreach (MessagePartDescription bodyPart in messageInfo.RpcEncodedTypedMessageBodyParts)
            {
                MemberInfo member = bodyPart.MemberInfo;
                FieldInfo field = member as FieldInfo;
                if (field != null)
                    field.SetValue(bodyObject, bodyPartValues[i++]);
                else
                {
                    PropertyInfo property = member as PropertyInfo;
                    if (property != null)
                        property.SetValue(bodyObject, bodyPartValues[i++], null);
                }
            }
            parameters[messageDescription.Body.Parts[0].Index] = bodyObject;
            return null;
        }
 public override PolicyAssertionCollection GetMessageBindingAssertions(MessageDescription message)
 {
     return(this.messageBindingAssertions[message]);
 }
        void ValidateExistingOrSetNewProtectionLevel(MessagePartDescription part, MessageDescription message, OperationDescription operation, ContractDescription contract, ProtectionLevel newProtectionLevel)
        {
            ProtectionLevel existingProtectionLevel;

            if (part != null && part.HasProtectionLevel)
            {
                existingProtectionLevel = part.ProtectionLevel;
            }
            else if (message.HasProtectionLevel)
            {
                existingProtectionLevel = message.ProtectionLevel;
            }
            else if (operation.HasProtectionLevel)
            {
                existingProtectionLevel = operation.ProtectionLevel;
            }
            else
            {
                if (part != null)
                {
                    part.ProtectionLevel = newProtectionLevel;
                }
                else
                {
                    message.ProtectionLevel = newProtectionLevel;
                }
                existingProtectionLevel = newProtectionLevel;
            }

            if (existingProtectionLevel != newProtectionLevel)
            {
                if (part != null && !part.HasProtectionLevel)
                {
                    part.ProtectionLevel = newProtectionLevel;
                }
                else if (part == null && !message.HasProtectionLevel)
                {
                    message.ProtectionLevel = newProtectionLevel;
                }
                else
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.GetString(SR.CannotImportProtectionLevelForContract, contract.Name, contract.Namespace)));
                }
            }
        }
示例#39
0
 public System.Web.Services.Description.OperationMessage GetOperationMessage(MessageDescription message)
 {
     return(default(System.Web.Services.Description.OperationMessage));
 }
示例#40
0
        /// <summary>
        /// Adds the preflight operations.
        /// </summary>
        /// <param name="endpoint">The endpoint.</param>
        /// <param name="corsOperations">The cors operations.</param>
        private void AddPreflightOperations(ServiceEndpoint endpoint, List<OperationDescription> corsOperations)
        {
            Dictionary<string, PreflightOperationBehavior> uriTemplates = new Dictionary<string, PreflightOperationBehavior>(StringComparer.OrdinalIgnoreCase);

            foreach (var operation in corsOperations)
            {
                if ((operation.Behaviors.Find<WebGetAttribute>() != null) || (operation.IsOneWay))
                {
                    continue;
                }

                string originalUriTemplate;
                WebInvokeAttribute originalWia = operation.Behaviors.Find<WebInvokeAttribute>();

                if (originalWia != null && originalWia.UriTemplate != null)
                {
                    originalUriTemplate = NormalizeTemplate(originalWia.UriTemplate);
                }
                else
                {
                    originalUriTemplate = operation.Name;
                }

                string originalMethod = originalWia != null && originalWia.Method != null ? originalWia.Method : "POST";

                if (uriTemplates.ContainsKey(originalUriTemplate))
                {
                    PreflightOperationBehavior operationBehavior = uriTemplates[originalUriTemplate];
                    operationBehavior.AddAllowedMethod(originalMethod);
                }
                else
                {
                    ContractDescription contract = operation.DeclaringContract;
                    OperationDescription preflightOperation = new OperationDescription(operation.Name + CorsConstants.PreflightSuffix, contract);
                    MessageDescription inputMessage = new MessageDescription(operation.Messages[0].Action + CorsConstants.PreflightSuffix, MessageDirection.Input);
                    inputMessage.Body.Parts.Add(new MessagePartDescription("input", contract.Namespace) { Index = 0, Type = typeof(Message) });
                    preflightOperation.Messages.Add(inputMessage);
                    MessageDescription outputMessage = new MessageDescription(operation.Messages[1].Action + CorsConstants.PreflightSuffix, MessageDirection.Output);
                    outputMessage.Body.ReturnValue = new MessagePartDescription(preflightOperation.Name + "Return", contract.Namespace) { Type = typeof(Message) };
                    preflightOperation.Messages.Add(outputMessage);

                    WebInvokeAttribute wia = new WebInvokeAttribute();
                    wia.UriTemplate = originalUriTemplate;
                    wia.Method = "OPTIONS";

                    preflightOperation.Behaviors.Add(wia);
                    preflightOperation.Behaviors.Add(new DataContractSerializerOperationBehavior(preflightOperation));
                    PreflightOperationBehavior preflightOperationBehavior = new PreflightOperationBehavior(preflightOperation);
                    preflightOperationBehavior.AddAllowedMethod(originalMethod);
                    preflightOperationBehavior.AddAllowedMethod("DELETE");
                    preflightOperation.Behaviors.Add(preflightOperationBehavior);
                    uriTemplates.Add(originalUriTemplate, preflightOperationBehavior);

                    contract.Operations.Add(preflightOperation);
                }
            }
        }
示例#41
0
 public override PolicyAssertionCollection GetMessageBindingAssertions(MessageDescription message)
 {
     throw new NotImplementedException();
 }
示例#42
0
		void CreateOutputBinding (ServiceEndpoint endpoint, OperationBinding op_binding,
		                          MessageDescription sm_md)
		{
			var out_binding = new OutputBinding ();
			op_binding.Output = out_binding;

			var message_version = endpoint.Binding.MessageVersion ?? MessageVersion.None;
			if (message_version == MessageVersion.None)
				return;

			SoapBodyBinding soap_body_binding;
			if (message_version.Envelope == EnvelopeVersion.Soap11) {
				soap_body_binding = new SoapBodyBinding ();
			} else if (message_version.Envelope == EnvelopeVersion.Soap12) {
				soap_body_binding = new Soap12BodyBinding ();
			} else {
				throw new InvalidOperationException ();
			}

			soap_body_binding.Use = SoapBindingUse.Literal;
			out_binding.Extensions.Add (soap_body_binding);
		}
示例#43
0
 GetMessageBindingAssertions(MessageDescription message);
 public override PolicyAssertionCollection GetMessageBindingAssertions(MessageDescription message)
 {
     lock (this.messageBindingAssertions)
     {
         if (!this.messageBindingAssertions.ContainsKey(message))
         {
             this.messageBindingAssertions.Add(message, new PolicyAssertionCollection());
         }
     }
     return this.messageBindingAssertions[message];
 }
示例#45
0
        void DoImportContract()
        {
            PortType            port_type = context.WsdlPortType;
            ContractDescription contract = context.Contract;
            int i, j;
            List <MessagePartDescription> parts = new List <MessagePartDescription> ();

            i = 0;
            foreach (Operation op in port_type.Operations)
            {
                OperationDescription opdescr = contract.Operations [i];
                if (IsOperationImported(port_type, op))
                {
                    continue;
                }
                if (!CanImportOperation(port_type, op))
                {
                    continue;
                }

                j = 0;
                foreach (OperationMessage opmsg in op.Messages)
                {
                    //SM.MessageDescription
                    MessageDescription msgdescr = opdescr.Messages [j];

                    //OpMsg's corresponding WSMessage
                    Message msg = port_type.ServiceDescription.Messages [opmsg.Message.Name];

                    msgdescr.Body.WrapperNamespace = port_type.ServiceDescription.TargetNamespace;

                    if (opmsg is OperationOutput)
                    {
                        //ReturnValue
                        msg = port_type.ServiceDescription.Messages [opmsg.Message.Name];

                        resolveMessage(msg, msgdescr.Body, parts);
                        if (parts.Count > 0)
                        {
                            msgdescr.Body.ReturnValue = parts [0];
                            parts.Clear();
                        }
                        continue;
                    }

                    /* OperationInput */

                    /* Parts, MessagePartDescription */
                    resolveMessage(msg, msgdescr.Body, parts);
                    foreach (MessagePartDescription p in parts)
                    {
                        msgdescr.Body.Parts.Add(p);
                    }
                    parts.Clear();

                    j++;
                }

                OnOperationImported(opdescr);


                i++;
            }
        }