Esempio n. 1
0
        protected override void EndClass()
        {
            SoapTransportImporter transportImporter = SoapTransportImporter.FindTransportImporter(soapBinding.Transport);

            if (transportImporter == null)
            {
                throw new InvalidOperationException("Transport '" + soapBinding.Transport + "' not supported");
            }
            transportImporter.ImportContext = this;
            transportImporter.ImportClass();

            if (xmlExporter.IncludeMetadata.Count > 0 || soapExporter.IncludeMetadata.Count > 0)
            {
                if (CodeTypeDeclaration.CustomAttributes == null)
                {
                    CodeTypeDeclaration.CustomAttributes = new CodeAttributeDeclarationCollection();
                }
                CodeTypeDeclaration.CustomAttributes.AddRange(xmlExporter.IncludeMetadata);
                CodeTypeDeclaration.CustomAttributes.AddRange(soapExporter.IncludeMetadata);
            }
        }
 protected override CodeTypeDeclaration BeginClass()
 {
     base.MethodNames.Clear();
     this.soapBinding = (System.Web.Services.Description.SoapBinding) base.Binding.Extensions.Find(typeof(System.Web.Services.Description.SoapBinding));
     this.transport = this.GetTransport(this.soapBinding.Transport);
     Type[] types = new Type[] { typeof(SoapDocumentMethodAttribute), typeof(XmlAttributeAttribute), typeof(WebService), typeof(object), typeof(DebuggerStepThroughAttribute), typeof(DesignerCategoryAttribute) };
     WebCodeGenerator.AddImports(base.CodeNamespace, WebCodeGenerator.GetNamespacesForTypes(types));
     CodeFlags isAbstract = (CodeFlags) 0;
     if (base.Style == ServiceDescriptionImportStyle.Server)
     {
         isAbstract = CodeFlags.IsAbstract;
     }
     else if (base.Style == ServiceDescriptionImportStyle.ServerInterface)
     {
         isAbstract = CodeFlags.IsInterface;
     }
     CodeTypeDeclaration declaration = WebCodeGenerator.CreateClass(base.ClassName, null, new string[0], null, CodeFlags.IsPublic | isAbstract, base.ServiceImporter.CodeGenerator.Supports(GeneratorSupport.PartialTypes));
     declaration.Comments.Add(new CodeCommentStatement(System.Web.Services.Res.GetString("CodeRemarks"), true));
     if (base.Style == ServiceDescriptionImportStyle.Client)
     {
         declaration.CustomAttributes.Add(new CodeAttributeDeclaration(typeof(DebuggerStepThroughAttribute).FullName));
         declaration.CustomAttributes.Add(new CodeAttributeDeclaration(typeof(DesignerCategoryAttribute).FullName, new CodeAttributeArgument[] { new CodeAttributeArgument(new CodePrimitiveExpression("code")) }));
     }
     else if (base.Style == ServiceDescriptionImportStyle.Server)
     {
         CodeAttributeDeclaration declaration2 = new CodeAttributeDeclaration(typeof(WebServiceAttribute).FullName);
         string str = (base.Service != null) ? base.Service.ServiceDescription.TargetNamespace : base.Binding.ServiceDescription.TargetNamespace;
         declaration2.Arguments.Add(new CodeAttributeArgument("Namespace", new CodePrimitiveExpression(str)));
         declaration.CustomAttributes.Add(declaration2);
     }
     CodeAttributeDeclaration declaration3 = new CodeAttributeDeclaration(typeof(WebServiceBindingAttribute).FullName);
     declaration3.Arguments.Add(new CodeAttributeArgument("Name", new CodePrimitiveExpression(XmlConvert.DecodeName(base.Binding.Name))));
     declaration3.Arguments.Add(new CodeAttributeArgument("Namespace", new CodePrimitiveExpression(base.Binding.ServiceDescription.TargetNamespace)));
     declaration.CustomAttributes.Add(declaration3);
     this.codeClasses.Add(declaration);
     this.classHeaders.Clear();
     return declaration;
 }
        /// <include file='doc\SoapProtocolImporter.uex' path='docs/doc[@for="SoapProtocolImporter.BeginClass"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        protected override CodeTypeDeclaration BeginClass() {
            MethodNames.Clear();

            soapBinding = (SoapBinding)Binding.Extensions.Find(typeof(SoapBinding));
            transport = GetTransport(soapBinding.Transport);

            Type[] requiredTypes = new Type[] { typeof(SoapDocumentMethodAttribute), typeof(XmlAttributeAttribute), typeof(WebService), typeof(Object), typeof(DebuggerStepThroughAttribute), typeof(DesignerCategoryAttribute) };
            WebCodeGenerator.AddImports(this.CodeNamespace, WebCodeGenerator.GetNamespacesForTypes(requiredTypes));
            CodeFlags flags = 0;
            if (Style == ServiceDescriptionImportStyle.Server)
                flags = CodeFlags.IsAbstract;
            else if (Style == ServiceDescriptionImportStyle.ServerInterface)
                flags = CodeFlags.IsInterface;
            CodeTypeDeclaration codeClass = WebCodeGenerator.CreateClass(this.ClassName, null, 
                new string[0], null, CodeFlags.IsPublic | flags,
                ServiceImporter.CodeGenerator.Supports(GeneratorSupport.PartialTypes));

            codeClass.Comments.Add(new CodeCommentStatement(Res.GetString(Res.CodeRemarks), true));
            if (Style == ServiceDescriptionImportStyle.Client) {
                codeClass.CustomAttributes.Add(new CodeAttributeDeclaration(typeof(DebuggerStepThroughAttribute).FullName));
                codeClass.CustomAttributes.Add(new CodeAttributeDeclaration(typeof(DesignerCategoryAttribute).FullName, new CodeAttributeArgument[] { new CodeAttributeArgument(new CodePrimitiveExpression("code")) }));
            }
            else if (Style == ServiceDescriptionImportStyle.Server) {
                CodeAttributeDeclaration webService = new CodeAttributeDeclaration(typeof(WebServiceAttribute).FullName);
                string targetNs = Service != null ? Service.ServiceDescription.TargetNamespace : Binding.ServiceDescription.TargetNamespace;
                webService.Arguments.Add(new CodeAttributeArgument("Namespace", new CodePrimitiveExpression(targetNs)));
                codeClass.CustomAttributes.Add(webService);
            }

            CodeAttributeDeclaration attribute = new CodeAttributeDeclaration(typeof(WebServiceBindingAttribute).FullName);
            attribute.Arguments.Add(new CodeAttributeArgument("Name", new CodePrimitiveExpression(XmlConvert.DecodeName(Binding.Name))));
            attribute.Arguments.Add(new CodeAttributeArgument("Namespace", new CodePrimitiveExpression(Binding.ServiceDescription.TargetNamespace)));

            codeClass.CustomAttributes.Add(attribute);

            codeClasses.Add(codeClass);
            classHeaders.Clear();
            return codeClass;
        }