/// <summary>
        /// Initializes a new instance of <see cref="HttpParmeterDescription"/> class.
        /// </summary>
        /// <remarks>
        /// This form of the constructor creates an instance based on an existing
        /// <see cref="MessagePartDescription"/> instance.  To create such an instance, use the extension method
        /// <see cref="HttpParmeterDescriptionsExtensionMethods.ToHttpParameterDescription"/>.
        /// </remarks>
        /// <param name="messagePartDescription">The existing <see cref="MessagePartDescription"/>.</param>
        internal HttpParameterDescription(MessagePartDescription messagePartDescription)
        {
            if (messagePartDescription == null)
            {
                throw new ArgumentNullException("messagePartDescription");
            }

            this.messagePartDescription = messagePartDescription;
        }
 // Methods
 internal MessagePartDescription(MessagePartDescription other)
 {
     this.name = other.name;
     this.ns = other.ns;
     this.index = other.index;
     this.type = other.type;
     this.serializationPosition = other.serializationPosition;
     this.hasProtectionLevel = other.hasProtectionLevel;
     this.protectionLevel = other.protectionLevel;
     this.memberInfo = other.memberInfo;
     this.multiple = other.multiple;
     this.additionalAttributesProvider = other.additionalAttributesProvider;
     this.baseType = other.baseType;
     this.uniquePartName = other.uniquePartName;
 }
Exemplo n.º 3
0
        private static bool IsTypeSupported(MessagePartDescription bodyDescription)
        {
            Fx.Assert(bodyDescription != null, "");
            Type type = bodyDescription.Type;

            if (type == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.SFxMessagePartDescriptionMissingType, bodyDescription.Name, bodyDescription.Namespace)));
            }

            if (bodyDescription.Multiple)
            {
                return(false);
            }

            if (type == typeof(void))
            {
                return(true);
            }
            if (type.IsEnum())
            {
                return(false);
            }
            switch (type.GetTypeCode())
            {
            case TypeCode.Boolean:
            case TypeCode.DateTime:
            case TypeCode.Decimal:
            case TypeCode.Double:
            case TypeCode.Int32:
            case TypeCode.Int64:
            case TypeCode.Single:
            case TypeCode.String:
                return(true);

            case TypeCode.Object:
                if (type.IsArray && type.GetArrayRank() == 1 && IsArrayTypeSupported(type.GetElementType()))
                {
                    return(true);
                }
                break;

            default:
                break;
            }
            return(false);
        }
Exemplo n.º 4
0
        public static OuterCommand DecodeCommandInit(Int32 identity, IList <Byte[]> message)
        {
            Int32 index = 0;

            var command = new OuterCommand
            {
                Messenger   = message[index++][0],
                CommandId   = BitConverter.ToInt32(message[index++], 0),
                Name        = Encoding.ASCII.GetString(message[index++]),
                Description = Encoding.ASCII.GetString(message[index++]),
                Usage       = (CommandUsage)message[index++][0],
                Node        = identity,
            };
            var msgDesc = GetPart();

            if (msgDesc is null)
            {
                index++;
            }
            var replDesc = GetPart();

            command.ReplyDescription   = replDesc;
            command.RequestDescription = msgDesc;

            return(command);

            List <MessagePartDescription> GetPart()
            {
                Byte[] name;
                MessagePartDescription msgPart;

                var part = new Lazy <List <MessagePartDescription> >();

                while (message.Count > index && (name = message[index++]).Length != 0)
                {
                    msgPart = new MessagePartDescription
                    {
                        Name = Encoding.ASCII.GetString(name),
                        Type = (MessageValueType)message[index++][0]
                    };

                    part.Value.Add(msgPart);
                }

                return(part.IsValueCreated ? part.Value : null);
            }
        }
Exemplo n.º 5
0
        public void Parts()
        {
            ContractDescription cd =
                ContractDescription.GetContract(typeof(IFoo3));

            MessagePartDescriptionCollection parts =
                cd.Operations [0].Messages [0].Body.Parts;

            Assert.AreEqual(1, parts.Count, "#1");
            MessagePartDescription part = parts [0];

            Assert.AreEqual("intValue", part.Name, "#2");
            Assert.AreEqual("http://tempuri.org/", part.Namespace, "#3");
            Assert.AreEqual(typeof(int), part.Type, "#4");
            Assert.AreEqual(0, part.Index, "#5");
            Assert.AreEqual(false, part.Multiple, "#5");
        }
Exemplo n.º 6
0
        public void PartsNamespace()
        {
            ContractDescription cd =
                ContractDescription.GetContract(typeof(IFoo4));

            MessagePartDescriptionCollection parts =
                cd.Operations [0].Messages [0].Body.Parts;

            Assert.AreEqual(1, parts.Count, "#1");
            MessagePartDescription part = parts [0];

            Assert.AreEqual("intValue", part.Name, "#2");
            Assert.AreEqual("http://MonoTests.System.ServiceModel.Description", part.Namespace, "#3");
            Assert.AreEqual(typeof(int), part.Type, "#4");
            Assert.AreEqual(0, part.Index, "#5");
            Assert.AreEqual(false, part.Multiple, "#5");
        }
Exemplo n.º 7
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 PartInfo AddToDictionary(XmlDictionary dictionary, MessagePartDescription part, bool isRpc)
 {
     Type type = part.Type;
     XmlDictionaryString itemName = null;
     XmlDictionaryString itemNamespace = null;
     if (type.IsArray && type != typeof(byte[]))
     {
         const string ns = "http://schemas.microsoft.com/2003/10/Serialization/Arrays";
         string name = GetArrayItemName(type.GetElementType());
         itemName = AddToDictionary(dictionary, name);
         itemNamespace = AddToDictionary(dictionary, ns);
     }
     return new PartInfo(part,
         AddToDictionary(dictionary, part.Name),
         AddToDictionary(dictionary, isRpc ? string.Empty : part.Namespace),
         itemName, itemNamespace);
 }
 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;
 }
Exemplo n.º 10
0
        protected override object [] MessageToParts(
            MessageDescription md, Message message)
        {
            if (message.IsEmpty)
            {
                return(null);
            }

            int offset = ParamsOffset(md.Body);

            object [] parts = CreatePartsArray(md.Body);

            XmlDictionaryReader r = message.GetReaderAtBodyContents();

            if (md.Body.WrapperName != null)
            {
                r.ReadStartElement(md.Body.WrapperName, md.Body.WrapperNamespace);
            }

            for (r.MoveToContent(); r.NodeType == XmlNodeType.Element; r.MoveToContent())
            {
                XmlQualifiedName       key = new XmlQualifiedName(r.LocalName, r.NamespaceURI);
                MessagePartDescription rv  = md.Body.ReturnValue;
                if (rv != null && rv.Name == key.Name && rv.Namespace == key.Namespace && rv.Type != typeof(void))
                {
                    parts [0] = ReadMessagePart(md.Body.ReturnValue, r);
                }
                else if (md.Body.Parts.Contains(key))
                {
                    MessagePartDescription p = md.Body.Parts [key];
                    parts [p.Index + offset] = ReadMessagePart(p, r);
                }
                else                 // Skip unknown elements
                {
                    r.Skip();
                }
            }

            if (md.Body.WrapperName != null && !r.EOF)
            {
                r.ReadEndElement();
            }

            return(parts);
        }
Exemplo n.º 11
0
        public void HttpOperationDescription_Update_OutputParameters_From_HttpOperationDescription()
        {
            OperationDescription   od  = GetOperationDescription(typeof(MockService2), "OneInOneOutReturnsString");
            MessagePartDescription mpd = od.Messages[1].Body.Parts[0];  // output parameter 1 in the MPD

            Assert.AreEqual(typeof(double), mpd.Type, "MPD out parameter 1 has wrong type");

            // Get a synchronized HOD.
            HttpOperationDescription hod = od.ToHttpOperationDescription();

            Assert.IsNotNull(hod, "Failed to create HttpOperationDescription");

            // Get a synchronized HPDCollection and from it a synchronized HPD
            HttpParameterDescriptionCollection hpdColl = hod.OutputParameters;
            HttpParameterDescription           hpd     = hpdColl[0];

            Assert.IsNotNull(hpd, "Input parameter was null");
            Assert.AreEqual(typeof(double), hpd.ParameterType, "HPD out parameter 1 has wrong type");

            // Negative test -- Name and Namespace are immutable when synchronized
            ExceptionAssert.Throws(
                typeof(NotSupportedException),
                "Setting Name should throw when synchronized",
                () => hpd.Name = "Rename"
                );

            ExceptionAssert.Throws(
                typeof(NotSupportedException),
                "Setting Name should throw when synchronized",
                () => hpd.Name = "Rename"
                );

            // Update return value directly in HOD's parameter description
            hpd.ParameterType = typeof(int);
            hpd.Index         = 5;

            // This should have directly updated it in the MPD as well
            Assert.AreEqual(typeof(int), mpd.Type, "HPD failed to update ParameterType in MPD");
            Assert.AreEqual(5, mpd.Index, "HPD failed to update Index in MPD");

            // Final test -- and that should have updated it in the OD.
            // This is technically the same test as above, but this proves it.
            Assert.AreEqual(typeof(int), od.Messages[1].Body.Parts[0].Type, "HPD failed to update ParameterType in MPD");
            Assert.AreEqual(5, od.Messages[1].Body.Parts[0].Index, "HPD failed to update Index in MPD");
        }
Exemplo n.º 12
0
        private 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(string.Format(SRServiceModel.CannotImportProtectionLevelForContract, contract.Name, contract.Namespace)));
                }
            }
        }
Exemplo n.º 13
0
 public PartInfo(MessagePartDescription description, XmlDictionaryString dictionaryName, XmlDictionaryString dictionaryNamespace, XmlDictionaryString itemName, XmlDictionaryString itemNamespace)
 {
     this.dictionaryName      = dictionaryName;
     this.dictionaryNamespace = dictionaryNamespace;
     this.itemName            = itemName;
     this.itemNamespace       = itemNamespace;
     this.description         = description;
     if (description.Type.IsArray)
     {
         this.isArray  = true;
         this.typeCode = Type.GetTypeCode(description.Type.GetElementType());
     }
     else
     {
         this.isArray  = false;
         this.typeCode = Type.GetTypeCode(description.Type);
     }
 }
Exemplo n.º 14
0
    private static void ValidatePartDescriptionCollection(string action, string section, StringBuilder errorBuilder, MessagePartDescription[] desc, PartDescriptionData[] data)
    {
        if (data != null)
        {
            if (desc.Length != data.Length)
            {
                errorBuilder.AppendLine(String.Format("action {0}, section {1}, expected part count = {2}, actual = {3}",
                                                      action, section, data.Length, desc.Length));
            }

            // MessagePartDescriptions are keyed collections, so their order is unpredictable
            foreach (PartDescriptionData dataPart in data)
            {
                MessagePartDescription descPart = desc.SingleOrDefault((d) => String.Equals(dataPart.Name, d.Name));
                ValidatePartDescription(action, section, errorBuilder, descPart, dataPart);
            }
        }
    }
Exemplo n.º 15
0
 public PartInfo(MessagePartDescription description, XmlDictionaryString dictionaryName, XmlDictionaryString dictionaryNamespace, XmlDictionaryString itemName, XmlDictionaryString itemNamespace)
 {
     _dictionaryName      = dictionaryName;
     _dictionaryNamespace = dictionaryNamespace;
     _itemName            = itemName;
     _itemNamespace       = itemNamespace;
     _description         = description;
     if (description.Type.IsArray)
     {
         _isArray  = true;
         _typeCode = description.Type.GetElementType().GetTypeCode();
     }
     else
     {
         _isArray  = false;
         _typeCode = description.Type.GetTypeCode();
     }
 }
Exemplo n.º 16
0
        static (Byte[][] msg, MessagePartDescription[] description) CreateTestMessage(Int32 length, Boolean name)
        {
            if (length % 4 != 0)
            {
                throw new ArgumentException();
            }
            Contract.EndContractBlock();

            var msg  = new Byte[length][];
            var desc = new MessagePartDescription[length];

            for (Int32 i = 0; i < length; i += 4)
            {
                msg[i]  = BitConverter.GetBytes(333);
                desc[i] = new MessagePartDescription {
                    Name = (name) ? RandomString(15) : i.ToString(), Type = MessageValueType.Int32
                };

                msg[i + 1]  = Encoding.ASCII.GetBytes("Make love, not war");
                desc[i + 1] = new MessagePartDescription {
                    Name = (name) ? RandomString(15) : (i + 1).ToString(), Type = MessageValueType.String
                };

                msg[i + 2]  = BitConverter.GetBytes(7.77);
                desc[i + 2] = new MessagePartDescription {
                    Name = (name) ? RandomString(15) : (i + 2).ToString(), Type = MessageValueType.Double
                };

                msg[i + 3]  = Encoding.ASCII.GetBytes("e");
                desc[i + 3] = new MessagePartDescription {
                    Name = (name) ? RandomString(15) : (i + 3).ToString(), Type = MessageValueType.String
                };
            }

            return(msg, desc);

            String RandomString(Int32 len)
            {
                const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

                return(new string(Enumerable.Repeat(chars, length)
                                  .Select(s => s[rand.Next(s.Length)]).ToArray()));
            }
        }
        private void ValidateExistingOrSetNewProtectionLevel(MessagePartDescription part, MessageDescription message, OperationDescription operation, ContractDescription contract, ProtectionLevel newProtectionLevel)
        {
            ProtectionLevel protectionLevel;

            if ((part != null) && part.HasProtectionLevel)
            {
                protectionLevel = part.ProtectionLevel;
            }
            else if (message.HasProtectionLevel)
            {
                protectionLevel = message.ProtectionLevel;
            }
            else if (operation.HasProtectionLevel)
            {
                protectionLevel = operation.ProtectionLevel;
            }
            else
            {
                if (part != null)
                {
                    part.ProtectionLevel = newProtectionLevel;
                }
                else
                {
                    message.ProtectionLevel = newProtectionLevel;
                }
                protectionLevel = newProtectionLevel;
            }
            if (protectionLevel != newProtectionLevel)
            {
                if ((part != null) && !part.HasProtectionLevel)
                {
                    part.ProtectionLevel = newProtectionLevel;
                }
                else
                {
                    if ((part != null) || message.HasProtectionLevel)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(System.ServiceModel.SR.GetString("CannotImportProtectionLevelForContract", new object[] { contract.Name, contract.Namespace })));
                    }
                    message.ProtectionLevel = newProtectionLevel;
                }
            }
        }
Exemplo n.º 18
0
        public static MessengerInfo DecodeMessengerInitMsg(IList <Byte[]> message)
        {
            var msgrInfo = new MessengerInfo
            {
                Type       = (MessengerType)message[NodeInfoIndex][NodeTypeIndex],
                Device     = (DeviceType)message[NodeInfoIndex][DeviceTypeIndex],
                Protocol   = (TransportProtocol)message[NodeInfoIndex][TransportProtocolIndex],
                Name       = Encoding.ASCII.GetString(message[NodeNameIndex]),
                DeviceName = Encoding.ASCII.GetString(message[DeviceNameIndex]),
                Id         = message[MessengerIdIndex][0]
            };

            if (msgrInfo.Type == MessengerType.Raw || msgrInfo.Type == MessengerType.None)
            {
                return(msgrInfo);
            }

            Int32 sectionsNumber = (Int32)msgrInfo.Type;
            var   parts          = new List <MessagePartDescription> [sectionsNumber];

            Byte[] name;
            MessagePartDescription msgPart;
            Int32 j = TypesDescriptionIndex;

            for (Int32 i = 0; i < sectionsNumber; i++)
            {
                parts[i] = new List <MessagePartDescription>();

                while (j < message.Count && (name = message[j]).Length != 0)
                {
                    msgPart = new MessagePartDescription
                    {
                        Name = Encoding.ASCII.GetString(name),
                        Type = (MessageValueType)message[j + 1][0]
                    };

                    j += 2;
                    parts[i].Add(msgPart);
                }
                j++;
            }
            msgrInfo.MessageDescriptions = parts;
            return(msgrInfo);
        }
Exemplo n.º 19
0
        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);
            }
        }
Exemplo n.º 20
0
        public void HttpOperationDescription_Update_ReturnValue_From_HttpOperationDescription()
        {
            OperationDescription   od  = GetOperationDescription(typeof(MockService2), "GetAStringFromInt");
            MessagePartDescription mpd = od.Messages[1].Body.ReturnValue;

            // Get a synchronized HOD.
            HttpOperationDescription hod = od.ToHttpOperationDescription();

            Assert.IsNotNull(hod, "Failed to create HttpOperationDescription");

            // Get a synchronized HPD
            HttpParameterDescription hpd = hod.ReturnValue;

            Assert.IsNotNull(hpd, "Return parameter was null");
            Assert.AreEqual(typeof(string), hpd.ParameterType, "Return parameter type should have been string");

            // Negative test -- Name and Namespace are immutable when synchronized
            ExceptionAssert.Throws(
                typeof(NotSupportedException),
                "Setting Name should throw when synchronized",
                () => hpd.Name = "Rename"
                );

            ExceptionAssert.Throws(
                typeof(NotSupportedException),
                "Setting Name should throw when synchronized",
                () => hpd.Name = "Rename"
                );

            // Update return value directly in HOD's parameter description
            hpd.ParameterType = typeof(double);
            hpd.Index         = 5;

            // This should have directly updated it in the MPD as well
            Assert.AreEqual(typeof(double), mpd.Type, "HPD failed to update ParameterType in MPD");
            Assert.AreEqual(5, mpd.Index, "HPD failed to update Index in MPD");

            // Final test -- and that should have updated it in the OD.
            // This is technically the same test as above, but this proves it.
            Assert.AreEqual(typeof(double), od.Messages[1].Body.ReturnValue.Type, "HPD failed to update ParameterType in MPD");
            Assert.AreEqual(5, od.Messages[1].Body.ReturnValue.Index, "HPD failed to update Index in MPD");
        }
Exemplo n.º 21
0
 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);
     }
 }
Exemplo n.º 22
0
        public void HttpOperationDescription_Update_ReturnValue_From_Incomplete_HttpOperationDescription()
        {
            OperationDescription     od  = GetOperationDescription(typeof(SimpleOperationsService), "OneInputAndReturnValue");
            MessagePartDescription   mpd = od.Messages[1].Body.ReturnValue;
            HttpOperationDescription hod = od.ToHttpOperationDescription();
            HttpParameter            hpd = hod.ReturnValue;

            // Clear out all of Messages[]
            od.Messages.Clear();

            Assert.IsNull(hod.ReturnValue, "ReturnValue should be null with no backing Messages[1]");

            // Setting a valid ReturnValue should auto-create Messages[1]
            hod.ReturnValue = hpd;

            Assert.IsNotNull(hod.ReturnValue, "ReturnValue was not set");
            Assert.AreSame(hpd.MessagePartDescription, hod.ReturnValue.MessagePartDescription, "ReturnValue not as expected");

            Assert.AreEqual(2, od.Messages.Count, "Setting ReturnValue should have created Messages[1]");
        }
Exemplo n.º 23
0
        private void FillParametersInfo(OperationDescription opDesp, object[] parameters)
        {
            this._Name = opDesp.Name;

            for (int i = 0; i < opDesp.Messages[0].Body.Parts.Count; i++)
            {
                string paramName = opDesp.Messages[0].Body.Parts[i].Name;
                object paramVal  = parameters[i];

                MessagePartDescription mp = opDesp.Messages[0].Body.Parts[i];

                WfClientParameter parameter = new WfClientParameter()
                {
                    Name  = mp.Name,
                    Type  = mp.Type,
                    Value = parameters[i]
                };

                this.Parameters.Add(parameter);
            }
        }
Exemplo n.º 24
0
        public void HttpOperationDescription_Delete_OutputParameters_From_HttpOperationDescription()
        {
            OperationDescription   od  = GetOperationDescription(typeof(MockService2), "OneInOneOutReturnsString");
            MessagePartDescription mpd = od.Messages[1].Body.Parts[0];  // input parameter 1 in the MPD

            // Get a synchronized HOD.
            HttpOperationDescription hod = od.ToHttpOperationDescription();

            Assert.IsNotNull(hod, "Failed to create HttpOperationDescription");

            // Get a synchronized HPDCollection and from it a synchronized HPD
            HttpParameterDescriptionCollection hpdColl = hod.OutputParameters;

            Assert.AreEqual(1, hpdColl.Count, "Expected HPD collection to have one output param");

            // Delete it from our collection
            hpdColl.RemoveAt(0);

            // Verify the backing OD has seen that change
            Assert.AreEqual(0, od.Messages[1].Body.Parts.Count, "Expected delete of HPD input parameter to delete it from OD");
        }
Exemplo n.º 25
0
        public void HttpOperationDescription_Update_InputParameters_From_Incomplete_HttpOperationDescription()
        {
            OperationDescription     od      = GetOperationDescription(typeof(SimpleOperationsService), "OneInputAndReturnValue");
            MessagePartDescription   mpd     = od.Messages[0].Body.Parts[0]; // input parameter 1 in the MPD
            HttpOperationDescription hod     = od.ToHttpOperationDescription();
            IList <HttpParameter>    hpdColl = hod.InputParameters;
            HttpParameter            hpd     = hpdColl[0];

            // Zap the Messages[]
            od.Messages.Clear();

            // Zapping the backing Messages should have rendered the input collection empty
            Assert.AreEqual(0, hpdColl.Count, "Resetting Messages did not reset count");
            Assert.AreEqual(0, hod.InputParameters.Count, "Resetting Messages did not reset count in HOD");

            // Mutating the InputParameter collection should auto-create the Messages
            hpdColl.Add(hpd);

            Assert.AreEqual(1, od.Messages.Count, "Messages[0] was not autocreated");
            Assert.AreEqual(1, hpdColl.Count, "Creating Messages did not set count");
            Assert.AreEqual(1, hod.InputParameters.Count, "Creating Messages did not set count in HOD");
        }
Exemplo n.º 26
0
        public void HttpOperationDescription_Update_ReturnValue_Throws_From_Unsynchronized()
        {
            OperationDescription   od  = GetOperationDescription(typeof(MockService2), "GetAStringFromInt");
            MessagePartDescription mpd = od.Messages[1].Body.ReturnValue;

            // Get a synchronized HOD.
            HttpOperationDescription hod = od.ToHttpOperationDescription();

            Assert.IsNotNull(hod, "Failed to create HttpOperationDescription");

            // Get an unsynchronized HPD
            HttpParameterDescription unsynchedHpd = new HttpParameterDescription()
            {
                Name          = "TheReturn",
                ParameterType = typeof(int)
            };

            ExceptionAssert.ThrowsInvalidOperation(
                "Expect InvalidOperation to throw when trying to set unsynchronized return",
                () => hod.ReturnValue = unsynchedHpd
                );

            // Get a synchronized HPD
            HttpParameterDescription hpd = hod.ReturnValue;

            Assert.IsNotNull(hpd, "Return parameter was null");
            Assert.AreEqual(typeof(string), hpd.ParameterType, "Return parameter type should have been string");

            // Null set should succeed
            hod.ReturnValue = null;
            Assert.IsNull(hod.ReturnValue, "Could not set to null");

            // Null should propagate
            Assert.IsNull(od.Messages[1].Body.ReturnValue, "Null did not propagate");

            // Set back to valid value and see if propagates
            hod.ReturnValue = hpd;
            Assert.AreEqual(mpd, od.Messages[1].Body.ReturnValue, "Did not reset to synced value");
        }
Exemplo n.º 27
0
        public void HttpOperationDescription_Update_OutputParameters_From_Incomplete_HttpOperationDescription()
        {
            OperationDescription               od      = GetOperationDescription(typeof(MockService2), "OneInOneOutReturnsString");
            MessagePartDescription             mpd     = od.Messages[1].Body.Parts[0]; // output parameter 1 in the MPD
            HttpOperationDescription           hod     = od.ToHttpOperationDescription();
            HttpParameterDescriptionCollection hpdColl = hod.OutputParameters;
            HttpParameterDescription           hpd     = hpdColl[0];

            // Zap the Messages[]
            od.Messages.Clear();

            // Zapping the backing Messages should have rendered the input collection empty
            Assert.AreEqual(0, hpdColl.Count, "Resetting Messages did not reset count");
            Assert.AreEqual(0, hod.InputParameters.Count, "Resetting Messages did not reset count in HOD");

            // Mutating the OutputParameter collection should auto-create the both in and out Messages
            hpdColl.Add(hpd);

            Assert.AreEqual(2, od.Messages.Count, "Messages[1] was not autocreated");
            Assert.AreEqual(1, hpdColl.Count, "Creating Messages did not set count");
            Assert.AreEqual(1, hod.OutputParameters.Count, "Creating Messages did not set count in HOD");
        }
Exemplo n.º 28
0
        private static bool IsTypeSupported(MessagePartDescription bodyDescription)
        {
            System.Type type = bodyDescription.Type;
            if (type == null)
            {
                throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("SFxMessagePartDescriptionMissingType", new object[] { bodyDescription.Name, bodyDescription.Namespace })));
            }
            if (!bodyDescription.Multiple)
            {
                if (type == typeof(void))
                {
                    return(true);
                }
                if (type.IsEnum)
                {
                    return(false);
                }
                switch (System.Type.GetTypeCode(type))
                {
                case TypeCode.Object:
                    if ((!type.IsArray || (type.GetArrayRank() != 1)) || !IsArrayTypeSupported(type.GetElementType()))
                    {
                        break;
                    }
                    return(true);

                case TypeCode.Boolean:
                case TypeCode.Int32:
                case TypeCode.Int64:
                case TypeCode.Single:
                case TypeCode.Double:
                case TypeCode.Decimal:
                case TypeCode.DateTime:
                case TypeCode.String:
                    return(true);
                }
            }
            return(false);
        }
        private static MessagePartDescription ValidateAndGetStreamPart(MessageDescription messageDescription, bool isRequest, string operationName)
        {
            MessagePartDescription streamPart = GetStreamPart(messageDescription);

            if (streamPart != null)
            {
                return(streamPart);
            }
            if (!HasStream(messageDescription))
            {
                return(null);
            }
            if (messageDescription.IsTypedMessage)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("SFxInvalidStreamInTypedMessage", new object[] { messageDescription.MessageName })));
            }
            if (isRequest)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("SFxInvalidStreamInRequest", new object[] { operationName })));
            }
            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("SFxInvalidStreamInResponse", new object[] { operationName })));
        }
Exemplo n.º 30
0
        XmlObjectSerializer GetSerializer(MessagePartDescription partDesc)
        {
            if (!serializers.ContainsKey(partDesc))
#if !MOBILE
            { if (serializerBehavior != null)
              {
                  serializers [partDesc] = serializerBehavior.CreateSerializer(
                      partDesc.Type, partDesc.Name, partDesc.Namespace, OperationKnownTypes as IList <Type>);
              }
              else
#endif
            { serializers [partDesc] = new DataContractSerializer(
                  partDesc.Type, partDesc.Name, partDesc.Namespace, OperationKnownTypes); }
            return(serializers [partDesc]);
        }

        object ReadHeaderObject(Type type, XmlObjectSerializer serializer, XmlDictionaryReader reader)
        {
            // FIXME: it's a nasty workaround just to avoid UniqueId output as a string.
            // Seealso MessageHeader.DefaultMessageHeader.OnWriteHeaderContents().
            // Note that msg.Headers.GetHeader<UniqueId> () simply fails (on .NET too) and it is useless. The API is lame by design.
            if (type == typeof(UniqueId))
                return(new UniqueId(reader.ReadElementContentAsString())); }
Exemplo n.º 31
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());
        }
Exemplo n.º 32
0
        private OperationDescription CreateOperationDescription(ContractDescription contract, Type serviceType, MethodInfo method)
        {
            OperationDescription result = new OperationDescription(method.Name, contract);

            result.SyncMethod = method;

            MessageDescription inputMessage = new MessageDescription(DefaultNamespace + serviceType.Name + "/" + method.Name, MessageDirection.Input);

            inputMessage.Body.WrapperNamespace = DefaultNamespace;
            inputMessage.Body.WrapperName      = method.Name;
            ParameterInfo[] parameters = method.GetParameters();
            for (int i = 0; i < parameters.Length; i++)
            {
                ParameterInfo          parameter = parameters[i];
                MessagePartDescription part      = new MessagePartDescription(parameter.Name, DefaultNamespace);
                part.Type  = parameter.ParameterType;
                part.Index = i;
                inputMessage.Body.Parts.Add(part);
            }

            result.Messages.Add(inputMessage);

            MessageDescription outputMessage = new MessageDescription(DefaultNamespace + serviceType.Name + "/" + method.Name + "Response", MessageDirection.Output);

            outputMessage.Body.WrapperName      = method.Name + "Response";
            outputMessage.Body.WrapperNamespace = DefaultNamespace;
            outputMessage.Body.ReturnValue      = new MessagePartDescription(method.Name + "Result", DefaultNamespace);
            outputMessage.Body.ReturnValue.Type = method.ReturnType;
            result.Messages.Add(outputMessage);

            result.Behaviors.Add(new OperationInvoker(method));
            result.Behaviors.Add(new OperationBehaviorAttribute());
            result.Behaviors.Add(new DataContractSerializerOperationBehavior(result));

            return(result);
        }
 public int Compare(MessagePartDescription p1, MessagePartDescription p2)
 {
     if (p1 == null)
     {
         if (p2 != null)
         {
             return -1;
         }
         return 0;
     }
     if (p2 == null)
     {
         return 1;
     }
     int num = string.CompareOrdinal(p1.Namespace, p2.Namespace);
     if (num == 0)
     {
         num = string.CompareOrdinal(p1.Name, p2.Name);
     }
     return num;
 }