protected override CodeTypeDeclaration BeginClass()
        {
            methodNames.Clear();
            CodeAttributeDeclarationCollection metadata = new CodeAttributeDeclarationCollection();

            if (Style == ServiceDescriptionImportStyle.Client)
            {
                WebCodeGenerator.AddCustomAttribute(metadata, typeof(DebuggerStepThroughAttribute), new CodeExpression[0]);
                WebCodeGenerator.AddCustomAttribute(metadata, typeof(DesignerCategoryAttribute), new CodeExpression[] { new CodePrimitiveExpression("code") });
            }

            Type[] requiredTypes = new Type[] { typeof(SoapDocumentMethodAttribute), typeof(XmlAttributeAttribute), typeof(WebService), typeof(Object), typeof(DebuggerStepThroughAttribute), typeof(DesignerCategoryAttribute) };
            WebCodeGenerator.AddImports(this.CodeNamespace, WebCodeGenerator.GetNamespacesForTypes(requiredTypes));
            CodeTypeDeclaration codeClass = WebCodeGenerator.CreateClass(this.ClassName, BaseClass.FullName,
                                                                         new string[0], metadata, CodeFlags.IsPublic | (Style == ServiceDescriptionImportStyle.Client ? 0 : CodeFlags.IsAbstract));

            codeClass.Comments.Add(new CodeCommentStatement("<remarks/>", true));

            CodeConstructor ctor = WebCodeGenerator.AddConstructor(codeClass, new string[0], new string[0], null, CodeFlags.IsPublic);

            ctor.Comments.Add(new CodeCommentStatement("<remarks/>", true));

            HttpAddressBinding httpAddressBinding = Port == null ? null : (HttpAddressBinding)Port.Extensions.Find(typeof(HttpAddressBinding));
            string             url = (httpAddressBinding != null) ? httpAddressBinding.Location : null;
            ServiceDescription serviceDescription = Binding.ServiceDescription;

            ProtocolImporterUtil.GenerateConstructorStatements(ctor, url, serviceDescription.AppSettingUrlKey, serviceDescription.AppSettingBaseUrl);

            codeClasses.Add(codeClass);
            return(codeClass);
        }
        public override void ImportClass()
        {
            // grab this here so it gets marked "handled" for both client and server
            SoapAddressBinding soapAddress = ImportContext.Port == null ? null : (SoapAddressBinding)ImportContext.Port.Extensions.Find(typeof(SoapAddressBinding));

            if (ImportContext.Style == ServiceDescriptionImportStyle.Client)
            {
                ImportContext.CodeTypeDeclaration.BaseTypes.Add(typeof(SoapHttpClientProtocol).FullName);
                CodeConstructor ctor = WebCodeGenerator.AddConstructor(ImportContext.CodeTypeDeclaration, new string[0], new string[0], null, CodeFlags.IsPublic);
                ctor.Comments.Add(new CodeCommentStatement("<remarks/>", true));
                if (ImportContext is Soap12ProtocolImporter)
                {
                    // add version code
                    CodeTypeReferenceExpression     versionEnumTypeReference  = new CodeTypeReferenceExpression(typeof(SoapProtocolVersion));
                    CodeFieldReferenceExpression    versionEnumFieldReference = new CodeFieldReferenceExpression(versionEnumTypeReference, Enum.Format(typeof(SoapProtocolVersion), SoapProtocolVersion.Soap12, "G"));
                    CodePropertyReferenceExpression versionPropertyReference  = new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "SoapVersion");
                    CodeAssignStatement             assignVersionStatement    = new CodeAssignStatement(versionPropertyReference, versionEnumFieldReference);
                    ctor.Statements.Add(assignVersionStatement);
                }
                ServiceDescription serviceDescription = ImportContext.Binding.ServiceDescription;
                string             url     = (soapAddress != null) ? soapAddress.Location : null;
                string             urlKey  = serviceDescription.AppSettingUrlKey;
                string             baseUrl = serviceDescription.AppSettingBaseUrl;
                ProtocolImporterUtil.GenerateConstructorStatements(ctor, url, urlKey, baseUrl);
            }
            else
            {
                ImportContext.CodeTypeDeclaration.BaseTypes.Add(typeof(WebService).FullName);
            }
        }
Пример #3
0
        public override void ImportClass()
        {
            SoapAddressBinding binding = (base.ImportContext.Port == null) ? null : ((SoapAddressBinding)base.ImportContext.Port.Extensions.Find(typeof(SoapAddressBinding)));

            if (base.ImportContext.Style == ServiceDescriptionImportStyle.Client)
            {
                base.ImportContext.CodeTypeDeclaration.BaseTypes.Add(typeof(SoapHttpClientProtocol).FullName);
                CodeConstructor ctor = WebCodeGenerator.AddConstructor(base.ImportContext.CodeTypeDeclaration, new string[0], new string[0], null, CodeFlags.IsPublic);
                ctor.Comments.Add(new CodeCommentStatement(Res.GetString("CodeRemarks"), true));
                bool flag = true;
                if (base.ImportContext is Soap12ProtocolImporter)
                {
                    flag = false;
                    CodeTypeReferenceExpression     targetObject = new CodeTypeReferenceExpression(typeof(SoapProtocolVersion));
                    CodeFieldReferenceExpression    right        = new CodeFieldReferenceExpression(targetObject, Enum.Format(typeof(SoapProtocolVersion), SoapProtocolVersion.Soap12, "G"));
                    CodePropertyReferenceExpression left         = new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "SoapVersion");
                    CodeAssignStatement             statement    = new CodeAssignStatement(left, right);
                    ctor.Statements.Add(statement);
                }
                ServiceDescription serviceDescription = base.ImportContext.Binding.ServiceDescription;
                string             url = (binding != null) ? binding.Location : null;
                string             appSettingUrlKey  = serviceDescription.AppSettingUrlKey;
                string             appSettingBaseUrl = serviceDescription.AppSettingBaseUrl;
                ProtocolImporterUtil.GenerateConstructorStatements(ctor, url, appSettingUrlKey, appSettingBaseUrl, flag && !base.ImportContext.IsEncodedBinding);
            }
            else if (base.ImportContext.Style == ServiceDescriptionImportStyle.Server)
            {
                base.ImportContext.CodeTypeDeclaration.BaseTypes.Add(typeof(WebService).FullName);
            }
        }
        protected override CodeTypeDeclaration BeginClass()
        {
            base.MethodNames.Clear();
            base.ExtraCodeClasses.Clear();
            CodeAttributeDeclarationCollection metadata = new CodeAttributeDeclarationCollection();

            if (base.Style == ServiceDescriptionImportStyle.Client)
            {
                WebCodeGenerator.AddCustomAttribute(metadata, typeof(DebuggerStepThroughAttribute), new CodeExpression[0]);
                WebCodeGenerator.AddCustomAttribute(metadata, typeof(DesignerCategoryAttribute), new CodeExpression[] { new CodePrimitiveExpression("code") });
            }
            Type[] types = new Type[] { typeof(SoapDocumentMethodAttribute), typeof(XmlAttributeAttribute), typeof(WebService), typeof(object), typeof(DebuggerStepThroughAttribute), typeof(DesignerCategoryAttribute), typeof(TransactionOption) };
            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 codeClass = WebCodeGenerator.CreateClass(base.ClassName, this.BaseClass.FullName, new string[0], metadata, CodeFlags.IsPublic | isAbstract, base.ServiceImporter.CodeGenerator.Supports(GeneratorSupport.PartialTypes));

            codeClass.Comments.Add(new CodeCommentStatement(System.Web.Services.Res.GetString("CodeRemarks"), true));
            CodeConstructor ctor = WebCodeGenerator.AddConstructor(codeClass, new string[0], new string[0], null, CodeFlags.IsPublic);

            ctor.Comments.Add(new CodeCommentStatement(System.Web.Services.Res.GetString("CodeRemarks"), true));
            HttpAddressBinding binding            = (base.Port == null) ? null : ((HttpAddressBinding)base.Port.Extensions.Find(typeof(HttpAddressBinding)));
            string             url                = (binding != null) ? binding.Location : null;
            ServiceDescription serviceDescription = base.Binding.ServiceDescription;

            ProtocolImporterUtil.GenerateConstructorStatements(ctor, url, serviceDescription.AppSettingUrlKey, serviceDescription.AppSettingBaseUrl, false);
            this.codeClasses.Add(codeClass);
            return(codeClass);
        }