Пример #1
0
        private MetadataSection CreateMetadataSection(object document)
        {
            System.Web.Services.Description.ServiceDescription description =
                document as System.Web.Services.Description.ServiceDescription;

            XmlSchema       schema  = document as XmlSchema;
            XmlElement      element = document as XmlElement;
            MetadataSection section;

            if (description != null)
            {
                section = MetadataSection.CreateFromServiceDescription(description);
            }
            else if (schema != null)
            {
                section = MetadataSection.CreateFromSchema(schema);
            }
            else if ((element != null) && IsPolicyElement(element))
            {
                section = MetadataSection.CreateFromPolicy(element, null);
            }
            else
            {
                section          = new MetadataSection();
                section.Metadata = document;
            }

            return(section);
        }
Пример #2
0
        internal static MetadataSet GetMetadataSetForMonolithicWsdl()
        {
            string    xmlSchemaFile = TestFiles.GetFilePath(TestFiles.RestaurantDataXsdFileName);
            XmlSchema xmlSchema;

            using (XmlTextReader xmlTextReader = new XmlTextReader(xmlSchemaFile))
            {
                xmlSchema = XmlSchema.Read(xmlTextReader, null);
            }

            string             serviceDescriptionFile = TestFiles.GetFilePath(TestFiles.RestaurantServiceWsdlFileName2);
            ServiceDescription serviceDescription;

            using (XmlTextReader xmlTextReader = new XmlTextReader(serviceDescriptionFile))
            {
                serviceDescription = ServiceDescription.Read(xmlTextReader);
            }

            List <MetadataSection> sections = new List <MetadataSection>
            {
                MetadataSection.CreateFromSchema(xmlSchema),
                MetadataSection.CreateFromServiceDescription(serviceDescription)
            };

            return(new MetadataSet(sections));
        }
Пример #3
0
        private void ReflectInternal(ProtocolReflector[] reflectors)
        {
            this.description = new System.Web.Services.Description.ServiceDescription();
            this.description.TargetNamespace = this.serviceAttr.Namespace;
            this.ServiceDescriptions.Add(this.description);
            this.service = new System.Web.Services.Description.Service();
            string name = this.serviceAttr.Name;

            if ((name == null) || (name.Length == 0))
            {
                name = this.serviceType.Name;
            }
            this.service.Name = XmlConvert.EncodeLocalName(name);
            if ((this.serviceAttr.Description != null) && (this.serviceAttr.Description.Length > 0))
            {
                this.service.Documentation = this.serviceAttr.Description;
            }
            this.description.Services.Add(this.service);
            this.reflectionContext = new Hashtable();
            this.exporter          = new XmlSchemaExporter(this.description.Types.Schemas);
            this.importer          = SoapReflector.CreateXmlImporter(this.serviceAttr.Namespace, SoapReflector.ServiceDefaultIsEncoded(this.serviceType));
            WebMethodReflector.IncludeTypes(this.methods, this.importer);
            for (int i = 0; i < reflectors.Length; i++)
            {
                reflectors[i].Reflect();
            }
        }
        private static void AddDocumentToSet(MetadataSet metadataSet, object document)
        {
            ServiceDescription serviceDescription = document as ServiceDescription;
            XmlSchema          schema             = document as XmlSchema;
            XmlElement         policy             = document as XmlElement;

            if (serviceDescription != null)
            {
                metadataSet.MetadataSections.Add(MetadataSection.CreateFromServiceDescription(serviceDescription));
            }
            else if (schema != null)
            {
                metadataSet.MetadataSections.Add(MetadataSection.CreateFromSchema(schema));
            }
            else if ((policy != null) && IsPolicyElement(policy))
            {
                metadataSet.MetadataSections.Add(MetadataSection.CreateFromPolicy(policy, null));
            }
            else
            {
                MetadataSection item = new MetadataSection {
                    Metadata = document
                };
                metadataSet.MetadataSections.Add(item);
            }
        }
Пример #5
0
        private static void AddDocumentToResults(object document, ICollection <MetadataSection> results)
        {
            ServiceDescription serviceDescription = document as ServiceDescription;
            XmlSchema          xmlSchema          = document as XmlSchema;
            XmlElement         xmlElement         = document as XmlElement;

            if (serviceDescription != null)
            {
                results.Add(MetadataSection.CreateFromServiceDescription(serviceDescription));
            }
            else if (xmlSchema != null)
            {
                results.Add(MetadataSection.CreateFromSchema(xmlSchema));
            }
            else if (xmlElement != null && (xmlElement.NamespaceURI == "http://schemas.xmlsoap.org/ws/2004/09/policy" || xmlElement.NamespaceURI == "http://www.w3.org/ns/ws-policy") && xmlElement.LocalName == "Policy")
            {
                results.Add(MetadataSection.CreateFromPolicy(xmlElement, null));
            }
            else
            {
                MetadataSection mexDoc = new MetadataSection();
                mexDoc.Metadata = document;
                results.Add(mexDoc);
            }
        }
Пример #6
0
        void AddDocumentToResults(object document, Collection <MetadataSection> results)
        {
            System.Web.Services.Description.ServiceDescription wsdl = document as System.Web.Services.Description.ServiceDescription;
            XmlSchema  schema = document as XmlSchema;
            XmlElement xmlDoc = document as XmlElement;

            if (wsdl != null)
            {
                results.Add(MetadataSection.CreateFromServiceDescription(wsdl));
            }
            else if (schema != null)
            {
                results.Add(MetadataSection.CreateFromSchema(schema));
            }
            else if (xmlDoc != null && xmlDoc.LocalName == "Policy")
            {
                results.Add(MetadataSection.CreateFromPolicy(xmlDoc, null));
            }
            else
            {
                MetadataSection mexDoc = new MetadataSection();
                mexDoc.Metadata = document;
                results.Add(mexDoc);
            }
        }
Пример #7
0
        private XmlDocument ExportEndpoints()
        {
            WsdlExporter exporter = new WsdlExporter();

            foreach (ServiceEndpoint ep in endpoints)
            {
                exporter.ExportEndpoint(ep);
            }

            MetadataSet   metadataSet = exporter.GetGeneratedMetadata();
            StringBuilder b           = new StringBuilder();
            StringWriter  sw          = new StringWriter(b);
            XmlTextWriter tw          = new XmlTextWriter(sw);

            foreach (MetadataSection section in metadataSet.MetadataSections)
            {
                if (section.Metadata is System.Web.Services.Description.ServiceDescription)
                {
                    System.Web.Services.Description.ServiceDescription sd = (System.Web.Services.Description.ServiceDescription)section.Metadata;
                    sd.Write(tw);
                }
            }

            string wcfWsdl = b.ToString();
            // Read it in to an XmlDocument.
            XmlDocument wcfWsdlDoc = new XmlDocument();

            wcfWsdlDoc.LoadXml(wcfWsdl);
            return(wcfWsdlDoc);
        }
Пример #8
0
        private static XmlSchemaSet ExtractXmlSchemas(IEnumerable <MetadataSection> metadataSections)
        {
            XmlSchemaSet xmlSchemaSet = new XmlSchemaSet {
                XmlResolver = null
            };

            foreach (MetadataSection metadataSection in metadataSections)
            {
                ServiceDescription serviceDescription = metadataSection.Metadata as ServiceDescription;
                if (((serviceDescription != null) && (serviceDescription.Types != null)) && (serviceDescription.Types.Schemas != null))
                {
                    foreach (XmlSchema schema in serviceDescription.Types.Schemas)
                    {
                        xmlSchemaSet.Add(schema);
                    }
                    continue;
                }
                XmlSchema xmlSchema = metadataSection.Metadata as XmlSchema;
                if (xmlSchema != null)
                {
                    xmlSchemaSet.Add(xmlSchema);
                }
            }
            return(xmlSchemaSet);
        }
Пример #9
0
 public static MetadataSection CreateFromServiceDescription(
     WSServiceDescription serviceDescription)
 {
     return(new MetadataSection(
                MetadataSection.ServiceDescriptionDialect,
                serviceDescription.TargetNamespace, serviceDescription));
 }
Пример #10
0
        public static object UploadData(string url, string @namespace, string classname,
                                        string methodname, object[] args, ArrayList al)
        {
            try
            {
                System.Net.WebClient wc = new System.Net.WebClient();
                //System.IO.Stream stream = wc.OpenRead(url + "?WSDL");
                System.IO.Stream stream = wc.OpenRead(url);
                System.Web.Services.Description.ServiceDescription         sd  = System.Web.Services.Description.ServiceDescription.Read(stream);
                System.Web.Services.Description.ServiceDescriptionImporter sdi = new System.Web.Services.Description.ServiceDescriptionImporter();
                sdi.AddServiceDescription(sd, string.Empty, string.Empty);                 //将sd描述导入到sdi中
                System.CodeDom.CodeNamespace   cn  = new System.CodeDom.CodeNamespace(@namespace);
                System.CodeDom.CodeCompileUnit ccu = new System.CodeDom.CodeCompileUnit();
                ccu.Namespaces.Add(cn);
                sdi.Import(cn, ccu);

                Microsoft.CSharp.CSharpCodeProvider   csc = new Microsoft.CSharp.CSharpCodeProvider();
                System.CodeDom.Compiler.ICodeCompiler icc = csc.CreateCompiler();

                System.CodeDom.Compiler.CompilerParameters cplist = new System.CodeDom.Compiler.CompilerParameters();
                cplist.GenerateExecutable = false;
                cplist.GenerateInMemory   = true;
                cplist.ReferencedAssemblies.Add("System.dll");
                cplist.ReferencedAssemblies.Add("System.XML.dll");
                cplist.ReferencedAssemblies.Add("System.Web.Services.dll");
                cplist.ReferencedAssemblies.Add("System.Data.dll");

                System.CodeDom.Compiler.CompilerResults cr = icc.CompileAssemblyFromDom(cplist, ccu);
                if (cr.Errors.HasErrors)
                {
                    System.Text.StringBuilder sb = new System.Text.StringBuilder();
                    foreach (System.CodeDom.Compiler.CompilerError ce in cr.Errors)
                    {
                        sb.Append(ce.ToString());
                        sb.Append(System.Environment.NewLine);
                    }
                    throw new Exception(sb.ToString());
                }

                System.Reflection.Assembly assembly = cr.CompiledAssembly;
                Type   t   = assembly.GetType(@namespace + "." + classname, true, true);
                object obj = Activator.CreateInstance(t);

                ParameterModifier[] paramsModifer = new ParameterModifier[1];
                paramsModifer[0] = new ParameterModifier(args.Length);
                //paramsModifer[0][7] = true;

                object result = t.InvokeMember(methodname, BindingFlags.Default | BindingFlags.InvokeMethod, null,
                                               obj, args, paramsModifer, null, null);

                //al.Add(args[7]);
                return(result);
            }
            catch (Exception ex)
            {
                WriteLog(ex.Message, EXCEPTION_LOG_TITLE);
                return(null);
            }
        }
Пример #11
0
        /// <summary>
        /// 根据指定的信息,调用远程WebService方法
        /// </summary>
        /// <param name="url">WebService的http形式的地址</param>
        /// <param name="namespace">欲调用的WebService的命名空间</param>
        /// <param name="classname">欲调用的WebService的类名(不包括命名空间前缀)</param>
        /// <param name="methodname">欲调用的WebService的方法名</param>
        /// <param name="args">参数列表</param>
        /// <returns>WebService的执行结果</returns>
        /// <remarks>
        /// 如果调用失败,将会抛出Exception。请调用的时候,适当截获异常。
        /// 异常信息可能会发生在两个地方:
        /// 1、动态构造WebService的时候,CompileAssembly失败。
        /// 2、WebService本身执行失败。
        /// </remarks>
        /// <example>
        /// <code>
        /// object obj = InvokeWebService("http://localhost/Service.asmx","method",new object[]{"1"});
        /// </code>
        /// </example>
        public static object InvokeWebService(string url, string methodname, object[] args)
        {
            try
            {
                string               @namespace = "WebService.DynamicWebCalling";
                string[]             parts      = url.Split('/');
                string[]             pps        = parts[parts.Length - 1].Split('.');
                string               classname  = pps[0];
                System.Net.WebClient wc         = new System.Net.WebClient();
                System.IO.Stream     stream     = wc.OpenRead(url + "?WSDL");
                System.Web.Services.Description.ServiceDescription         sd  = System.Web.Services.Description.ServiceDescription.Read(stream);
                System.Web.Services.Description.ServiceDescriptionImporter sdi = new System.Web.Services.Description.ServiceDescriptionImporter();
                sdi.AddServiceDescription(sd, "", "");
                System.CodeDom.CodeNamespace   cn  = new System.CodeDom.CodeNamespace(@namespace);
                System.CodeDom.CodeCompileUnit ccu = new System.CodeDom.CodeCompileUnit();
                ccu.Namespaces.Add(cn);
                sdi.Import(cn, ccu);

                Microsoft.CSharp.CSharpCodeProvider   csc = new Microsoft.CSharp.CSharpCodeProvider();
                System.CodeDom.Compiler.ICodeCompiler icc = csc.CreateCompiler();

                System.CodeDom.Compiler.CompilerParameters cplist = new System.CodeDom.Compiler.CompilerParameters();
                cplist.GenerateExecutable = false;
                cplist.GenerateInMemory   = true;
                cplist.ReferencedAssemblies.Add("System.dll");
                cplist.ReferencedAssemblies.Add("System.XML.dll");
                cplist.ReferencedAssemblies.Add("System.Web.Services.dll");
                cplist.ReferencedAssemblies.Add("System.Data.dll");

                System.CodeDom.Compiler.CompilerResults cr = icc.CompileAssemblyFromDom(cplist, ccu);
                if (true == cr.Errors.HasErrors)
                {
                    System.Text.StringBuilder sb = new System.Text.StringBuilder();
                    foreach (System.CodeDom.Compiler.CompilerError ce in cr.Errors)
                    {
                        sb.Append(ce.ToString());
                        sb.Append(System.Environment.NewLine);
                    }
                    throw new Exception(sb.ToString());
                }
                System.Reflection.Assembly assembly = cr.CompiledAssembly;
                Type   t   = assembly.GetType(@namespace + "." + classname, true, true);
                object obj = Activator.CreateInstance(t);
                System.Reflection.MethodInfo mi = t.GetMethod(methodname);
                return(mi.Invoke(obj, args));
            }
            catch (Exception ex)
            {
                StringBuilder str = new StringBuilder();
                for (int m = 0; m < args.Length; m++)
                {
                    str.Append(args[m]);
                    str.Append(",");
                }
                LogUtility.DataLog.WriteLog(LogUtility.LogLevel.Info, ex.Message + "--" + ex.Source.ToString() + "--" + url + methodname + "--" + str, new LogUtility.RunningPlace("WebServiceHelper", "InvokeWebService"), "WebService获取数据失败");
                return("");
            }
        }
 public System.Web.Services.Description.ServiceDescription GetServiceDescription(string ns)
 {
     System.Web.Services.Description.ServiceDescription serviceDescription = this.ServiceDescriptions[ns];
     if (serviceDescription == null)
     {
         serviceDescription = new System.Web.Services.Description.ServiceDescription {
             TargetNamespace = ns
         };
         this.ServiceDescriptions.Add(serviceDescription);
     }
     return serviceDescription;
 }
 public System.Web.Services.Description.ServiceDescription GetServiceDescription(string ns)
 {
     System.Web.Services.Description.ServiceDescription serviceDescription = this.ServiceDescriptions[ns];
     if (serviceDescription == null)
     {
         serviceDescription = new System.Web.Services.Description.ServiceDescription {
             TargetNamespace = ns
         };
         this.ServiceDescriptions.Add(serviceDescription);
     }
     return(serviceDescription);
 }
Пример #14
0
        /*
         * 优点:不用引用,通过网址,目标命名空间,调用WebServices,用于主站向子站请求数据
         * 缺点:使用上不如直接Web引用进来易用,如果只是单个并确定的,最好引用进来
         */
        /// <summary>
        /// 通过反射完成调用
        /// </summary>
        public static object InvokeWebSer(string url, string @namespace, string classname, string methodname, object[] args)
        {
            System.Net.WebClient wc = new System.Net.WebClient();
            string URL = string.Empty;

            if ((url.Substring(url.Length - 5, 5) != null) && ((url.Substring(url.Length - 5, 5).ToLower() != "?wsdl")))
            {
                URL = url + "?WSDL";
            }
            else
            {
                URL = url;
            }
            System.IO.Stream stream = wc.OpenRead(URL);
            System.Web.Services.Description.ServiceDescription         sd  = System.Web.Services.Description.ServiceDescription.Read(stream);
            System.Web.Services.Description.ServiceDescriptionImporter sdi = new System.Web.Services.Description.ServiceDescriptionImporter();
            sdi.AddServiceDescription(sd, "", "");
            System.CodeDom.CodeNamespace   cn  = new System.CodeDom.CodeNamespace(@namespace);
            System.CodeDom.CodeCompileUnit ccu = new System.CodeDom.CodeCompileUnit();
            ccu.Namespaces.Add(cn);
            sdi.Import(cn, ccu);

            Microsoft.CSharp.CSharpCodeProvider csc = new Microsoft.CSharp.CSharpCodeProvider();

            System.CodeDom.Compiler.CompilerParameters cplist = new System.CodeDom.Compiler.CompilerParameters();
            cplist.GenerateExecutable = false;
            cplist.GenerateInMemory   = true;
            cplist.ReferencedAssemblies.Add("System.dll");
            cplist.ReferencedAssemblies.Add("System.XML.dll");
            cplist.ReferencedAssemblies.Add("System.Web.Services.dll");
            cplist.ReferencedAssemblies.Add("System.Data.dll");

            System.CodeDom.Compiler.CompilerResults cr = csc.CompileAssemblyFromDom(cplist, ccu);

            if (true == cr.Errors.HasErrors)
            {
                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                foreach (System.CodeDom.Compiler.CompilerError ce in cr.Errors)
                {
                    sb.Append(ce.ToString());
                    sb.Append(System.Environment.NewLine);
                }
                throw new Exception(sb.ToString());
            }
            System.Reflection.Assembly assembly = cr.CompiledAssembly;
            Type   t   = assembly.GetType(@namespace + "." + classname, true, true);
            object obj = Activator.CreateInstance(t);

            System.Reflection.MethodInfo mi = t.GetMethod(methodname);
            return(mi.Invoke(obj, args));
        }
Пример #15
0
        private int InvokeWebservice(string url, string @namespace, string classname, string methodname, object[] args)
        {
            try
            {
                System.Net.WebClient wc     = new System.Net.WebClient();
                System.IO.Stream     stream = wc.OpenRead(url);
                System.Web.Services.Description.ServiceDescription         sd  = System.Web.Services.Description.ServiceDescription.Read(stream);
                System.Web.Services.Description.ServiceDescriptionImporter sdi = new System.Web.Services.Description.ServiceDescriptionImporter();
                sdi.AddServiceDescription(sd, "", "");
                System.CodeDom.CodeNamespace   cn  = new System.CodeDom.CodeNamespace(@namespace);
                System.CodeDom.CodeCompileUnit ccu = new System.CodeDom.CodeCompileUnit();
                ccu.Namespaces.Add(cn);
                sdi.Import(cn, ccu);

                Microsoft.CSharp.CSharpCodeProvider   csc = new Microsoft.CSharp.CSharpCodeProvider();
                System.CodeDom.Compiler.ICodeCompiler icc = csc.CreateCompiler();

                System.CodeDom.Compiler.CompilerParameters cplist = new System.CodeDom.Compiler.CompilerParameters();
                cplist.GenerateExecutable = false;
                cplist.GenerateInMemory   = true;
                cplist.ReferencedAssemblies.Add("System.dll");
                cplist.ReferencedAssemblies.Add("System.XML.dll");
                cplist.ReferencedAssemblies.Add("System.Web.Services.dll");
                cplist.ReferencedAssemblies.Add("System.Data.dll");

                System.CodeDom.Compiler.CompilerResults cr = icc.CompileAssemblyFromDom(cplist, ccu);
                if (true == cr.Errors.HasErrors)
                {
                    System.Text.StringBuilder sb = new System.Text.StringBuilder();
                    foreach (System.CodeDom.Compiler.CompilerError ce in cr.Errors)
                    {
                        sb.Append(ce.ToString());
                        sb.Append(System.Environment.NewLine);
                    }
                    throw new Exception(sb.ToString());
                }
                System.Reflection.Assembly assembly = cr.CompiledAssembly;
                Type   t   = assembly.GetType(@namespace + "." + classname, true, true);
                object obj = Activator.CreateInstance(t);
                System.Reflection.MethodInfo mi = t.GetMethod(methodname);

                mi.Invoke(obj, args);
            }
            catch
            {
                return(-1);
            }

            return(1);
        }
Пример #16
0
        static void Main(string[] args)
        {
            MetadataSet    metadata = new MetadataSet();
            string         address  = "http://127.0.0.1:3721/calculatorservice/metadata";
            HttpWebRequest request  = (HttpWebRequest)WebRequest.Create(address);

            request.Method = "Get";
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            using (XmlReader reader = XmlDictionaryReader.CreateTextReader(response.GetResponseStream(), new XmlDictionaryReaderQuotas()))
            {
                System.Web.Services.Description.ServiceDescription serviceDesc = System.Web.Services.Description.ServiceDescription.Read(reader);
                metadata.MetadataSections.Add(MetadataSection.CreateFromServiceDescription(serviceDesc));
            }
            using (XmlWriter writer = new XmlTextWriter("metadata.xml", Encoding.UTF8))
            {
                metadata.WriteTo(writer);
            }
            Process.Start("metadata.xml");
        }
Пример #17
0
        private static IEnumerable <MetadataSection> LoadAsWsdl(XmlReader reader, string path)
        {
            ServiceDescription description;

            try
            {
                description = ServiceDescription.Read(reader);
            }
            catch (Exception exception)
            {
                if (exception.IsFatal())
                {
                    throw;
                }

                string message = string.Format("WSDL Parsing Error while reading: '{0}'. Verify that the XML is both well-formed and valid.", path);
                throw new MetadataDiscoveryException(message);
            }
            return(new List <MetadataSection> {
                MetadataSection.CreateFromServiceDescription(description)
            });
        }
        internal static void ExportEndpoint(WsdlExporter wsdlExporter)
        {
            if (wsdlExporter.GeneratedWsdlDocuments.Count > 1)
            {
                throw new ApplicationException("Single file option is not supported in multiple wsdl files");
            }

            ServiceDescription rootDescription = wsdlExporter.GeneratedWsdlDocuments[0];
            XmlSchemas         imports         = new XmlSchemas();

            foreach (XmlSchema schema in wsdlExporter.GeneratedXmlSchemas.Schemas())
            {
                imports.Add(schema);
            }
            foreach (XmlSchema schema in imports)
            {
                schema.Includes.Clear();
            }

            rootDescription.Types.Schemas.Clear();
            rootDescription.Types.Schemas.Add(imports);
        }
 private void ReflectInternal(ProtocolReflector[] reflectors)
 {
     this.description = new System.Web.Services.Description.ServiceDescription();
     this.description.TargetNamespace = this.serviceAttr.Namespace;
     this.ServiceDescriptions.Add(this.description);
     this.service = new System.Web.Services.Description.Service();
     string name = this.serviceAttr.Name;
     if ((name == null) || (name.Length == 0))
     {
         name = this.serviceType.Name;
     }
     this.service.Name = XmlConvert.EncodeLocalName(name);
     if ((this.serviceAttr.Description != null) && (this.serviceAttr.Description.Length > 0))
     {
         this.service.Documentation = this.serviceAttr.Description;
     }
     this.description.Services.Add(this.service);
     this.reflectionContext = new Hashtable();
     this.exporter = new XmlSchemaExporter(this.description.Types.Schemas);
     this.importer = SoapReflector.CreateXmlImporter(this.serviceAttr.Namespace, SoapReflector.ServiceDefaultIsEncoded(this.serviceType));
     WebMethodReflector.IncludeTypes(this.methods, this.importer);
     for (int i = 0; i < reflectors.Length; i++)
     {
         reflectors[i].Reflect();
     }
 }
		public System.Web.Services.Description.ServiceDescription ReadObject_ServiceDescription (bool isNullable, bool checkType)
		{
			System.Web.Services.Description.ServiceDescription ob = null;
			if (isNullable && ReadNull()) return null;

			if (checkType) 
			{
				System.Xml.XmlQualifiedName t = GetXsiType();
				if (t != null) 
				{
					if (t.Name != "ServiceDescription" || t.Namespace != "http://schemas.xmlsoap.org/wsdl/")
						throw CreateUnknownTypeException(t);
				}
			}

			ob = new System.Web.Services.Description.ServiceDescription ();

			Reader.MoveToElement();

			while (Reader.MoveToNextAttribute())
			{
				if (Reader.LocalName == "name" && Reader.NamespaceURI == "") {
					ob.Name = XmlConvert.DecodeName(Reader.Value);
				}
				else if (Reader.LocalName == "targetNamespace" && Reader.NamespaceURI == "") {
					ob.TargetNamespace = Reader.Value;
				}
				else if (IsXmlnsAttribute (Reader.Name)) {
				}
				else {
					UnknownNode (ob);
				}
			}

			Reader.MoveToElement();
			if (Reader.IsEmptyElement) {
				Reader.Skip ();
				return ob;
			}

			Reader.ReadStartElement();
			Reader.MoveToContent();

			bool b0=false, b1=false, b2=false, b3=false, b4=false, b5=false, b6=false;

			System.Web.Services.Description.ImportCollection o8 = ob.Imports;
			System.Web.Services.Description.MessageCollection o10 = ob.Messages;
			System.Web.Services.Description.PortTypeCollection o12 = ob.PortTypes;
			System.Web.Services.Description.BindingCollection o14 = ob.Bindings;
			System.Web.Services.Description.ServiceCollection o16 = ob.Services;
			int n7=0, n9=0, n11=0, n13=0, n15=0;

			while (Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
			{
				if (Reader.NodeType == System.Xml.XmlNodeType.Element) 
				{
					if (Reader.LocalName == "binding" && Reader.NamespaceURI == "http://schemas.xmlsoap.org/wsdl/" && !b4) {
						if (o14 == null)
							throw CreateReadOnlyCollectionException ("System.Web.Services.Description.BindingCollection");
						o14.Add (ReadObject_Binding (false, true));
						n13++;
					}
					else if (Reader.LocalName == "service" && Reader.NamespaceURI == "http://schemas.xmlsoap.org/wsdl/" && !b5) {
						if (o16 == null)
							throw CreateReadOnlyCollectionException ("System.Web.Services.Description.ServiceCollection");
						o16.Add (ReadObject_Service (false, true));
						n15++;
					}
					else if (Reader.LocalName == "import" && Reader.NamespaceURI == "http://schemas.xmlsoap.org/wsdl/" && !b0) {
						if (o8 == null)
							throw CreateReadOnlyCollectionException ("System.Web.Services.Description.ImportCollection");
						o8.Add (ReadObject_Import (false, true));
						n7++;
					}
					else if (Reader.LocalName == "documentation" && Reader.NamespaceURI == "http://schemas.xmlsoap.org/wsdl/" && !b6) {
						b6 = true;
						ob.Documentation = Reader.ReadElementString ();
					}
					else if (Reader.LocalName == "message" && Reader.NamespaceURI == "http://schemas.xmlsoap.org/wsdl/" && !b2) {
						if (o10 == null)
							throw CreateReadOnlyCollectionException ("System.Web.Services.Description.MessageCollection");
						o10.Add (ReadObject_Message (false, true));
						n9++;
					}
					else if (Reader.LocalName == "types" && Reader.NamespaceURI == "http://schemas.xmlsoap.org/wsdl/" && !b1) {
						b1 = true;
						ob.Types = ReadObject_Types (false, true);
					}
					else if (Reader.LocalName == "portType" && Reader.NamespaceURI == "http://schemas.xmlsoap.org/wsdl/" && !b3) {
						if (o12 == null)
							throw CreateReadOnlyCollectionException ("System.Web.Services.Description.PortTypeCollection");
						o12.Add (ReadObject_PortType (false, true));
						n11++;
					}
					else {
						ServiceDescription.ReadExtension (Reader, ob);
					}
				}
				else
					UnknownNode(ob);

				Reader.MoveToContent();
			}


			ReadEndElement();

			return ob;
		}
Пример #21
0
        private void button1_Click(object sender, EventArgs e)
        {
            Logger.Text = "";
            XmlTextReader xmlr = null;

            System.Web.Services.Description.ServiceDescription  servdesc = null;
            System.Web.Services.Description.PortTypeCollection  ports    = null;
            System.Web.Services.Description.OperationCollection ops      = null;

            try
            {
                xmlr = new XmlTextReader(urltext.Text);
                xmlr.WhitespaceHandling = WhitespaceHandling.None;
                servdesc     = System.Web.Services.Description.ServiceDescription.Read(xmlr);
                ports        = servdesc.PortTypes;
                Logger.Text += " *** Found " + ports.Count + " portType(s) *** \r\n";
                for (int j = 0; j < ports.Count; j++)
                {
                    ops          = ports[j].Operations;
                    Logger.Text += " --- Found " + ops.Count + " operation(s) in : " + (j + 1) + " ---\r\n";
                    for (int i = 0; i < ops.Count; i++)
                    {
                        Logger.Text += ops[i].Name + "->" + "\r\n";
                        System.Web.Services.Description.OperationMessageCollection iter = ops[i].Messages;
                        //Message msgiter = null;
                        for (int k = 0; k < iter.Count; k++)
                        {
                            Logger.Text += iter[k].Message.Name + "\r\n";
                        }
                    }
                }

                /*
                 * while (xmlr.Read())
                 * {
                 *  switch (xmlr.NodeType)
                 *  {
                 *      case XmlNodeType.Element:
                 *
                 *          Logger.Text += xmlr.Name + "->" + xmlr.R + "\r\n";
                 *          break;
                 *      case XmlNodeType.EndElement:
                 *          break;
                 *      default:
                 *          break;
                 *  }
                 * }
                 */
            }
            catch (XmlException xe)
            {
                Logger.Text += xe.ToString();
            }
            finally
            {
                if (xmlr != null)
                {
                    xmlr.Close();
                }
            }
        }
Пример #22
0
		public static MetadataSection CreateFromServiceDescription (
			WSServiceDescription serviceDescription)
		{
			return new MetadataSection (
				MetadataSection.ServiceDescriptionDialect,
				serviceDescription.TargetNamespace, serviceDescription);
		}
        private void ReflectBinding(ReflectedBinding reflectedBinding)
        {
            string identifier = XmlConvert.EncodeLocalName(reflectedBinding.bindingAttr.Name);
            string ns         = reflectedBinding.bindingAttr.Namespace;

            if (identifier.Length == 0)
            {
                identifier = this.Service.Name + this.ProtocolName;
            }
            if (ns.Length == 0)
            {
                ns = this.ServiceDescription.TargetNamespace;
            }
            WsiProfiles none = WsiProfiles.None;

            if (reflectedBinding.bindingAttr.Location.Length > 0)
            {
                this.portType = null;
                this.binding  = null;
            }
            else
            {
                this.bindingServiceDescription = this.GetServiceDescription(ns);
                CodeIdentifiers identifiers = new CodeIdentifiers();
                foreach (System.Web.Services.Description.Binding binding in this.bindingServiceDescription.Bindings)
                {
                    identifiers.AddReserved(binding.Name);
                }
                identifier         = identifiers.AddUnique(identifier, this.binding);
                this.portType      = new System.Web.Services.Description.PortType();
                this.binding       = new System.Web.Services.Description.Binding();
                this.portType.Name = identifier;
                this.binding.Name  = identifier;
                this.binding.Type  = new XmlQualifiedName(this.portType.Name, ns);
                none = reflectedBinding.bindingAttr.ConformsTo & this.ConformsTo;
                if (reflectedBinding.bindingAttr.EmitConformanceClaims && (none != WsiProfiles.None))
                {
                    System.Web.Services.Description.ServiceDescription.AddConformanceClaims(this.binding.GetDocumentationElement(), none);
                }
                this.bindingServiceDescription.Bindings.Add(this.binding);
                this.bindingServiceDescription.PortTypes.Add(this.portType);
            }
            if (this.portNames == null)
            {
                this.portNames = new CodeIdentifiers();
                foreach (System.Web.Services.Description.Port port in this.Service.Ports)
                {
                    this.portNames.AddReserved(port.Name);
                }
            }
            this.port         = new System.Web.Services.Description.Port();
            this.port.Binding = new XmlQualifiedName(identifier, ns);
            this.port.Name    = this.portNames.AddUnique(identifier, this.port);
            this.Service.Ports.Add(this.port);
            this.BeginClass();
            if ((reflectedBinding.methodList != null) && (reflectedBinding.methodList.Count > 0))
            {
                foreach (LogicalMethodInfo info in reflectedBinding.methodList)
                {
                    this.MoveToMethod(info);
                    this.operation      = new System.Web.Services.Description.Operation();
                    this.operation.Name = XmlConvert.EncodeLocalName(info.Name);
                    if ((this.methodAttr.Description != null) && (this.methodAttr.Description.Length > 0))
                    {
                        this.operation.Documentation = this.methodAttr.Description;
                    }
                    this.operationBinding      = new System.Web.Services.Description.OperationBinding();
                    this.operationBinding.Name = this.operation.Name;
                    this.inputMessage          = null;
                    this.outputMessage         = null;
                    this.headerMessages        = null;
                    if (this.ReflectMethod())
                    {
                        if (this.inputMessage != null)
                        {
                            this.bindingServiceDescription.Messages.Add(this.inputMessage);
                        }
                        if (this.outputMessage != null)
                        {
                            this.bindingServiceDescription.Messages.Add(this.outputMessage);
                        }
                        if (this.headerMessages != null)
                        {
                            foreach (Message message in this.headerMessages)
                            {
                                this.bindingServiceDescription.Messages.Add(message);
                            }
                        }
                        this.binding.Operations.Add(this.operationBinding);
                        this.portType.Operations.Add(this.operation);
                    }
                }
            }
            if (((this.binding != null) && (none == WsiProfiles.BasicProfile1_1)) && (this.ProtocolName == "Soap"))
            {
                BasicProfileViolationCollection violations = new BasicProfileViolationCollection();
                WebServicesInteroperability.AnalyzeBinding(this.binding, this.bindingServiceDescription, this.ServiceDescriptions, violations);
                if (violations.Count > 0)
                {
                    throw new InvalidOperationException(System.Web.Services.Res.GetString("WebWsiViolation", new object[] { this.ServiceType.FullName, violations.ToString() }));
                }
            }
            this.EndClass();
        }
Пример #24
0
 private MetadataSection MapFromServiceDecsription(ServiceDescription description)
 {
     return(MetadataSection.CreateFromServiceDescription(description));
 }
Пример #25
0
        public static System.ServiceModel.Description.MetadataSection CreateFromServiceDescription(System.Web.Services.Description.ServiceDescription serviceDescription)
        {
            Contract.Requires(serviceDescription != null);
            Contract.Ensures(Contract.Result <System.ServiceModel.Description.MetadataSection>() != null);

            return(default(System.ServiceModel.Description.MetadataSection));
        }
Пример #26
0
        /// <summary>
        /// Get all the information about the service in a current address.
        /// Send the http://schemas.xmlsoap.org/ws/2004/09/transfer/Get message and
        /// receive the http://schemas.xmlsoap.org/ws/2004/09/transfer/GetResponse.
        /// </summary>
        /// <param name="endpointAddress">The address the service will be called.</param>
        public static void GetServiceEndPoints(EndpointAddress endpointAddress)
        {
            // Custom binding with TextMessageEncoding and HttpTransport and the specific soap and wsa versions shown here:
            CustomBinding binding = new CustomBinding(
                new TextMessageEncodingBindingElement(MessageVersion.Soap12WSAddressingAugust2004, Encoding.UTF8),
                new HttpTransportBindingElement());

            // A custom mex client deriving from MetadataExchangeClient. The motivation behind writing the custom client was to get at the ClientVia behavior for the MetadataExchangeClient.
            // Followed the instructions here for this.
            // Gave the physical address in the Via for the custom client and the logical address as the EP address to be put into the ws-addressing To header as:
            MetadataExchangeClient mex         = new MetadataExchangeClient(binding);
            MetadataSet            metadataSet = mex.GetMetadata(endpointAddress);

            // Check for the metadata set size.
            System.Collections.ObjectModel.Collection <MetadataSection> documentCollection = metadataSet.MetadataSections;
            if (documentCollection != null)
            {
                //Get the WSDL from each MetadataSection of the metadata set
                foreach (MetadataSection section in documentCollection)
                {
                    try
                    {
                        if (section.Metadata is System.Xml.XmlElement)
                        {
                            System.Xml.XmlElement element = (System.Xml.XmlElement)section.Metadata;
                            if (element.Name == "wsdp:Relationship")
                            {
                                Relationship relationship = (Relationship)Utils.FromXML(element.OuterXml, typeof(Relationship), string.Empty);

                                foreach (System.Xml.XmlElement innerElement in relationship.Any)
                                {
                                    if (innerElement.Name == "wsdp:Host")
                                    {
                                        HostServiceType host = (HostServiceType)Utils.FromXML(innerElement.OuterXml, typeof(HostServiceType),
                                                                                              string.Empty);
                                    }
                                    else if (innerElement.Name == "wsdp:Hosted")
                                    {
                                        HostServiceType hosted = (HostServiceType)Utils.FromXML(innerElement.OuterXml, typeof(HostServiceType),
                                                                                                "http://schemas.xmlsoap.org/ws/2006/02/devprof", new System.Xml.Serialization.XmlRootAttribute("Hosted"));

                                        if (hosted.EndpointReference != null && hosted.EndpointReference.Length > 0)
                                        {
                                            Console.WriteLine("Service ID: {0}", hosted.ServiceId);

                                            if (hosted.ServiceId.Equals("AccelerationService"))
                                            {
                                                accelerationServiceEndPoint = new EndpointAddress(hosted.EndpointReference[0].Address.Value);
                                                Console.WriteLine("Found endpoint for AccelerationService");
                                            }
                                            else if (hosted.ServiceId.Equals("DeviceInfoService"))
                                            {
                                                deviceInfoServiceEndPoint = new EndpointAddress(hosted.EndpointReference[0].Address.Value);
                                                Console.WriteLine("Found endpoint for DeviceInfoService");
                                            }
                                            else if (hosted.ServiceId.Equals("DataLoggingService"))
                                            {
                                                dataLoggingServiceEndPoint = new EndpointAddress(hosted.EndpointReference[0].Address.Value);
                                                Console.WriteLine("Found endpoint for DataLoggingService");
                                            }
                                        }
                                    }
                                }
                            }
                            else if (element.Name == "wsdp:ThisModel")
                            {
                                ThisModelType thisModel = (ThisModelType)Utils.FromXML(element.OuterXml, typeof(ThisModelType), string.Empty);
                            }
                            else if (element.Name == "wsdp:ThisDevice")
                            {
                                ThisDeviceType thisDevice = (ThisDeviceType)Utils.FromXML(element.OuterXml, typeof(ThisDeviceType), string.Empty);
                                Console.WriteLine(string.Format("FirmwareVersion: {0}", thisDevice.FirmwareVersion));
                                Console.WriteLine(string.Format("FriendlyName: {0}", thisDevice.FriendlyName));
                                Console.WriteLine(string.Format("SerialNumber: {0}", thisDevice.SerialNumber));
                            }
                        }
                        else if (section.Metadata is System.Web.Services.Description.ServiceDescription)
                        {
                            System.Web.Services.Description.ServiceDescription sd = (System.Web.Services.Description.ServiceDescription)section.Metadata;
                            Console.WriteLine(string.Format("ServiceDescription name: {0}", sd.Name));
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Error on getting MetaData.");
                    }
                }
            }
        }
Пример #27
0
 internal void SetParent(System.Web.Services.Description.ServiceDescription parent)
 {
     this.parent = parent;
 }
Пример #28
0
        private string GenerateSOAP()
        {
            XmlTextReader xmlr = null;

            try
            {
                xmlr = new XmlTextReader(urltext.Text);
            }
            catch (XmlException xe)
            {
                Logger.Text += xe.ToString();
            }
            System.Web.Services.Description.ServiceDescription servdesc = null;
            servdesc = System.Web.Services.Description.ServiceDescription.Read(xmlr);
            System.Web.Services.Description.ServiceCollection serviceColl = servdesc.Services;
            string returnurl = null;

            Logger.Text += "\r\n **** Service(s) Found : " + serviceColl.Count + " ****\r\n";
            //string returnurl = null;
            //How to select from more than one WSDL Ports???
            TreeNode root   = null;
            TreeNode porttn = null;

            for (int i = 0; i < serviceColl.Count; i++)
            {
                //Logger.Text += "For service : " + serviceColl[i].Name + " " + serviceColl[i].Ports.Count + " port(s) discovered: --> ";
                root = new TreeNode(serviceColl[i].Name);
                portlist.Nodes.Add(root);
                for (int j = 0; j < serviceColl[i].Ports.Count; j++)
                {
                    //Logger.Text += serviceColl[i].Ports[j].Name + ", ";
                    //if (serviceColl[i].Ports[j].Name == stringNodeName)
                    //{
                    //int j = 0; // temp
                    //serviceno = i;
                    //portno = j;
                    //}
                    porttn = new TreeNode(serviceColl[i].Ports[j].Name);
                    root.Nodes.Add(porttn);
                }
            }
            portlist.SelectedNode = portlist.Nodes[0];

            for (int i = 0; i < serviceColl.Count; i++)
            {
                Logger.Text += "For service : " + serviceColl[i].Name + " " + serviceColl[i].Ports.Count + " port(s) discovered: --> ";
                for (int j = 0; j < serviceColl[i].Ports.Count; j++)
                {
                    Logger.Text += serviceColl[i].Ports[j].Name + ", ";
                    for (int k = 0; k < serviceColl[i].Ports[j].Extensions.Count; k++)
                    {
                        System.Web.Services.Description.Binding              basebinding = serviceColl[i].Ports[j].Extensions[k] as System.Web.Services.Description.Binding;
                        System.Web.Services.Description.SoapAddressBinding   sab         = serviceColl[i].Ports[j].Extensions[k] as System.Web.Services.Description.SoapAddressBinding;
                        System.Web.Services.Description.Soap12AddressBinding s12ab       = serviceColl[i].Ports[j].Extensions[k] as System.Web.Services.Description.Soap12AddressBinding;
                        System.Web.Services.Description.HttpAddressBinding   hab         = serviceColl[i].Ports[j].Extensions[k] as System.Web.Services.Description.HttpAddressBinding;
                        if (sab != null)
                        {
                            returnurl      = sab.Location;
                            Logger.Text   += returnurl;
                            targeturl.Text = returnurl;
                        }
                        else if (s12ab != null)
                        {
                            returnurl      = s12ab.Location;
                            Logger.Text   += returnurl;
                            targeturl.Text = returnurl;
                        }
                        else
                        {
                            returnurl      = hab.Location;
                            Logger.Text   += returnurl;
                            targeturl.Text = returnurl;
                        }
                    }
                }
                Logger.Text += "\r\n";
            }
            return(returnurl);
        }
 internal void SetParent(System.Web.Services.Description.ServiceDescription parent)
 {
     this.parent = parent;
 }
Пример #30
0
        private void button1_Click(object sender, EventArgs e)
        {
            Logger.Text = "";
            XmlTextReader xmlr = null;

            System.Web.Services.Description.ServiceDescription  servdesc = null;
            System.Web.Services.Description.PortTypeCollection  ports    = null;
            System.Web.Services.Description.OperationCollection ops      = null;
            System.Xml.Serialization.XmlSchemas schemas = null;

            for (int i = 0; i < httpheaderlist.Items.Count; i++)
            {
                httpheaderlist.Items.RemoveAt(i);
            }
            if (!urltext.Text.StartsWith("http"))
            {
                MessageBox.Show("Please enter a URL starting with http");
                return;
            }
            if (urltext.Text.IndexOf("://") == -1)
            {
                MessageBox.Show("Did you forget the protocol like http:// or https:// ?" +
                                "\r\n E.g., http://soap.amazon.com/schemas2/AmazonWebServices.wsdl");
                return;
            }
            try
            {
                xmlr = new XmlTextReader(urltext.Text);
                xmlr.WhitespaceHandling = WhitespaceHandling.None;
                servdesc     = System.Web.Services.Description.ServiceDescription.Read(xmlr);
                schemas      = servdesc.Types.Schemas;
                Logger.Text += "=== Found " + schemas.Count + " schema(s)===\r\n";

                for (int k = 0; k < schemas.Count; k++)
                {
                    XmlSchemaObjectCollection xmlelem    = schemas[k].Items;
                    XmlSchemaObjectEnumerator enumerator = xmlelem.GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        if (enumerator.Current is XmlSchemaElement)
                        {
                            XmlSchemaElement xse = (XmlSchemaElement)enumerator.Current;
                            Logger.Text += xse.Name + '=' + xse.SchemaType + ", ";
                            TraverseParticle(xse);
                        }
                        else
                        {
                            if (enumerator.Current is XmlSchemaComplexType)
                            {
                                XmlSchemaComplexType xsct = (XmlSchemaComplexType)enumerator.Current;
                                Logger.Text += '\'' + xsct.Name + ": ";
                                TraverseParticle(xsct.Particle);
                                if (xsct.ContentModel is XmlSchemaSimpleContent)
                                {
                                    Logger.Text += "Simple; ";
                                }
                                else
                                {
                                    //XmlSchemaComplexContent complexContent = (XmlSchemaComplexContent)xsct.ContentModel;
                                    if (xsct.ContentModel is XmlSchemaComplexContent)
                                    {
                                        Logger.Text += "Complex; ";
                                    }
                                }
                                Logger.Text += "\',";
                            }
                        }
                    }
                    Logger.Text += "\r\n";
                }

                ports        = servdesc.PortTypes;
                Logger.Text += " *** Found " + ports.Count + " portType(s) *** \r\n";
                TreeNode tn      = null;
                TreeNode msgNode = null;
                TreeNode root    = new TreeNode(urltext.Text);
                treeView1.Nodes.Add(root);
                for (int j = 0; j < ports.Count; j++)
                {
                    ops          = ports[j].Operations;
                    Logger.Text += " --- Found " + ops.Count + " operation(s) in : " + (j + 1) + " ---\r\n";
                    for (int i = 0; i < ops.Count; i++)
                    {
                        Logger.Text += ops[i].Name + "->" + "\r\n";
                        tn           = new TreeNode(ops[i].Name);
                        root.Nodes.Add(tn);
                        System.Web.Services.Description.OperationMessageCollection iter = ops[i].Messages;
                        //Message msgiter = null;
                        for (int k = 0; k < iter.Count; k++)
                        {
                            Logger.Text += iter[k].Message.Name + "\r\n";
                            msgNode      = new TreeNode(iter[k].Message.Name);
                            tn.Nodes.Add(msgNode);
                        }
                    }
                }
                GenerateSOAP();

                /*
                 * while (xmlr.Read())
                 * {
                 *  switch (xmlr.NodeType)
                 *  {
                 *      case XmlNodeType.Element:
                 *
                 *          Logger.Text += xmlr.Name + "->" + xmlr.R + "\r\n";
                 *          break;
                 *      case XmlNodeType.EndElement:
                 *          break;
                 *      default:
                 *          break;
                 *  }
                 * }
                 */
            }
            catch (XmlException xe)
            {
                Logger.Text += xe.StackTrace;
            }

            catch (Exception ex)
            {
                Logger.Text += ex.StackTrace;
            }
            finally
            {
                if (xmlr != null)
                {
                    xmlr.Close();
                }
            }
        }
Пример #31
0
        private string GenerateSOAP(string stringNodeName, string url)
        {
            XmlTextReader xmlr        = null;
            string        returnval   = null;
            string        headerval   = null;
            int           indexOfOp   = -1;
            int           indexOfPort = -1;

            System.Web.Services.Description.ServiceDescription servdesc = null;
            System.Xml.Serialization.XmlSchemas schemas = null;
            XmlGenerator xmlGen = new XmlGenerator();

            try
            {
                //xmlr = new XmlTextReader(urltext.Text);
                xmlr = new XmlTextReader(url);
                xmlr.WhitespaceHandling = WhitespaceHandling.None;
                servdesc = System.Web.Services.Description.ServiceDescription.Read(xmlr);
                schemas  = servdesc.Types.Schemas;
                //Find operation matching the selected row
                for (int i = 0; i < servdesc.PortTypes.Count && indexOfPort == -1 && indexOfOp == -1; i++)
                {
                    for (int j = 0; j < servdesc.PortTypes[i].Operations.Count && indexOfPort == -1 && indexOfOp == -1; j++)
                    {
                        if (servdesc.PortTypes[i].Operations[j].Name == stringNodeName)
                        {
                            indexOfOp   = j;
                            indexOfPort = i;
                        }
                    }
                }
                System.Web.Services.Description.Operation SelectedOp = null;

                if (indexOfPort != -1 && indexOfOp != -1)
                {
                    SelectedOp = servdesc.PortTypes[indexOfPort].Operations[indexOfOp];
                }
                else
                {
                    Logger.Text += " Element not found in selected Operations \r\n";
                    return("");
                }
                //Get the URL for the particular method
                int    serviceno = -1;
                int    portno    = -1;
                int    extno     = -1;
                string urltosend = null;
                System.Web.Services.Description.Port SelectedPort             = null;
                System.Web.Services.Description.ServiceCollection serviceColl = servdesc.Services;
                Logger.Text += "\r\nSelected port index: " + portlist.SelectedNode.Index + "\r\n";
                bool found = false;
                for (int i = 0; i < serviceColl.Count && !found; i++)
                {
                    for (int j = 0; j < serviceColl[i].Ports.Count && !found; j++)
                    {
                        if (serviceColl[i].Ports[j].Name == portlist.SelectedNode.Text)
                        {
                            found     = true;
                            serviceno = i;
                            portno    = j;
                        }
                    }
                }
                if (serviceno != -1 && portno != -1)
                {
                    SelectedPort = serviceColl[serviceno].Ports[portno];

                    for (int k = 0; k < SelectedPort.Extensions.Count; k++)
                    {
                        System.Web.Services.Description.Binding              basebinding = SelectedPort.Extensions[k] as System.Web.Services.Description.Binding;
                        System.Web.Services.Description.SoapAddressBinding   sab         = SelectedPort.Extensions[k] as System.Web.Services.Description.SoapAddressBinding;
                        System.Web.Services.Description.Soap12AddressBinding s12ab       = SelectedPort.Extensions[k] as System.Web.Services.Description.Soap12AddressBinding;
                        System.Web.Services.Description.HttpAddressBinding   hab         = SelectedPort.Extensions[k] as System.Web.Services.Description.HttpAddressBinding;
                        if (sab != null)
                        {
                            urltosend = sab.Location;
                            //Logger.Text += urltosend;
                        }
                        else if (s12ab != null)
                        {
                            urltosend = s12ab.Location;
                            //Logger.Text += urltosend;
                        }
                        else
                        {
                            urltosend = hab.Location;
                            //Logger.Text += urltosend;
                        }
                    }
                    int bindingno = -1;
                    int opno      = -1;
                    found = false;
                    for (int i = 0; i < servdesc.Bindings.Count && !found; i++)
                    {
                        for (int j = 0; j < servdesc.Bindings[i].Operations.Count && !found; j++)
                        {
                            if (servdesc.Bindings[i].Operations[j].Name == stringNodeName)
                            {
                                bindingno = i;
                                opno      = j;
                                found     = true;
                            }
                        }
                    }

                    if (bindingno != -1 && opno != -1)
                    {
                        for (int k = 0; k < servdesc.Bindings[bindingno].Operations[opno].Extensions.Count; k++)
                        {
                            System.Web.Services.Description.Binding basebinding          = servdesc.Bindings[bindingno].Operations[opno].Extensions[k] as System.Web.Services.Description.Binding;
                            System.Web.Services.Description.SoapOperationBinding   sob   = servdesc.Bindings[bindingno].Operations[opno].Extensions[k] as System.Web.Services.Description.SoapOperationBinding;
                            System.Web.Services.Description.Soap12OperationBinding s12ob = servdesc.Bindings[bindingno].Operations[opno].Extensions[k] as System.Web.Services.Description.Soap12OperationBinding;
                            System.Web.Services.Description.HttpOperationBinding   hob   = servdesc.Bindings[bindingno].Operations[opno].Extensions[k] as System.Web.Services.Description.HttpOperationBinding;
                            if (sob != null)
                            {
                                //urltosend += sob.SoapAction;
                                ListViewItem item = new ListViewItem();
                                item.Text = "SoapAction: \"" + sob.SoapAction + "\"";
                                httpheaderlist.Items.Add(item);
                                for (int index = 0; index < servdesc.Bindings[bindingno].Operations[opno].Input.Extensions.Count; index++)
                                {
                                    System.Web.Services.Description.SoapHeaderBinding shb = servdesc.Bindings[bindingno].Operations[opno].Input.Extensions[index] as System.Web.Services.Description.SoapHeaderBinding;
                                    if (shb != null)
                                    { //SoapHeader is defined
                                        //returnval += SchemaSearching(servdesc.Types.Schemas[0], shb.Message.Name);
                                        Logger.Text += "Name of header " + shb.Message.Name + "\r\n";
                                        string headerType;
                                        //returnval += SchemaSearching(servdesc.Types.Schemas[0], servdesc.Messages[shb.Message.Name].Parts[0].Element.Name);
                                        if (servdesc.Messages[shb.Message.Name].Parts[0].Type.IsEmpty)
                                        {
                                            headerType = servdesc.Messages[shb.Message.Name].Parts[0].Element.Name;
                                            headerval += SchemaSearching(servdesc.Types.Schemas[0], headerType);
                                        }
                                        else
                                        {   //Currently takes care of only one part in each message
                                            if (shb.Message.Name != null)
                                            {
                                                headerval += '<' + shb.Message.Name + '>';
                                                for (int i = 0; i < servdesc.Messages[shb.Message.Name].Parts.Count; i++)
                                                {
                                                    headerType = servdesc.Messages[shb.Message.Name].Parts[i].Type.Name;
                                                    headerval += '<' + servdesc.Messages[shb.Message.Name].Parts[i].Name + '>';
                                                    headerval += SchemaSearching(servdesc.Types.Schemas[0], headerType);
                                                    headerval += "</" + servdesc.Messages[shb.Message.Name].Parts[i].Name + ">";
                                                }
                                                headerval += "</" + shb.Message.Name + '>';
                                            }
                                        }
                                    }
                                }
                                break;
                                //Logger.Text += urltosend;
                            }
                            else if (s12ob != null)
                            {
                                ListViewItem item = new ListViewItem();
                                item.Text = "SoapAction: \"" + sob.SoapAction + "\"";
                                httpheaderlist.Items.Add(item);
                                for (int index = 0; index < servdesc.Bindings[bindingno].Operations[opno].Input.Extensions.Count; index++)
                                {
                                    System.Web.Services.Description.Soap12HeaderBinding s12hb = servdesc.Bindings[bindingno].Operations[opno].Input.Extensions[index] as System.Web.Services.Description.Soap12HeaderBinding;
                                    if (s12hb != null)
                                    { //SoapHeader is defined
                                        //returnval += SchemaSearching(servdesc.Types.Schemas[0], shb.Message.Name);
                                        Logger.Text += "Name of header " + s12hb.Message.Name + "\r\n";
                                        string headerType;
                                        //returnval += SchemaSearching(servdesc.Types.Schemas[0], servdesc.Messages[shb.Message.Name].Parts[0].Element.Name);
                                        if (servdesc.Messages[s12hb.Message.Name].Parts[0].Type.IsEmpty)
                                        {
                                            headerType = servdesc.Messages[s12hb.Message.Name].Parts[0].Element.Name;
                                            headerval += SchemaSearching(servdesc.Types.Schemas[0], headerType);
                                        }
                                        else
                                        {   //Currently takes care of only one part in each message
                                            if (s12hb.Message.Name != null)
                                            {
                                                headerval += '<' + s12hb.Message.Name + '>';
                                                for (int i = 0; i < servdesc.Messages[s12hb.Message.Name].Parts.Count; i++)
                                                {
                                                    headerType = servdesc.Messages[s12hb.Message.Name].Parts[i].Type.Name;
                                                    headerval += '<' + servdesc.Messages[s12hb.Message.Name].Parts[i].Name + '>';
                                                    headerval += SchemaSearching(servdesc.Types.Schemas[0], headerType);
                                                    headerval += "</" + servdesc.Messages[s12hb.Message.Name].Parts[i].Name + ">";
                                                }
                                                headerval += "</" + s12hb.Message.Name + '>';
                                            }
                                        }
                                    }
                                }
                                urltosend += s12ob.SoapAction;
                                break;
                                //Logger.Text += urltosend;
                            }
                            else if (hob != null)
                            {
                                urltosend += hob.Location;
                                break;
                                //Logger.Text += urltosend;
                            }
                        }
                    }
                    //Find the right binding
                    Logger.Text   += urltosend;
                    Logger.Text   += "\r\n";
                    targeturl.Text = urltosend;
                }
                //Path to XML schema definition from Operation Name
                //portType -> Operation:Name -> input:message
                // input:message == Message:Name
                //Message:Name -> Part:element
                //Types -> Schema -> Element:Name
                //Part:Element == Element:Name
                Logger.Text += " searching for " + stringNodeName + "\r\n";
                //Logger.Text += " ****** " + SelectedOp.Messages.Count + " ****** ";

                /*for (int i = 0; i < SelectedOp.PortType.Operations.Count; i++)
                 * {
                 *  for (int j = 0; j < SelectedOp.PortType.Operations[i].Messages.Count; j++)//  +", ";
                 *  {
                 *      Logger.Text += SelectedOp.PortType.Operations[i].Messages[j].GetType() + " == ";
                 *      Logger.Text += SelectedOp.PortType.Operations[i].Messages[j].Name + "\r\n";
                 *  }
                 * }*/
                string inputParameterType = null;
                string inputMessageType   = SelectedOp.Messages.Input.Message.Name;
                // TODO: What if there are more than one service descriptions?
                System.Xml.Schema.XmlSchema xmlSchema = servdesc.Types.Schemas[0];
                //What if there are more than one Parts
                if (servdesc.Messages[SelectedOp.Messages.Input.Message.Name].Parts[0].Type.IsEmpty)
                {
                    inputParameterType = servdesc.Messages[SelectedOp.Messages.Input.Message.Name].Parts[0].Element.Name;
                    returnval         += SchemaSearching(xmlSchema, inputParameterType);
                }
                else
                {   //Currently takes care of only one part in each message
                    if (SelectedOp.Messages.Input.Message.Name != null)
                    {
                        returnval += '<' + SelectedOp.Messages.Input.Message.Name + '>';
                        for (int i = 0; i < servdesc.Messages[SelectedOp.Messages.Input.Message.Name].Parts.Count; i++)
                        {
                            inputParameterType = servdesc.Messages[SelectedOp.Messages.Input.Message.Name].Parts[i].Type.Name;
                            returnval         += '<' + servdesc.Messages[SelectedOp.Messages.Input.Message.Name].Parts[i].Name + '>';
                            returnval         += SchemaSearching(xmlSchema, inputParameterType);
                            returnval         += "</" + servdesc.Messages[SelectedOp.Messages.Input.Message.Name].Parts[i].Name + ">";
                        }
                        returnval += "</" + SelectedOp.Messages.Input.Message.Name + '>';
                    }
                }
                Logger.Text += "Selected the method : " + inputMessageType + " that needs " + inputParameterType + " as the param\r\n";
                //Logger.Text += servdesc.Messages[SelectedOp.Messages.Input.Message.Name].Parts[0].Type.Name + " as the param\r\n" ;
                //Logger.Text += "\r\n";

                /*
                 * System.Xml.Schema.XmlSchema xmlSchema = servdesc.Types.Schemas[0];
                 *
                 * foreach (object item in xmlSchema.Items)
                 * {
                 *
                 *  System.Xml.Schema.XmlSchemaElement schemaElement = item as System.Xml.Schema.XmlSchemaElement;
                 *  //Logger.Text += "Ref name = " + schemaElement.RefName + "\r\n";
                 *  //Logger.Text += " -------- " + item.GetType() + "\r\n";
                 *  if (schemaElement != null)
                 *  {
                 *      //Logger.Text += "Ref name = " + schemaElement.RefName + "\r\n";
                 *      if (schemaElement.Name == inputParameterType)
                 *      {
                 *          Logger.Text += "\r\n1. ******************\r\n";
                 *          returnval = xmlGen.GenerateXmlString(schemaElement, xmlSchema);
                 *          Logger.Text += returnval+"\r\n";
                 *          Logger.Text += "\r\n******************\r\n";*/
                /*Logger.Text += "Schema Element Name : " + schemaElement.Name + "\r\n" ;
                 * System.Xml.Schema.XmlSchemaType schemaType = schemaElement.SchemaType;
                 * Logger.Text += "Type of " + schemaElement.Name + " is " + schemaElement.SchemaTypeName + "\r\n";
                 * System.Xml.Schema.XmlSchemaComplexType complexType = schemaType as System.Xml.Schema.XmlSchemaComplexType;
                 * if (complexType != null)
                 * {
                 *  System.Xml.Schema.XmlSchemaParticle particle = complexType.Particle;
                 *  Logger.Text += "Annot  : " + particle.Annotation + "\r\n" ;
                 *  if (particle != null)
                 *  {    //TraverseParticle(complexType.Particle);
                 *      Logger.Text += '<' + complexType.Name + '>' + xmlGen.GenerateXmlString(complexType.Particle) + "</" + complexType.Name + '>';
                 *  }
                 * }
                 * else
                 * {
                 *  //If it's not a Complex Type element
                 *  System.Xml.Schema.XmlSchemaSimpleType simpleType = schemaType as System.Xml.Schema.XmlSchemaSimpleType;
                 *  //simpleType.
                 * }*//*
                 * }
                 * }
                 * else
                 * { //This is a complex Type
                 * System.Xml.Schema.XmlSchemaComplexType complexType = item as System.Xml.Schema.XmlSchemaComplexType;
                 * if (complexType != null)
                 * {
                 * //Logger.Text += "Name : " + complexType.Name + "\r\n" ;
                 * if (complexType.Name == inputParameterType)
                 * {
                 *  Logger.Text += "Complex Type Name : " + complexType.Name + "\r\n";
                 *  System.Xml.Schema.XmlSchemaParticle particle = complexType.Particle;
                 *  System.Xml.Schema.XmlSchemaSequence sequence = particle as System.Xml.Schema.XmlSchemaSequence;
                 *  System.Xml.Schema.XmlSchemaAll schemaall = particle as System.Xml.Schema.XmlSchemaAll;
                 *  if (sequence != null)
                 *  {
                 *      foreach (System.Xml.Schema.XmlSchemaElement childElement in sequence.Items)
                 *      {
                 *          string parameterName = childElement.Name;
                 *          string parameterType = childElement.SchemaTypeName.Name;
                 *          Logger.Text += parameterName + " is a " + parameterType;
                 *          Logger.Text += "\r\n2. ************************************\r\n";
                 *          returnval = '<' + complexType.Name + '>' + xmlGen.GenerateXmlString(childElement, xmlSchema) + "</" + complexType.Name + '>';
                 *          Logger.Text += returnval;
                 *          Logger.Text += "\r\n************************************\r\n";
                 *      }
                 *  }
                 *  else
                 *  {
                 *      if (schemaall != null)
                 *      {
                 *          Logger.Text += "\r\n3. ************************************\r\n";
                 *          returnval = '<' + complexType.Name + '>' + xmlGen.GenerateXmlString(schemaall, xmlSchema) + "</" + complexType.Name + '>';
                 *          Logger.Text += returnval;
                 *          Logger.Text += "\r\n************************************\r\n";
                 *          //TraverseParticle(schemaall);
                 *      }
                 *      else
                 *      {
                 *          System.Xml.Schema.XmlSchemaComplexContent cmplxContent = null;
                 *
                 *          if (cmplxContent != null)
                 *          {
                 *              Logger.Text += cmplxContent.GetType();
                 *              Logger.Text += "\r\n4. ************************************\r\n";
                 *              returnval = '<' + complexType.Name + '>' + xmlGen.GenerateXmlString(cmplxContent, xmlSchema) + "</" + complexType.Name + '>'; ;
                 *              Logger.Text += returnval;
                 *              Logger.Text += "\r\n************************************\r\n";
                 *          }
                 *      }
                 *  }
                 * }
                 * }
                 * else
                 * {
                 * System.Xml.Schema.XmlSchemaSimpleType simpleType = item as System.Xml.Schema.XmlSchemaSimpleType;
                 *
                 * }
                 * }
                 * }*/
                returnval = Encapsulate("xmlns=\"" + servdesc.TargetNamespace + "\"", headerval, returnval);
                return(returnval);

                /*
                 * for (int k = 0; k < schemas.Count; k++)
                 * {
                 *  XmlSchemaObjectCollection xmlelem = schemas[k].Items;
                 *  XmlSchemaObjectEnumerator enumerator = xmlelem.GetEnumerator();
                 *  while (enumerator.MoveNext())
                 *  {
                 *      Logger.Text += " Type of " +enumerator.Current.GetType() + "\r\n" ;
                 *
                 *      if (enumerator.Current is XmlSchemaElement)
                 *      {
                 *          XmlSchemaElement xse = (XmlSchemaElement)enumerator.Current;
                 *          Logger.Text += xse.Name + '=' + xse.SchemaType + ", ";
                 *          //if
                 *          TraverseParticle(xse);
                 *      }
                 *      else
                 *      {
                 *          if (enumerator.Current is XmlSchemaComplexType)
                 *          {
                 *              XmlSchemaComplexType xsct = (XmlSchemaComplexType)enumerator.Current;
                 *              Logger.Text += '\'' + xsct.Name + ": ";
                 *              TraverseParticle(xsct.Particle);
                 *              if (xsct.ContentModel is XmlSchemaSimpleContent)
                 *              {
                 *                  Logger.Text += "Simple; ";
                 *              }
                 *              else
                 *              {
                 *                  //XmlSchemaComplexContent complexContent = (XmlSchemaComplexContent)xsct.ContentModel;
                 *                  if (xsct.ContentModel is XmlSchemaComplexContent)
                 *                  {
                 *                      Logger.Text += "Complex; ";
                 *                  }
                 *              }
                 *              Logger.Text += "\',";
                 *          }
                 *      }
                 *  }
                 *  Logger.Text += "\r\n";
                 * }*/
                //Path to URL from Operation Name
                // Operation ^ Binding:Name
                //Service -> Port:Binding
                // Binding:Name == Port:Binding
                // Port:Name -> (Soapaddressbinding/HttpAddressBinding/Soap12AddressBinding).Location
            }
            catch (XmlException xe)
            {
                Logger.Text += xe.ToString();
            }
            returnval = Encapsulate("xmlns=\"" + servdesc.TargetNamespace + "\"", headerval, returnval);
            return(returnval);
        }
Пример #32
0
        public object CreateDynamicClientProxy(string ResourceUrl)
        {
            if (!ResourceUrl.EndsWith("?wsdl", true, CultureInfo.CurrentCulture))
            {
                ResourceUrl = string.Concat(ResourceUrl, "?wsdl");
            }
            HttpWebRequest httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(ResourceUrl);

            httpWebRequest.Credentials = CredentialCache.DefaultCredentials;
            HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();

            System.IO.Stream stream = httpWebResponse.GetResponseStream();

            //read the downloaded WSDL file
            System.Web.Services.Description.ServiceDescription serviceDescription = System.Web.Services.Description.ServiceDescription.Read(stream);

            Uri mexAddress = new Uri(ResourceUrl);
            MetadataExchangeClientMode mexMode = MetadataExchangeClientMode.HttpGet;

            MetadataExchangeClient mexClient = new MetadataExchangeClient(mexAddress, mexMode);

            mexClient.ResolveMetadataReferences = true;
            MetadataSet metaSet = mexClient.GetMetadata();

            WsdlImporter importer = new WsdlImporter(metaSet);
            Collection <ContractDescription> contracts    = importer.ImportAllContracts();
            ServiceEndpointCollection        allEndpoints = importer.ImportAllEndpoints();

            ServiceContractGenerator generator = new ServiceContractGenerator();
            var endpointsForContracts          = new Dictionary <string, IEnumerable <ServiceEndpoint> >();

            foreach (ContractDescription contract in contracts)
            {
                generator.GenerateServiceContractType(contract);
                // Keep a list of each contract's endpoints
                endpointsForContracts[contract.Name] = allEndpoints.Where(se => se.Contract.Name == contract.Name).ToList();
            }

            if (generator.Errors.Count != 0)
            {
                throw new Exception("There were errors during code compilation.");
            }

            // Generate a code file for the contracts
            CodeGeneratorOptions options = new CodeGeneratorOptions();

            options.BracingStyle = "C";
            CodeDomProvider codeDomProvider = CodeDomProvider.CreateProvider("C#");

            // Compile the code file to an in-memory assembly
            // Don't forget to add all WCF-related assemblies as references
            CompilerParameters compilerParameters = new CompilerParameters(new string[] {
                "System.dll", "System.ServiceModel.dll", "System.Runtime.Serialization.dll"
            });

            compilerParameters.GenerateInMemory = true;

            CompilerResults results = codeDomProvider.CompileAssemblyFromDom(
                compilerParameters, generator.TargetCompileUnit);

            if (results.Errors.Count > 0)
            {
                throw new Exception("There were errors during generated code compilation");
            }
            else
            {
                // Find the proxy type that was generated for the specified contract
                // (identified by a class that implements
                // the contract and ICommunicationbject)
                Type clientProxyType = results.CompiledAssembly.GetTypes().First(
                    t => t.IsClass &&
                    t.GetInterface(serviceDescription.PortTypes[0].Name) != null &&
                    t.GetInterface(typeof(ICommunicationObject).Name) != null);

                // Get the first service endpoint for the contract
                ServiceEndpoint se = endpointsForContracts[serviceDescription.PortTypes[0].Name].First();

                // Create an instance of the proxy
                // Pass the endpoint's binding and address as parameters
                // to the ctor
                object ClientProxyInstance = results.CompiledAssembly.CreateInstance(
                    clientProxyType.Name,
                    false,
                    System.Reflection.BindingFlags.CreateInstance,
                    null,
                    new object[] { se.Binding, se.Address },
                    CultureInfo.CurrentCulture, null);



                //this.Resources.Add(retVal.ToString(), )
                return(ClientProxyInstance);
            }
        }
 private void ReflectBinding(ReflectedBinding reflectedBinding)
 {
     string identifier = XmlConvert.EncodeLocalName(reflectedBinding.bindingAttr.Name);
     string ns = reflectedBinding.bindingAttr.Namespace;
     if (identifier.Length == 0)
     {
         identifier = this.Service.Name + this.ProtocolName;
     }
     if (ns.Length == 0)
     {
         ns = this.ServiceDescription.TargetNamespace;
     }
     WsiProfiles none = WsiProfiles.None;
     if (reflectedBinding.bindingAttr.Location.Length > 0)
     {
         this.portType = null;
         this.binding = null;
     }
     else
     {
         this.bindingServiceDescription = this.GetServiceDescription(ns);
         CodeIdentifiers identifiers = new CodeIdentifiers();
         foreach (System.Web.Services.Description.Binding binding in this.bindingServiceDescription.Bindings)
         {
             identifiers.AddReserved(binding.Name);
         }
         identifier = identifiers.AddUnique(identifier, this.binding);
         this.portType = new System.Web.Services.Description.PortType();
         this.binding = new System.Web.Services.Description.Binding();
         this.portType.Name = identifier;
         this.binding.Name = identifier;
         this.binding.Type = new XmlQualifiedName(this.portType.Name, ns);
         none = reflectedBinding.bindingAttr.ConformsTo & this.ConformsTo;
         if (reflectedBinding.bindingAttr.EmitConformanceClaims && (none != WsiProfiles.None))
         {
             System.Web.Services.Description.ServiceDescription.AddConformanceClaims(this.binding.GetDocumentationElement(), none);
         }
         this.bindingServiceDescription.Bindings.Add(this.binding);
         this.bindingServiceDescription.PortTypes.Add(this.portType);
     }
     if (this.portNames == null)
     {
         this.portNames = new CodeIdentifiers();
         foreach (System.Web.Services.Description.Port port in this.Service.Ports)
         {
             this.portNames.AddReserved(port.Name);
         }
     }
     this.port = new System.Web.Services.Description.Port();
     this.port.Binding = new XmlQualifiedName(identifier, ns);
     this.port.Name = this.portNames.AddUnique(identifier, this.port);
     this.Service.Ports.Add(this.port);
     this.BeginClass();
     if ((reflectedBinding.methodList != null) && (reflectedBinding.methodList.Count > 0))
     {
         foreach (LogicalMethodInfo info in reflectedBinding.methodList)
         {
             this.MoveToMethod(info);
             this.operation = new System.Web.Services.Description.Operation();
             this.operation.Name = XmlConvert.EncodeLocalName(info.Name);
             if ((this.methodAttr.Description != null) && (this.methodAttr.Description.Length > 0))
             {
                 this.operation.Documentation = this.methodAttr.Description;
             }
             this.operationBinding = new System.Web.Services.Description.OperationBinding();
             this.operationBinding.Name = this.operation.Name;
             this.inputMessage = null;
             this.outputMessage = null;
             this.headerMessages = null;
             if (this.ReflectMethod())
             {
                 if (this.inputMessage != null)
                 {
                     this.bindingServiceDescription.Messages.Add(this.inputMessage);
                 }
                 if (this.outputMessage != null)
                 {
                     this.bindingServiceDescription.Messages.Add(this.outputMessage);
                 }
                 if (this.headerMessages != null)
                 {
                     foreach (Message message in this.headerMessages)
                     {
                         this.bindingServiceDescription.Messages.Add(message);
                     }
                 }
                 this.binding.Operations.Add(this.operationBinding);
                 this.portType.Operations.Add(this.operation);
             }
         }
     }
     if (((this.binding != null) && (none == WsiProfiles.BasicProfile1_1)) && (this.ProtocolName == "Soap"))
     {
         BasicProfileViolationCollection violations = new BasicProfileViolationCollection();
         WebServicesInteroperability.AnalyzeBinding(this.binding, this.bindingServiceDescription, this.ServiceDescriptions, violations);
         if (violations.Count > 0)
         {
             throw new InvalidOperationException(System.Web.Services.Res.GetString("WebWsiViolation", new object[] { this.ServiceType.FullName, violations.ToString() }));
         }
     }
     this.EndClass();
 }