示例#1
0
 /// <summary>
 /// Recupera os dados do xml.
 /// </summary>
 /// <param name="reader"></param>
 public void ReadXml(System.Xml.XmlReader reader)
 {
     if (reader.MoveToAttribute("name"))
     {
         Name = reader.ReadContentAsString();
         reader.MoveToElement();
     }
     if (reader.MoveToAttribute("address"))
     {
         Address = reader.ReadContentAsString();
         reader.MoveToElement();
     }
     reader.ReadStartElement();
     while (reader.NodeType != System.Xml.XmlNodeType.EndElement)
     {
         if (reader.Name == "Configuration")
         {
             if (!reader.IsEmptyElement)
             {
                 var config = new ServiceAddressNode();
                 config.ReadXml(reader);
                 Configuration = config;
             }
             else
             {
                 reader.Skip();
             }
         }
         else
         {
             reader.Skip();
         }
     }
     reader.ReadEndElement();
 }
示例#2
0
        /// <summary>
        /// Método usado para recupera o esquema da classe.
        /// </summary>
        /// <param name="xs"></param>
        /// <returns></returns>
        public static XmlSchemaType MySchema(XmlSchemaSet xs)
        {
            var complexType = new XmlSchemaComplexType();

            complexType.Attributes.Add(new XmlSchemaAttribute {
                Name           = "name",
                SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"),
                Use            = XmlSchemaUse.Required
            });
            complexType.Attributes.Add(new XmlSchemaAttribute {
                Name           = "address",
                SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"),
                Use            = XmlSchemaUse.Required
            });
            var sequence             = new XmlSchemaSequence();
            var configurationElement = new XmlSchemaElement()
            {
                Name       = "Configuration",
                SchemaType = ServiceAddressNode.MySchema(null)
            };

            sequence.Items.Add(configurationElement);
            complexType.Particle = sequence;
            return(complexType);
        }
示例#3
0
        /// <summary>
        /// Cria um novo endereço com as dados de configuração informados.
        /// </summary>
        /// <param name="name">Nome do serviço.</param>
        /// <param name="address">Endereço do serviço.</param>
        /// <param name="bindingType"></param>
        /// <param name="contract"></param>
        /// <param name="bindingConfiguration"></param>
        /// <param name="identity"></param>
        /// <param name="customNodes">Nós de customização.</param>
        public ServiceAddress(string name, string address, string bindingType, string contract, ServiceAddressNode bindingConfiguration, ServiceAddressNode identity, ServiceAddressNode[] customNodes)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name");
            }
            else if (string.IsNullOrEmpty(address))
            {
                throw new ArgumentNullException("address");
            }
            this.Name    = name;
            this.Address = address;
            var endPointNode = CreateEndpointNode(name, bindingType, contract, identity);
            var children     = new List <ServiceAddressNode>();

            children.Add(endPointNode);
            children.Add(bindingConfiguration);
            if (customNodes != null)
            {
                var customNode = new ServiceAddressNode("custom", null, customNodes);
                children.Add(customNode);
            }
            if (identity != null)
            {
                children.Add(identity);
            }
            Configuration = new ServiceAddressNode("configuration", null, children.ToArray());
        }
示例#4
0
 /// <summary>
 /// Cria um nód de com a configuração padrão de Binding.
 /// </summary>
 /// <returns></returns>
 public static ServiceAddressNode CreateDefaultBindingConfiguration()
 {
     using (var sr = new System.IO.StringReader(@"<binding name='WSHttpBinding_IIntegrationService' closeTimeout='00:01:00'
             openTimeout='00:01:00' receiveTimeout='00:10:00' sendTimeout='00:01:00'
             bypassProxyOnLocal='false' transactionFlow='false' hostNameComparisonMode='StrongWildcard'
             maxBufferPoolSize='524288' maxReceivedMessageSize='65536'
             messageEncoding='Text' textEncoding='utf-8' useDefaultWebProxy='true'
             allowCookies='false'>
             <readerQuotas maxDepth='32' maxStringContentLength='8192' maxArrayLength='16384'
                           maxBytesPerRead='4096' maxNameTableCharCount='16384' />
             <reliableSession ordered='true' inactivityTimeout='00:10:00' enabled='false' />
             <security mode='None'>
                 <transport clientCredentialType='None' proxyCredentialType='None' realm='' />
                 <message clientCredentialType='UserName' algorithmSuite='Default' />
             </security>
         </binding>"))
     {
         var xmlReader   = System.Xml.XmlReader.Create(sr);
         var xmlDocument = new System.Xml.XmlDocument();
         xmlDocument.Load(xmlReader);
         return(ServiceAddressNode.CreateFromXmlElement(xmlDocument.DocumentElement));
     }
 }
示例#5
0
        /// <summary>
        /// Preenche as propriedades do objeto.
        /// </summary>
        /// <param name="node"></param>
        /// <param name="refObject"></param>
        private static void FillObjectProperties(ServiceAddressNode node, object refObject)
        {
            if (refObject == null)
            {
                return;
            }
            var properties = refObject.GetType().GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public);

            foreach (ServiceAddressParameter i in node.Parameters)
            {
                var pp = properties.Where(f => string.Compare(f.Name, i.Name, true) == 0).FirstOrDefault();
                if (pp == null)
                {
                    continue;
                }
                object value = null;
                try
                {
                    if (pp.PropertyType.IsEnum)
                    {
                        value = Enum.Parse(pp.PropertyType, i.Value);
                    }
                    else if (pp.PropertyType.FullName == "System.Text.Encoding")
                    {
                        value = System.Text.Encoding.GetEncoding(i.Value);
                    }
                    else
                    {
                        var convertMethod = typeof(Convert).GetMethod("To" + pp.PropertyType.Name, new Type[] {
                            typeof(string)
                        });
                        if (convertMethod == null)
                        {
                            convertMethod = pp.PropertyType.GetMethod("Parse", new Type[] {
                                typeof(string)
                            });
                        }
                        if (convertMethod != null)
                        {
                            value = convertMethod.Invoke(null, new object[] {
                                i.Value
                            });
                        }
                        else
                        {
                            continue;
                        }
                    }
                }
                catch (Exception)
                {
                    continue;
                }
                pp.SetValue(refObject, value, null);
            }
            foreach (ServiceAddressNode child in node)
            {
                var pp = properties.Where(f => string.Compare(f.Name, child.Name, true) == 0).FirstOrDefault();
                if (pp == null)
                {
                    continue;
                }
                var value = pp.GetValue(refObject, null);
                if (value == null)
                {
                    var constructor = pp.PropertyType.GetConstructor(new Type[0]);
                    if (constructor == null)
                    {
                        continue;
                    }
                    value = constructor.Invoke(new object[0]);
                }
                FillObjectProperties(child, value);
            }
        }
示例#6
0
 /// <summary>
 /// Cria um novo endereço com as dados de configuração informados.
 /// </summary>
 /// <param name="name">Nome do serviço.</param>
 /// <param name="address">Endereço do serviço.</param>
 /// <param name="bindingType"></param>
 /// <param name="contract"></param>
 /// <param name="bindingConfiguration"></param>
 /// <param name="identity"></param>
 public ServiceAddress(string name, string address, string bindingType, string contract, ServiceAddressNode bindingConfiguration, ServiceAddressNode identity) : this(name, address, bindingType, contract, bindingConfiguration, identity, null)
 {
 }