Ejemplo n.º 1
0
        public static MessageDescription CreateMessageDescription(
            Type messageType, string defaultNamespace, string action, bool isRequest, MessageContractAttribute mca)
        {
            MessageDescription md = new MessageDescription(
                action, isRequest ? MessageDirection.Input :
                MessageDirection.Output);

            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;
                }

                MessageBodyMemberAttribute mba = GetMessageBodyMemberAttribute(bmi);
                if (mba == null)
                {
                    continue;
                }

                MessagePartDescription pd = CreatePartCore(mba, mname, defaultNamespace);
                pd.Index      = index++;
                pd.Type       = MessageFilterOutByRef(mtype);
                pd.MemberInfo = bmi;
                mb.Parts.Add(pd);
            }

            // FIXME: fill headers and properties.
            return(md);
        }
Ejemplo n.º 2
0
        public static MessageDescription CreateMessageDescription(
            OperationContractAttribute oca, ParameterInfo[] plist, string name, string defaultNamespace, string action, bool isRequest, Type retType, ICustomAttributeProvider retTypeAttributes)
        {
            MessageDescription md = new MessageDescription(
                action, isRequest ? MessageDirection.Input :
                MessageDirection.Output);

            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);
        }
        public static MessageDescription CreateMessageDescription(
            OperationContractAttribute oca, ParameterInfo[] plist, string name, string defaultNamespace, string action, bool isRequest, bool isCallback, Type retType)
        {
            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)
                {
                    if (isRequest && pi.Position == plist.Length - 2)
                    {
                        break;
                    }
                    if (!isRequest && pi.Position == plist.Length - 1)
                    {
                        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);
            }

            return(md);
        }
Ejemplo n.º 4
0
 internal MessageBodyDescription(MessageBodyDescription other)
 {
     this.WrapperName      = other.WrapperName;
     this.WrapperNamespace = other.WrapperNamespace;
     _parts = new MessagePartDescriptionCollection();
     foreach (MessagePartDescription mpd in other.Parts)
     {
         this.Parts.Add(mpd.Clone());
     }
     if (other.ReturnValue != null)
     {
         this.ReturnValue = other.ReturnValue.Clone();
     }
 }
 internal MessageBodyDescription(MessageBodyDescription other)
 {
     this.WrapperName = other.WrapperName;
     this.WrapperNamespace = other.WrapperNamespace;
     this.parts = new MessagePartDescriptionCollection();
     foreach (MessagePartDescription mpd in other.Parts)
     {
         this.Parts.Add(mpd.Clone());
     }
     if (other.ReturnValue != null)
     {
         this.ReturnValue = other.ReturnValue.Clone();
     }
 }
		void resolveMessage (Message msg, MessageBodyDescription body, List<MessagePartDescription> parts)
		{
			foreach (MessagePart part in msg.Parts) {
				if (part.Name == "parameters") {
					if (!part.Element.IsEmpty) {
						body.WrapperName = part.Element.Name;
						ImportPartsBySchemaElement (part.Element, parts, body.WrapperNamespace);
					} else {
						body.WrapperName = part.Type.Name;
						resolveType (part.Type, parts, body.WrapperNamespace);
					}
				}
				//FIXME: non-parameters?
			}
		}
Ejemplo n.º 7
0
        // Assumption: gets called exactly once per operation
        void IOperationContractGenerationExtension.GenerateOperation(OperationContractGenerationContext context)
        {
            if (context == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
            }
            if (partInfoTable != null && partInfoTable.Count > 0)
            {
                Dictionary <XmlMembersMapping, XmlMembersMapping> alreadyExported = new Dictionary <XmlMembersMapping, XmlMembersMapping>();
                foreach (MessageDescription message in context.Operation.Messages)
                {
                    foreach (MessageHeaderDescription header in message.Headers)
                    {
                        GeneratePartType(alreadyExported, header, header.Namespace);
                    }


                    MessageBodyDescription body = message.Body;
                    bool isWrapped = (body.WrapperName != null);
                    if (OperationFormatter.IsValidReturnValue(body.ReturnValue))
                    {
                        GeneratePartType(alreadyExported, body.ReturnValue, isWrapped ? body.WrapperNamespace : body.ReturnValue.Namespace);
                    }

                    foreach (MessagePartDescription part in body.Parts)
                    {
                        GeneratePartType(alreadyExported, part, isWrapped ? body.WrapperNamespace : part.Namespace);
                    }
                }
            }
            XmlSerializerOperationBehavior xmlSerializerOperationBehavior = context.Operation.Behaviors.Find <XmlSerializerOperationBehavior>() as XmlSerializerOperationBehavior;

            if (xmlSerializerOperationBehavior == null)
            {
                return;
            }

            XmlSerializerFormatAttribute xmlSerializerFormatAttribute = (xmlSerializerOperationBehavior == null) ? new XmlSerializerFormatAttribute() : xmlSerializerOperationBehavior.XmlSerializerFormatAttribute;
            OperationFormatStyle         style = xmlSerializerFormatAttribute.Style;

            operationGenerator.GenerateOperation(context, ref style, xmlSerializerFormatAttribute.IsEncoded, new WrappedBodyTypeGenerator(context), new Dictionary <MessagePartDescription, ICollection <CodeTypeReference> >());
            context.ServiceContractGenerator.AddReferencedAssembly(typeof(System.Xml.Serialization.XmlTypeAttribute).Assembly);
            xmlSerializerFormatAttribute.Style = style;
            context.SyncMethod.CustomAttributes.Add(OperationGenerator.GenerateAttributeDeclaration(context.Contract.ServiceContractGenerator, xmlSerializerFormatAttribute));
            AddKnownTypes(context.SyncMethod.CustomAttributes, xmlSerializerFormatAttribute.IsEncoded ? SoapExporter.IncludeMetadata : XmlExporter.IncludeMetadata);
            DataContractSerializerOperationGenerator.UpdateTargetCompileUnit(context, this.options.CodeCompileUnit);
        }
Ejemplo n.º 8
0
        MessagePart ExportMessageBodyDescription(MessageBodyDescription msgbody, string name, string ns)
        {
            MessagePart msgpart   = new MessagePart();
            string      part_name = IsTypeMessage(msgbody);

            if (part_name != null)
            {
                msgpart.Name = part_name;
                msgpart.Type = ExportTypeMessage();                  //FIXME: Cache this
            }
            else
            {
                msgpart.Name    = "parameters";
                msgpart.Element = ExportParameters(msgbody, name, ns);
            }
            return(msgpart);
        }
Ejemplo n.º 9
0
        /* Sets the @name if the param or return type is SMMessage */
        string IsTypeMessage(MessageBodyDescription msgbody)
        {
            MessagePartDescription part = null;

            if (msgbody.Parts.Count == 0)
            {
                part = msgbody.ReturnValue;
            }
            else if (msgbody.Parts.Count == 1)
            {
                part = msgbody.Parts [0];
            }

            if (part != null && (part.Type.FullName == typeof(SMMessage).FullName))
            {
                return(part.Name);
            }

            return(null);
        }
Ejemplo n.º 10
0
 void resolveMessage(Message msg, MessageBodyDescription body, List <MessagePartDescription> parts)
 {
     foreach (MessagePart part in msg.Parts)
     {
         if (part.Name == "parameters")
         {
             if (!part.Element.IsEmpty)
             {
                 body.WrapperName = part.Element.Name;
                 ImportPartsBySchemaElement(part.Element, parts, msg, part);
             }
             else
             {
                 body.WrapperName = part.Type.Name;
                 ResolveType(part.Type, parts, body.WrapperNamespace);
             }
         }
         else
         {
             throw new InvalidOperationException("Only 'parameters' element in message part is supported");                      // this should have been rejected by CanImportOperation().
         }
     }
 }
Ejemplo n.º 11
0
		protected static int ParamsOffset (MessageBodyDescription desc)
		{
			return HasReturnValue (desc) ? 1 : 0;
		}
		void resolveMessage (Message msg, MessageBodyDescription body, List<MessagePartDescription> parts)
		{
			foreach (MessagePart part in msg.Parts) {
				if (part.Name == "parameters") {
					if (!part.Element.IsEmpty) {
						body.WrapperName = part.Element.Name;
						ImportPartsBySchemaElement (part.Element, parts, msg, part);
					} else {
						body.WrapperName = part.Type.Name;
						ResolveType (part.Type, parts, body.WrapperNamespace);
					}
				}
				else
					throw new InvalidOperationException ("Only 'parameters' element in message part is supported"); // this should have been rejected by CanImportOperation().
			}
		}
Ejemplo n.º 13
0
        QName ExportParameters(MessageBodyDescription msgbody, string name, string ns)
        {
            XmlSchema xs = GetSchema(ns);

            //FIXME: Extract to a HasElement method ?
            foreach (XmlSchemaObject o in xs.Items)
            {
                XmlSchemaElement e = o as XmlSchemaElement;
                if (e == null)
                {
                    continue;
                }

                if (e.Name == name)
                {
                    throw new InvalidOperationException(String.Format(
                                                            "Message element named '{0}:{1}' has already been exported.",
                                                            ns, name));
                }
            }

            //Create the element for "parameters"
            XmlSchemaElement schema_element = new XmlSchemaElement();

            schema_element.Name = name;

            XmlSchemaComplexType complex_type = new XmlSchemaComplexType();
            //Generate Sequence representing the message/parameters
            //FIXME: MessageContractAttribute

            XmlSchemaSequence sequence = new XmlSchemaSequence();
            XmlSchemaElement  element  = null;

            if (msgbody.ReturnValue == null)
            {
                //parameters
                foreach (MessagePartDescription part in msgbody.Parts)
                {
                    if (part.Type == null)
                    {
                        //FIXME: Eg. when WsdlImporter is used to import a wsdl
                        throw new NotImplementedException();
                    }

                    element = GetSchemaElementForPart(part, xs);
                    sequence.Items.Add(element);
                }
            }
            else
            {
                //ReturnValue
                if (msgbody.ReturnValue.Type != typeof(void))
                {
                    element = GetSchemaElementForPart(msgbody.ReturnValue, xs);
                    sequence.Items.Add(element);
                }
            }

            complex_type.Particle     = sequence;
            schema_element.SchemaType = complex_type;

            xs.Items.Add(schema_element);
            GeneratedXmlSchemas.Reprocess(xs);

            return(new QName(schema_element.Name, xs.TargetNamespace));
        }
Ejemplo n.º 14
0
			void WriteMessagePart (
				XmlDictionaryWriter writer, MessageBodyDescription desc, MessagePartDescription partDesc, object obj)
			{
				parent.GetSerializer (partDesc).WriteObject (writer, obj);
			}
Ejemplo n.º 15
0
			void WriteMessagePart (
				XmlDictionaryWriter writer, MessageBodyDescription desc, MessagePartDescription partDesc, object obj)
			{
				// FIXME: it seems TransferMode.Streamed* has different serialization than .Buffered. Need to differentiate serialization somewhere (not limited to here).
				if (partDesc.Type == typeof (Stream)) {
					writer.WriteStartElement (partDesc.Name, partDesc.Namespace);
					writer.WriteValue (new StreamProvider ((Stream) obj));
					writer.WriteEndElement ();
				}
				else
					parent.GetSerializer (partDesc).WriteObject (writer, obj);
			}
Ejemplo n.º 16
0
		/* Sets the @name if the param or return type is SMMessage */
		string IsTypeMessage (MessageBodyDescription msgbody)
		{
			MessagePartDescription part = null;

			if (msgbody.Parts.Count == 0)
				part = msgbody.ReturnValue;
			else if (msgbody.Parts.Count == 1)
				part = msgbody.Parts [0];

			if (part != null && (part.Type.FullName == typeof (SMMessage).FullName))
				return part.Name;

			return null;
		}
Ejemplo n.º 17
0
 public static void FillMessageBodyDescriptionByContract(
     Type messageType, MessageBodyDescription mb)
 {
 }
Ejemplo n.º 18
0
		internal static bool HasReturnValue (MessageBodyDescription desc)
		{
			return desc.ReturnValue != null && desc.ReturnValue.Type != typeof (void);
		}
Ejemplo n.º 19
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 mpa = bmi.GetCustomAttribute <MessagePropertyAttribute> (false);
                if (mpa != null)
                {
                    var pd = new MessagePropertyDescription(mpa.Name ?? mname);
                    pd.Type       = MessageFilterOutByRef(mtype);
                    pd.MemberInfo = bmi;
                    md.Properties.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);
                }
            }

            return(md);
        }
Ejemplo n.º 20
0
		public static void FillMessageBodyDescriptionByContract (
			Type messageType, MessageBodyDescription mb)
		{
		}
Ejemplo n.º 21
0
		protected static object [] CreatePartsArray (MessageBodyDescription desc)
		{
			if (HasReturnValue (desc))
				return new object [desc.Parts.Count + 1];
			return new object [desc.Parts.Count];
		}
Ejemplo n.º 22
0
		MessagePart ExportMessageBodyDescription (MessageBodyDescription msgbody, string name, string ns)
		{
			MessagePart msgpart = new MessagePart ();
			string part_name = IsTypeMessage (msgbody);

			if (part_name != null) {
				msgpart.Name = part_name;
				msgpart.Type = ExportTypeMessage (); //FIXME: Cache this
			} else {
				msgpart.Name = "parameters";
				msgpart.Element = ExportParameters (msgbody, name, ns);
			}
			return msgpart;
		}
Ejemplo n.º 23
0
		XmlSerializer GetSerializer (MessageBodyDescription desc)
		{
			if (bodySerializers.ContainsKey (desc))
				return bodySerializers [desc];

			int count = desc.Parts.Count + (HasReturnValue (desc) ? 1 : 0);
			XmlReflectionMember [] members = new XmlReflectionMember [count];

			int ind = 0;
			if (HasReturnValue (desc))
				members [ind++] = CreateReflectionMember (desc.ReturnValue, true);

			foreach (MessagePartDescription partDesc in desc.Parts)
				members [ind++] = CreateReflectionMember (partDesc, false);

			XmlReflectionImporter xmlImporter = new XmlReflectionImporter ();
			// Register known types into xmlImporter.
			foreach (var type in OperationKnownTypes)
				xmlImporter.IncludeType (type);
			XmlMembersMapping [] partsMapping = new XmlMembersMapping [1];
			partsMapping [0] = xmlImporter.ImportMembersMapping (desc.WrapperName, desc.WrapperNamespace, members, true);
			bodySerializers [desc] = XmlSerializer.FromMappings (partsMapping) [0];
			return bodySerializers [desc];
		}
Ejemplo n.º 24
0
		QName ExportParameters (MessageBodyDescription msgbody, string name, string ns)
		{
			XmlSchema xs = GetSchema (ns);
			//FIXME: Extract to a HasElement method ?
			foreach (XmlSchemaObject o in xs.Items) {
				XmlSchemaElement e = o as XmlSchemaElement;
				if (e == null)
					continue;

				if (e.Name == name)
					throw new InvalidOperationException (String.Format (
						"Message element named '{0}:{1}' has already been exported.",
						ns, name));
			}
				
			//Create the element for "parameters"
			XmlSchemaElement schema_element = new XmlSchemaElement ();
			schema_element.Name = name;

			XmlSchemaComplexType complex_type = new XmlSchemaComplexType ();
			//Generate Sequence representing the message/parameters
			//FIXME: MessageContractAttribute
		
			XmlSchemaSequence sequence = new XmlSchemaSequence ();
			XmlSchemaElement element = null;

			if (msgbody.ReturnValue == null) {
				//parameters
				foreach (MessagePartDescription part in msgbody.Parts) {
					if (part.Type == null)
						//FIXME: Eg. when WsdlImporter is used to import a wsdl
						throw new NotImplementedException ();
					
					element = GetSchemaElementForPart (part, xs);
					sequence.Items.Add (element);
				}
			} else {
				//ReturnValue
				if (msgbody.ReturnValue.Type != typeof (void)) {
					element = GetSchemaElementForPart (msgbody.ReturnValue, xs);
					sequence.Items.Add (element);
				}
			}

			complex_type.Particle = sequence;
			schema_element.SchemaType = complex_type;

			xs.Items.Add (schema_element);
			GeneratedXmlSchemas.Reprocess (xs);

			return new QName (schema_element.Name, xs.TargetNamespace);
		}
Ejemplo n.º 25
0
			public DataContractBodyWriter (MessageBodyDescription desc, DataContractMessagesFormatter parent, object [] parts)
				: base (false)
			{
				this.desc = desc;
				this.parent = parent;
				this.parts = parts;
			}