Inheritance: IOperationBehavior, IWsdlExportExtension
Beispiel #1
0
 private static bool GetStyleAndUse(OperationDescription operation, Type messageContractExporterType, out bool isRpc, out bool isEncoded)
 {
     isRpc = isEncoded = false;
     if ((messageContractExporterType == typeof(DataContractSerializerMessageContractExporter)) || (messageContractExporterType == null))
     {
         DataContractSerializerOperationBehavior behavior = operation.Behaviors.Find <DataContractSerializerOperationBehavior>();
         if (behavior != null)
         {
             isRpc     = behavior.DataContractFormatAttribute.Style == OperationFormatStyle.Rpc;
             isEncoded = false;
             return(true);
         }
         if (messageContractExporterType == typeof(DataContractSerializerMessageContractExporter))
         {
             return(false);
         }
     }
     if ((messageContractExporterType == typeof(XmlSerializerMessageContractExporter)) || (messageContractExporterType == null))
     {
         XmlSerializerOperationBehavior behavior2 = operation.Behaviors.Find <XmlSerializerOperationBehavior>();
         if (behavior2 != null)
         {
             isRpc     = behavior2.XmlSerializerFormatAttribute.Style == OperationFormatStyle.Rpc;
             isEncoded = behavior2.XmlSerializerFormatAttribute.IsEncoded;
             return(true);
         }
     }
     return(false);
 }
        protected override object OnExportMessageContract()
        {
            object obj2 = this.Reflector.ReflectOperation(base.operation);

            if (obj2 == null)
            {
                XmlSerializerOperationBehavior extension = base.extension as XmlSerializerOperationBehavior;
                if (extension != null)
                {
                    obj2 = this.Reflector.ReflectOperation(base.operation, extension.XmlSerializerFormatAttribute);
                }
            }
            return(obj2);
        }
Beispiel #3
0
        private static OperationFormatter GetOperationFormatter(System.Type t, Attribute formatAttribute, string defaultNS, string action)
        {
            bool flag = formatAttribute is XmlSerializerFormatAttribute;
            MessageDescription   description       = new TypeLoader().CreateTypedMessageDescription(t, null, null, defaultNS, action, MessageDirection.Output);
            ContractDescription  declaringContract = new ContractDescription("dummy_contract", defaultNS);
            OperationDescription operation         = new OperationDescription(NamingHelper.XmlName(t.Name), declaringContract, false)
            {
                Messages = { description }
            };

            if (flag)
            {
                return(XmlSerializerOperationBehavior.CreateOperationFormatter(operation, (XmlSerializerFormatAttribute)formatAttribute));
            }
            return(new DataContractSerializerOperationFormatter(operation, (DataContractFormatAttribute)formatAttribute, null));
        }
Beispiel #4
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);
        }
        static OperationFormatter GetOperationFormatter(Type t, Attribute formatAttribute, string defaultNS, string action)
        {
            bool                 isXmlSerializer = (formatAttribute is XmlSerializerFormatAttribute);
            TypeLoader           typeLoader      = new TypeLoader();
            MessageDescription   message         = typeLoader.CreateTypedMessageDescription(t, null, null, defaultNS, action, MessageDirection.Output);
            ContractDescription  contract        = new ContractDescription("dummy_contract", defaultNS);
            OperationDescription operation       = new OperationDescription(NamingHelper.XmlName(t.Name), contract, false);

            operation.Messages.Add(message);

            if (isXmlSerializer)
            {
                return(XmlSerializerOperationBehavior.CreateOperationFormatter(operation, (XmlSerializerFormatAttribute)formatAttribute));
            }
            else
            {
                return(new DataContractSerializerOperationFormatter(operation, (DataContractFormatAttribute)formatAttribute, null));
            }
        }
 public SingleBodyParameterXmlSerializerMessageFormatter(OperationDescription operation, Type parameterType, bool isRequestFormatter, XmlSerializerOperationBehavior xsob, UnwrappedTypesXmlSerializerManager serializerManager)
     : base(operation, isRequestFormatter, "XmlSerializer")
 {
     if (operation == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("operation");
     }
     if (parameterType == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("parameterType");
     }
     if (xsob == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("xsob");
     }
     if (serializerManager == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("serializerManager");
     }
     this.serializerManager = serializerManager;
     this.parameterType = parameterType;
     List<Type> operationTypes = new List<Type>();
     operationTypes.Add(parameterType);
     this.knownTypes = new List<Type>();
     if (operation.KnownTypes != null)
     {
         foreach (Type knownType in operation.KnownTypes)
         {
             this.knownTypes.Add(knownType);
             operationTypes.Add(knownType);
         }
     }
     Type nullableType = SingleBodyParameterDataContractMessageFormatter.UnwrapNullableType(this.parameterType);
     if (nullableType != this.parameterType)
     {
         this.knownTypes.Add(nullableType);
         operationTypes.Add(nullableType);
     }
     this.serializerManager.RegisterType(this, operationTypes);
     thisLock = new Object();
 }
Beispiel #7
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);
            }
        }
 public XmlRpcOperationFormatterBehavior(DataContractSerializerOperationBehavior dcs, XmlSerializerOperationBehavior xcs)
 {
     _dcs = dcs;
     _xcs = xcs;
 }
 internal XmlSerializerFaultContractInfo(System.ServiceModel.Dispatcher.FaultContractInfo faultContractInfo, XmlSerializerOperationBehavior.Reflector.SerializerStub serializerStub, XmlQualifiedName faultContractElementName)
 {
     if (faultContractInfo == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("faultContractInfo");
     }
     if (faultContractElementName == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("faultContractElementName");
     }
     this.faultContractInfo = faultContractInfo;
     this.serializerStub = serializerStub;
     this.faultContractElementName = faultContractElementName;
 }
 internal SerializerStub(XmlSerializerOperationBehavior.Reflector.SerializerGenerationContext context, XmlMembersMapping mapping, int handle)
 {
     this.context = context;
     this.Mapping = mapping;
     this.Handle = handle;
 }
 private void CreateHeaderDescriptionTable(MessageDescription message, XmlSerializerOperationBehavior.Reflector.MessageInfo info, XmlMembersMapping headersMapping)
 {
     int num = 0;
     OperationFormatter.MessageHeaderDescriptionTable headerDescriptionTable = new OperationFormatter.MessageHeaderDescriptionTable();
     info.SetHeaderDescriptionTable(headerDescriptionTable);
     foreach (MessageHeaderDescription description in message.Headers)
     {
         if (description.IsUnknownHeaderCollection)
         {
             info.SetUnknownHeaderDescription(description);
         }
         else if (headersMapping != null)
         {
             string typeName;
             string typeNamespace;
             XmlMemberMapping mapping = headersMapping[num++];
             if (this.IsEncoded)
             {
                 typeName = mapping.TypeName;
                 typeNamespace = mapping.TypeNamespace;
             }
             else
             {
                 typeName = mapping.XsdElementName;
                 typeNamespace = mapping.Namespace;
             }
             if (typeName != description.Name)
             {
                 if (message.MessageType != null)
                 {
                     throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("SFxHeaderNameMismatchInMessageContract", new object[] { message.MessageType, description.MemberInfo.Name, description.Name, typeName })));
                 }
                 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("SFxHeaderNameMismatchInOperation", new object[] { this.Operation.Name, this.Operation.DeclaringContract.Name, this.Operation.DeclaringContract.Namespace, description.Name, typeName })));
             }
             if (typeNamespace != description.Namespace)
             {
                 if (message.MessageType != null)
                 {
                     throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("SFxHeaderNamespaceMismatchInMessageContract", new object[] { message.MessageType, description.MemberInfo.Name, description.Namespace, typeNamespace })));
                 }
                 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("SFxHeaderNamespaceMismatchInOperation", new object[] { this.Operation.Name, this.Operation.DeclaringContract.Name, this.Operation.DeclaringContract.Namespace, description.Namespace, typeNamespace })));
             }
             headerDescriptionTable.Add(typeName, typeNamespace, description);
         }
     }
 }
 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 void SetHeaders(XmlSerializerOperationBehavior.Reflector.SerializerStub headers)
 {
     this.headers = headers;
 }
 internal void SetBody(XmlSerializerOperationBehavior.Reflector.SerializerStub body, MessagePartDescriptionCollection rpcEncodedTypedMessageBodyParts)
 {
     this.body = body;
     this.rpcEncodedTypedMessageBodyParts = rpcEncodedTypedMessageBodyParts;
 }
        void ExportFault(FaultDescription fault, XmlSerializerOperationBehavior.Reflector.OperationReflector operationReflector)
        {
            WsdlNS.Message faultMessage = new WsdlNS.Message();
            faultMessage.Name = GetFaultMessageName(fault.Name);

            XmlQualifiedName elementName = ExportFaultElement(fault, operationReflector);
            this.contractContext.WsdlPortType.ServiceDescription.Messages.Add(faultMessage);
            AddMessagePart(faultMessage, "detail", elementName, null);

            // create a wsdl:fault to put inside the wsdl:portType/wsdl:operation
            WsdlNS.OperationFault operationFault = contractContext.GetOperationFault(fault);
            WsdlExporter.WSAddressingHelper.AddActionAttribute(fault.Action, operationFault, this.exporter.PolicyVersion);
            operationFault.Message = new XmlQualifiedName(faultMessage.Name, faultMessage.ServiceDescription.TargetNamespace);
        }
Beispiel #16
0
        internal IClientMessageFormatter GetDefaultClientFormatter(OperationDescription od, bool useJson, bool isWrapped)
        {
            DataContractSerializerOperationBehavior dcsob = od.Behaviors.Find<DataContractSerializerOperationBehavior>();
            if (useJson)
            {
                if (dcsob == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR2.GetString(SR2.JsonFormatRequiresDataContract, od.Name, od.DeclaringContract.Name, od.DeclaringContract.Namespace)));
                }
                return CreateDataContractJsonSerializerOperationFormatter(od, dcsob, isWrapped);
            }
            else
            {
                ClientRuntime clientRuntime = new ClientRuntime("name", "");
                ClientOperation cop = new ClientOperation(clientRuntime, "dummyClient", "urn:dummy");
                cop.Formatter = null;

                if (dcsob != null)
                {
                    (dcsob as IOperationBehavior).ApplyClientBehavior(od, cop);
                    return cop.Formatter;
                }
                XmlSerializerOperationBehavior xsob = od.Behaviors.Find<XmlSerializerOperationBehavior>();
                if (xsob != null)
                {
                    xsob = new XmlSerializerOperationBehavior(od, xsob.XmlSerializerFormatAttribute, this.reflector);
                    (xsob as IOperationBehavior).ApplyClientBehavior(od, cop);
                    return cop.Formatter;
                }
            }
            return null;
        }
Beispiel #17
0
        IDispatchMessageFormatter GetDefaultDispatchFormatter(OperationDescription od, bool useJson, bool isWrapped)
        {
            DataContractSerializerOperationBehavior dcsob = od.Behaviors.Find<DataContractSerializerOperationBehavior>();
            if (useJson)
            {
                if (dcsob == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR2.GetString(SR2.JsonFormatRequiresDataContract, od.Name, od.DeclaringContract.Name, od.DeclaringContract.Namespace)));
                }
                return CreateDataContractJsonSerializerOperationFormatter(od, dcsob, isWrapped);
            }
            else
            {
                EndpointDispatcher dummyED = new EndpointDispatcher(new EndpointAddress("http://localhost/"), "name", "");
                DispatchRuntime dispatchRuntime = dummyED.DispatchRuntime;
                DispatchOperation dop = new DispatchOperation(dispatchRuntime, "dummyDispatch", "urn:dummy");
                dop.Formatter = null;

                if (dcsob != null)
                {
                    (dcsob as IOperationBehavior).ApplyDispatchBehavior(od, dop);
                    return dop.Formatter;
                }
                XmlSerializerOperationBehavior xsob = od.Behaviors.Find<XmlSerializerOperationBehavior>();
                if (xsob != null)
                {
                    xsob = new XmlSerializerOperationBehavior(od, xsob.XmlSerializerFormatAttribute, this.reflector);
                    (xsob as IOperationBehavior).ApplyDispatchBehavior(od, dop);
                    return dop.Formatter;
                }
            }
            return null;
        }
 XmlQualifiedName ExportFaultElement(FaultDescription fault, XmlSerializerOperationBehavior.Reflector.OperationReflector operationReflector)
 {
     XmlQualifiedName elementName;
     XmlMembersMapping mapping = operationReflector.ImportFaultElement(fault, out elementName);
     if (operationReflector.IsEncoded)
         SoapExporter.ExportMembersMapping(mapping);
     else
         XmlExporter.ExportMembersMapping(mapping);
     return elementName;
 }
            internal static XmlSerializerFormatAttribute GetFormatAttribute(OperationDescription operation, bool createNew)
            {
                XmlSerializerOperationBehavior operationBehavior = operation.Behaviors.Find<XmlSerializerOperationBehavior>();

                if (operationBehavior != null)
                    return operationBehavior.XmlSerializerFormatAttribute;
                if (!createNew)
                    return null;
                operationBehavior = new XmlSerializerOperationBehavior(operation);
                operation.Behaviors.Add(operationBehavior);
                return operationBehavior.XmlSerializerFormatAttribute;
            }