Esempio n. 1
0
            private static XmlSerializerFormatAttribute FindAttribute(OperationDescription operation)
            {
                Type contractType = operation.DeclaringContract != null ? operation.DeclaringContract.ContractType : null;
                XmlSerializerFormatAttribute contractFormatAttribute = contractType != null?TypeLoader.GetFormattingAttribute(contractType, null) as XmlSerializerFormatAttribute : null;

                return(TypeLoader.GetFormattingAttribute(operation.OperationMethod, contractFormatAttribute) as XmlSerializerFormatAttribute);
            }
 public XmlSerializerOperationFormatter(OperationDescription description, XmlSerializerFormatAttribute xmlSerializerFormatAttribute,
                                        MessageInfo requestMessageInfo, MessageInfo replyMessageInfo) :
     base(description, xmlSerializerFormatAttribute.Style == OperationFormatStyle.Rpc, false /*isEncoded*/)
 {
     _requestMessageInfo = requestMessageInfo;
     _replyMessageInfo   = replyMessageInfo;
 }
            private static XmlSerializerFormatAttribute FindAttribute(OperationDescription operation)
            {
                System.Type attrProvider = (operation.DeclaringContract != null) ? operation.DeclaringContract.ContractType : null;
                XmlSerializerFormatAttribute defaultFormatAttribute = (attrProvider != null) ? (TypeLoader.GetFormattingAttribute(attrProvider, null) as XmlSerializerFormatAttribute) : null;

                return(TypeLoader.GetFormattingAttribute(operation.OperationMethod, defaultFormatAttribute) as XmlSerializerFormatAttribute);
            }
Esempio n. 4
0
 public static TypedMessageConverter Create(
     Type type, string action, string defaultNamespace,
     XmlSerializerFormatAttribute formatterAttribute)
 {
     return(new DefaultTypedMessageConverter(
                new XmlMessagesFormatter(
                    MessageContractToMessagesDescription(type, defaultNamespace, action),
                    formatterAttribute)));
 }
            internal OperationReflector ReflectOperation(OperationDescription operation)
            {
                XmlSerializerFormatAttribute attrOverride = FindAttribute(operation);

                if (attrOverride == null)
                {
                    return(null);
                }
                return(this.ReflectOperation(operation, attrOverride));
            }
        private static XmlSerializerFormatAttribute ConvertFromServiceModelXmlSerializerFormatAttribute(object attr)
        {
            var xmlSerializerFormatAttribute = new XmlSerializerFormatAttribute();

            xmlSerializerFormatAttribute.Style         = GetProperty <OperationFormatStyle>(attr, nameof(XmlSerializerFormatAttribute.Style));
            xmlSerializerFormatAttribute.SupportFaults = GetProperty <bool>(attr, nameof(XmlSerializerFormatAttribute.SupportFaults));
            xmlSerializerFormatAttribute.Use           = GetProperty <OperationFormatUse>(attr, nameof(XmlSerializerFormatAttribute.Use));

            return(xmlSerializerFormatAttribute);
        }
Esempio n. 7
0
 public XmlSerializerOperationFormatter(OperationDescription description, XmlSerializerFormatAttribute xmlSerializerFormatAttribute, MessageInfo requestMessageInfo, MessageInfo replyMessageInfo) : base(description, xmlSerializerFormatAttribute.Style == OperationFormatStyle.Rpc, xmlSerializerFormatAttribute.IsEncoded)
 {
     if (xmlSerializerFormatAttribute.IsEncoded && (xmlSerializerFormatAttribute.Style != OperationFormatStyle.Rpc))
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("SFxDocEncodedNotSupported", new object[] { description.Name })));
     }
     this.isEncoded          = xmlSerializerFormatAttribute.IsEncoded;
     this.requestMessageInfo = requestMessageInfo;
     this.replyMessageInfo   = replyMessageInfo;
 }
Esempio n. 8
0
 public XmlSerializerOperationBehavior(
     OperationDescription operation,
     XmlSerializerFormatAttribute format)
 {
     if (format == null)
     {
         format = new XmlSerializerFormatAttribute();
     }
     this.format    = format;
     this.operation = operation;
 }
Esempio n. 9
0
        private static bool DetermineXmlFormat(HttpOperationDescription operation)
        {
            Fx.Assert(operation != null, "The 'operation' parameter should not be null.");

            DataContractFormatAttribute  dataContract  = null;
            XmlSerializerFormatAttribute xmlSerializer = null;

            foreach (Attribute attribute in operation.Attributes)
            {
                if (dataContract == null)
                {
                    dataContract = attribute as DataContractFormatAttribute;
                }

                if (xmlSerializer == null)
                {
                    xmlSerializer = attribute as XmlSerializerFormatAttribute;
                }
            }

            if (xmlSerializer == null && dataContract != null)
            {
                return(false);
            }

            ContractDescription contract = operation.DeclaringContract;

            if (contract != null)
            {
                Type contractType = contract.ContractType;
                if (contractType != null)
                {
                    foreach (Attribute attribute in contractType.GetCustomAttributes(true).Cast <Attribute>())
                    {
                        if (dataContract == null)
                        {
                            dataContract = attribute as DataContractFormatAttribute;
                        }

                        if (xmlSerializer == null)
                        {
                            xmlSerializer = attribute as XmlSerializerFormatAttribute;
                        }
                    }

                    if (xmlSerializer == null && dataContract != null)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Esempio n. 10
0
        public XmlSerializerOperationBehavior(OperationDescription operation, XmlSerializerFormatAttribute attribute)
        {
            if (operation == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("operation");
            }
#pragma warning disable 56506 // Declaring contract cannot be null
            Reflector parentReflector = new Reflector(operation.DeclaringContract.Namespace, operation.DeclaringContract.ContractType);
#pragma warning disable 56506 // parentReflector cannot be null
            _reflector = parentReflector.ReflectOperation(operation, attribute ?? new XmlSerializerFormatAttribute());
        }
Esempio n. 11
0
        public XmlSerializerOperationFormatter(OperationDescription description, XmlSerializerFormatAttribute xmlSerializerFormatAttribute,
                                               MessageInfo requestMessageInfo, MessageInfo replyMessageInfo) :
            base(description, xmlSerializerFormatAttribute.Style == OperationFormatStyle.Rpc, xmlSerializerFormatAttribute.IsEncoded)
        {
            if (xmlSerializerFormatAttribute.IsEncoded && xmlSerializerFormatAttribute.Style != OperationFormatStyle.Rpc)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.SFxDocEncodedNotSupported, description.Name)));
            }

            _isEncoded          = xmlSerializerFormatAttribute.IsEncoded;
            _requestMessageInfo = requestMessageInfo;
            _replyMessageInfo   = replyMessageInfo;
        }
Esempio n. 12
0
 public XmlSerializerOperationBehavior(
     OperationDescription operation,
     XmlSerializerFormatAttribute format)
 {
     if (operation == null)
     {
         throw new ArgumentNullException("operation");
     }
     if (format == null)
     {
         format = new XmlSerializerFormatAttribute();
     }
     this.format    = format;
     this.operation = operation;
 }
Esempio n. 13
0
                internal OperationReflector(Reflector parent, OperationDescription operation, XmlSerializerFormatAttribute attr, bool reflectOnDemand)
                {
                    Fx.Assert(parent != null, "");
                    Fx.Assert(operation != null, "");
                    Fx.Assert(attr != null, "");

                    OperationFormatter.Validate(operation, attr.Style == OperationFormatStyle.Rpc, false /*IsEncoded*/);

                    _parent = parent;

                    this.Operation = operation;
                    this.Attribute = attr;

                    this.IsRpc    = (attr.Style == OperationFormatStyle.Rpc);
                    this.IsOneWay = operation.Messages.Count == 1;

                    this.RequestRequiresSerialization = !operation.Messages[0].IsUntypedMessage;
                    this.ReplyRequiresSerialization   = !this.IsOneWay && !operation.Messages[1].IsUntypedMessage;

                    MethodInfo methodInfo = operation.OperationMethod;

                    if (methodInfo == null)
                    {
                        // keyBase needs to be unique within the scope of the parent reflector
                        _keyBase = string.Empty;
                        if (operation.DeclaringContract != null)
                        {
                            _keyBase = operation.DeclaringContract.Name + "," + operation.DeclaringContract.Namespace + ":";
                        }
                        _keyBase = _keyBase + operation.Name;
                    }
                    else
                    {
                        _keyBase = methodInfo.DeclaringType.FullName + ":" + methodInfo.ToString();
                    }

                    foreach (MessageDescription message in operation.Messages)
                    {
                        foreach (MessageHeaderDescription header in message.Headers)
                        {
                            SetUnknownHeaderInDescription(header);
                        }
                    }
                    if (!reflectOnDemand)
                    {
                        this.EnsureMessageInfos();
                    }
                }
Esempio n. 14
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);
        }
Esempio n. 15
0
    public static void XmlSerializerOperationBehavior_BasicUsage()
    {
        XmlSerializerOperationBehavior serializerBehavior;
        BasicHttpBinding binding = new BasicHttpBinding();
        string baseAddress = "http://localhost:1066/SomeService";
        ChannelFactory<IXmlTestingType> factory = new ChannelFactory<IXmlTestingType>(binding, new EndpointAddress(baseAddress));
        ContractDescription cd = factory.Endpoint.Contract;
        OperationDescriptionCollection collection = cd.Operations;

        foreach (OperationDescription description in collection)
        {
            // Find the serializer behavior for those operations that have the attribute set via the interface.
            serializerBehavior = description.Behaviors.Find<XmlSerializerOperationBehavior>();
            if (serializerBehavior == null)
            {
                // This operation was not set with XmlSerializerFormatAttribute
                // Here we add the attribute programatically using defaults.
                if (String.Equals(description.Name, nameof(IXmlTestingType.XmlSerializerFormatAttribute_NotSet_One)))
                {
                    // Default OperationFormatStyle is "Document"
                    serializerBehavior = new XmlSerializerOperationBehavior(description);
                    description.Behaviors.Add(serializerBehavior);
                }
                // There is one additional operation not set with XmlSerializerFormatAttribute
                // Here we add the attribute programatically and further set the OperationFormatStyle to 'Rpc'
                else
                {
                    XmlSerializerFormatAttribute serializerAttribute = new XmlSerializerFormatAttribute();
                    serializerAttribute.Style = OperationFormatStyle.Rpc;

                    serializerBehavior = new XmlSerializerOperationBehavior(description, serializerAttribute);
                    description.Behaviors.Add(serializerBehavior);
                }

            }

            if (String.Equals(description.Name, nameof(IXmlTestingType.XmlSerializerFormatAttribute_Set_StyleSetTo_Rpc)) || (String.Equals(description.Name, nameof(IXmlTestingType.XmlSerializerFormatAttribute_NotSet_Two))))
            {
                Assert.True(String.Equals(serializerBehavior.XmlSerializerFormatAttribute.Style.ToString(), "Rpc"));
            }
            else
            {
                Assert.True(String.Equals(serializerBehavior.XmlSerializerFormatAttribute.Style.ToString(), "Document"));
            }
        }
    }
Esempio n. 16
0
        void IOperationContractGenerationExtension.GenerateOperation(OperationContractGenerationContext context)
        {
            if (context == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
            }
            if ((this.partInfoTable != null) && (this.partInfoTable.Count > 0))
            {
                Dictionary <XmlMembersMapping, XmlMembersMapping> alreadyExported = new Dictionary <XmlMembersMapping, XmlMembersMapping>();
                foreach (MessageDescription description in context.Operation.Messages)
                {
                    foreach (MessageHeaderDescription description2 in description.Headers)
                    {
                        this.GeneratePartType(alreadyExported, description2);
                    }
                    if (OperationFormatter.IsValidReturnValue(description.Body.ReturnValue))
                    {
                        this.GeneratePartType(alreadyExported, description.Body.ReturnValue);
                    }
                    foreach (MessagePartDescription description3 in description.Body.Parts)
                    {
                        this.GeneratePartType(alreadyExported, description3);
                    }
                }
            }
            XmlSerializerOperationBehavior behavior = context.Operation.Behaviors.Find <XmlSerializerOperationBehavior>();

            if (behavior != null)
            {
                XmlSerializerFormatAttribute attribute = (behavior == null) ? new XmlSerializerFormatAttribute() : behavior.XmlSerializerFormatAttribute;
                OperationFormatStyle         style     = attribute.Style;
                this.operationGenerator.GenerateOperation(context, ref style, attribute.IsEncoded, new WrappedBodyTypeGenerator(context), new Dictionary <MessagePartDescription, ICollection <CodeTypeReference> >());
                context.ServiceContractGenerator.AddReferencedAssembly(typeof(XmlTypeAttribute).Assembly);
                attribute.Style = style;
                context.SyncMethod.CustomAttributes.Add(System.ServiceModel.Description.OperationGenerator.GenerateAttributeDeclaration(context.Contract.ServiceContractGenerator, attribute));
                this.AddKnownTypes(context.SyncMethod.CustomAttributes, attribute.IsEncoded ? this.SoapExporter.IncludeMetadata : this.XmlExporter.IncludeMetadata);
                DataContractSerializerOperationGenerator.UpdateTargetCompileUnit(context, this.options.CodeCompileUnit);
            }
        }
                internal OperationReflector(XmlSerializerOperationBehavior.Reflector parent, OperationDescription operation, XmlSerializerFormatAttribute attr, bool reflectOnDemand)
                {
                    OperationFormatter.Validate(operation, attr.Style == OperationFormatStyle.Rpc, attr.IsEncoded);
                    this.parent    = parent;
                    this.Operation = operation;
                    this.Attribute = attr;
                    this.IsEncoded = attr.IsEncoded;
                    this.IsRpc     = attr.Style == OperationFormatStyle.Rpc;
                    this.IsOneWay  = operation.Messages.Count == 1;
                    this.RequestRequiresSerialization = !operation.Messages[0].IsUntypedMessage;
                    this.ReplyRequiresSerialization   = !this.IsOneWay && !operation.Messages[1].IsUntypedMessage;
                    MethodInfo operationMethod = operation.OperationMethod;

                    if (operationMethod == null)
                    {
                        this.keyBase = string.Empty;
                        if (operation.DeclaringContract != null)
                        {
                            this.keyBase = operation.DeclaringContract.Name + "," + operation.DeclaringContract.Namespace + ":";
                        }
                        this.keyBase = this.keyBase + operation.Name;
                    }
                    else
                    {
                        this.keyBase = operationMethod.DeclaringType.FullName + ":" + operationMethod.ToString();
                    }
                    foreach (MessageDescription description in operation.Messages)
                    {
                        foreach (MessageHeaderDescription description2 in description.Headers)
                        {
                            this.SetUnknownHeaderInDescription(description2);
                        }
                    }
                    if (!reflectOnDemand)
                    {
                        this.EnsureMessageInfos();
                    }
                }
 internal ExtensionData(XmlSerializerFormatAttribute xsFormatAttr)
 {
     this.xsFormatAttr = xsFormatAttr;
 }
        public static TypedMessageConverter Create(Type messageContract, String action, String defaultNamespace, XmlSerializerFormatAttribute formatterAttribute)
        {
            if (messageContract == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("messageContract"));
            }

            if (defaultNamespace == null)
            {
                defaultNamespace = NamingHelper.DefaultNamespace;
            }

            return(new XmlMessageConverter(GetOperationFormatter(messageContract, formatterAttribute, defaultNamespace, action)));
        }
 public static TypedMessageConverter Create(Type messageContract, string action, XmlSerializerFormatAttribute formatterAttribute)
 {
     return(Create(messageContract, action, null, formatterAttribute));
 }
Esempio n. 21
0
 public XmlMessagesFormatter(MessageDescriptionCollection messages, XmlSerializerFormatAttribute attr)
     : base(messages)
 {
     this.attr = attr;
 }
Esempio n. 22
0
 public XmlMessagesFormatter(OperationDescription desc, XmlSerializerFormatAttribute attr)
     : base(desc)
 {
     this.attr = attr;
 }
            internal OperationReflector ReflectOperation(OperationDescription operation, XmlSerializerFormatAttribute attrOverride)
            {
                OperationReflector item = new OperationReflector(this, operation, attrOverride, true);

                this.operationReflectors.Add(item);
                return(item);
            }
Esempio n. 24
0
 internal XmlSerializerOperationBehavior(OperationDescription operation, XmlSerializerFormatAttribute attribute, Reflector parentReflector)
     : this(operation, attribute)
 {
     // used by System.ServiceModel.Web
     _reflector = parentReflector.ReflectOperation(operation, attribute ?? new XmlSerializerFormatAttribute());
 }
Esempio n. 25
0
 internal static XmlSerializerOperationFormatter CreateOperationFormatter(OperationDescription operation, XmlSerializerFormatAttribute attr)
 {
     return(new XmlSerializerOperationBehavior(operation, attr).CreateFormatter());
 }
Esempio n. 26
0
            // overrides the auto-reflection with an attribute
            internal OperationReflector ReflectOperation(OperationDescription operation, XmlSerializerFormatAttribute attrOverride)
            {
                OperationReflector operationReflector = new OperationReflector(this, operation, attrOverride, true /*reflectOnDemand*/);

                _operationReflectors.Add(operationReflector);

                return(operationReflector);
            }
Esempio n. 27
0
 public static TypedMessageConverter Create(
     Type type, string action,
     XmlSerializerFormatAttribute formatterAttribute)
 {
     return(Create(type, action, TempUri, formatterAttribute));
 }