Esempio n. 1
0
            private void AddServiceContractAttribute(ServiceContractGenerationContext context)
            {
                CodeAttributeDeclaration declaration = new CodeAttributeDeclaration(context.ServiceContractGenerator.GetCodeTypeReference(typeof(ServiceContractAttribute)));

                if (context.ContractType.Name != context.Contract.CodeName)
                {
                    string str = (NamingHelper.XmlName(context.Contract.CodeName) == context.Contract.Name) ? context.Contract.CodeName : context.Contract.Name;
                    declaration.Arguments.Add(new CodeAttributeArgument("Name", new CodePrimitiveExpression(str)));
                }
                if ("http://tempuri.org/" != context.Contract.Namespace)
                {
                    declaration.Arguments.Add(new CodeAttributeArgument("Namespace", new CodePrimitiveExpression(context.Contract.Namespace)));
                }
                declaration.Arguments.Add(new CodeAttributeArgument("ConfigurationName", new CodePrimitiveExpression(ServiceContractGenerator.NamespaceHelper.GetCodeTypeReference(context.Namespace, context.ContractType).BaseType)));
                if (context.Contract.HasProtectionLevel)
                {
                    declaration.Arguments.Add(new CodeAttributeArgument("ProtectionLevel", new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(typeof(ProtectionLevel)), context.Contract.ProtectionLevel.ToString())));
                }
                if (context.DuplexCallbackType != null)
                {
                    declaration.Arguments.Add(new CodeAttributeArgument("CallbackContract", new CodeTypeOfExpression(context.DuplexCallbackTypeReference)));
                }
                if (context.Contract.SessionMode != SessionMode.Allowed)
                {
                    declaration.Arguments.Add(new CodeAttributeArgument("SessionMode", new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(typeof(SessionMode)), context.Contract.SessionMode.ToString())));
                }
                context.ContractType.CustomAttributes.Add(declaration);
            }
Esempio n. 2
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));
        }
        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));
            }
        }
 private void ExportMembersMapping(XmlMembersMapping membersMapping, Message message, bool skipSchemaExport, bool isEncoded, bool isRpc, bool isDocWrapped, bool isHeader)
 {
     if (!skipSchemaExport)
     {
         if (isEncoded)
         {
             this.SoapExporter.ExportMembersMapping(membersMapping);
         }
         else
         {
             this.XmlExporter.ExportMembersMapping(membersMapping, !isRpc);
         }
     }
     if (isDocWrapped)
     {
         if (isHeader)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Header cannot be Document Wrapped", new object[0])));
         }
         MessageContractExporter.AddMessagePart(message, "parameters", new XmlQualifiedName(membersMapping.XsdElementName, membersMapping.Namespace), XmlQualifiedName.Empty);
     }
     else
     {
         bool flag = !isRpc && !isEncoded;
         for (int i = 0; i < membersMapping.Count; i++)
         {
             XmlMemberMapping mapping  = membersMapping[i];
             string           partName = (isHeader || flag) ? NamingHelper.XmlName(mapping.MemberName) : mapping.XsdElementName;
             if (flag)
             {
                 MessageContractExporter.AddMessagePart(message, partName, new XmlQualifiedName(mapping.XsdElementName, mapping.Namespace), XmlQualifiedName.Empty);
             }
             else
             {
                 if (string.IsNullOrEmpty(mapping.TypeName))
                 {
                     throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("SFxAnonymousTypeNotSupported", new object[] { message.Name, partName })));
                 }
                 MessageContractExporter.AddMessagePart(message, partName, XmlQualifiedName.Empty, new XmlQualifiedName(mapping.TypeName, mapping.TypeNamespace));
             }
         }
     }
 }
            void AddServiceContractAttribute(ServiceContractGenerationContext context)
            {
                CodeAttributeDeclaration serviceContractAttr = new CodeAttributeDeclaration(context.ServiceContractGenerator.GetCodeTypeReference(typeof(ServiceContractAttribute)));

                if (context.ContractType.Name != context.Contract.CodeName)
                {
                    // make sure that decoded Contract name can be used, if not, then override name with encoded value
                    // specified in wsdl; this only works beacuse our Encoding algorithm will leave alredy encoded names untouched
                    string friendlyName = NamingHelper.XmlName(context.Contract.CodeName) == context.Contract.Name ? context.Contract.CodeName : context.Contract.Name;
                    serviceContractAttr.Arguments.Add(new CodeAttributeArgument("Name", new CodePrimitiveExpression(friendlyName)));
                }

                if (NamingHelper.DefaultNamespace != context.Contract.Namespace)
                {
                    serviceContractAttr.Arguments.Add(new CodeAttributeArgument("Namespace", new CodePrimitiveExpression(context.Contract.Namespace)));
                }

                serviceContractAttr.Arguments.Add(new CodeAttributeArgument("ConfigurationName", new CodePrimitiveExpression(NamespaceHelper.GetCodeTypeReference(context.Namespace, context.ContractType).BaseType)));

                if (context.Contract.HasProtectionLevel)
                {
                    serviceContractAttr.Arguments.Add(new CodeAttributeArgument("ProtectionLevel",
                                                                                new CodeFieldReferenceExpression(
                                                                                    new CodeTypeReferenceExpression(typeof(ProtectionLevel)), context.Contract.ProtectionLevel.ToString())));
                }

                if (context.DuplexCallbackType != null)
                {
                    serviceContractAttr.Arguments.Add(new CodeAttributeArgument("CallbackContract", new CodeTypeOfExpression(context.DuplexCallbackTypeReference)));
                }

                if (context.Contract.SessionMode != SessionMode.Allowed)
                {
                    serviceContractAttr.Arguments.Add(new CodeAttributeArgument("SessionMode",
                                                                                new CodeFieldReferenceExpression(
                                                                                    new CodeTypeReferenceExpression(typeof(SessionMode)), context.Contract.SessionMode.ToString())));
                }

                context.ContractType.CustomAttributes.Add(serviceContractAttr);
            }