Пример #1
0
        internal void SetHeaderValue(object ob, SoapHeader header)
        {
            object value = header;

            if (Custom && HeaderType.IsArray)
            {
                SoapUnknownHeader   uheader = header as SoapUnknownHeader;
                SoapUnknownHeader[] array   = (SoapUnknownHeader[])GetHeaderValue(ob);
                if (array == null || array.Length == 0)
                {
                    value = new SoapUnknownHeader[] { uheader };
                }
                else
                {
                    SoapUnknownHeader[] newArray = new SoapUnknownHeader [array.Length + 1];
                    Array.Copy(array, newArray, array.Length);
                    newArray [array.Length] = uheader;
                    value = newArray;
                }
            }

            if (member is PropertyInfo)
            {
                ((PropertyInfo)member).SetValue(ob, value, null);
            }
            else
            {
                ((FieldInfo)member).SetValue(ob, value);
            }
        }
Пример #2
0
 public static void SetHeaderMembers(SoapHeaderCollection headers, object target, SoapHeaderMapping[] mappings, SoapHeaderDirection direction, bool client)
 {
     bool[] flagArray = new bool[headers.Count];
     if (mappings != null)
     {
         for (int j = 0; j < mappings.Length; j++)
         {
             SoapHeaderMapping mapping = mappings[j];
             if ((mapping.direction & direction) != 0)
             {
                 if (mapping.repeats)
                 {
                     ArrayList list = new ArrayList();
                     for (int k = 0; k < headers.Count; k++)
                     {
                         SoapHeader header = headers[k];
                         if (!flagArray[k] && mapping.headerType.IsAssignableFrom(header.GetType()))
                         {
                             list.Add(header);
                             flagArray[k] = true;
                         }
                     }
                     MemberHelper.SetValue(mapping.memberInfo, target, list.ToArray(mapping.headerType));
                 }
                 else
                 {
                     bool flag = false;
                     for (int m = 0; m < headers.Count; m++)
                     {
                         SoapHeader header2 = headers[m];
                         if (!flagArray[m] && mapping.headerType.IsAssignableFrom(header2.GetType()))
                         {
                             if (flag)
                             {
                                 header2.DidUnderstand = false;
                             }
                             else
                             {
                                 flag = true;
                                 MemberHelper.SetValue(mapping.memberInfo, target, header2);
                                 flagArray[m] = true;
                             }
                         }
                     }
                 }
             }
         }
     }
     for (int i = 0; i < flagArray.Length; i++)
     {
         if (!flagArray[i])
         {
             SoapHeader header3 = headers[i];
             if (header3.MustUnderstand && !header3.DidUnderstand)
             {
                 throw new SoapHeaderException(System.Web.Services.Res.GetString("WebCannotUnderstandHeader", new object[] { GetHeaderElementName(header3) }), new XmlQualifiedName("MustUnderstand", "http://schemas.xmlsoap.org/soap/envelope/"));
             }
         }
     }
 }
Пример #3
0
        static int FindMapping(SoapHeaderMapping[] mappings, SoapHeader header, SoapHeaderDirection direction)
        {
            if (mappings == null || mappings.Length == 0)
            {
                return(-1);
            }
            Type headerType = header.GetType();

            for (int i = 0; i < mappings.Length; i++)
            {
                SoapHeaderMapping mapping = mappings[i];
                if ((mapping.direction & direction) == 0)
                {
                    continue;
                }
                if (!mapping.custom)
                {
                    continue;
                }
                if (mapping.headerType.IsAssignableFrom(headerType))
                {
                    return(i);
                }
            }
            return(-1);
        }
Пример #4
0
 public void Insert(int index, SoapHeader header)
 {
     if (index < 0 || index > Count)
     {
         throw new ArgumentOutOfRangeException();
     }
     List.Insert(index, header);
 }
Пример #5
0
 private static string GetHeaderElementName(SoapHeader header)
 {
     if (header is SoapUnknownHeader)
     {
         return(((SoapUnknownHeader)header).Element.LocalName);
     }
     return(GetHeaderElementName(header.GetType()));
 }
 private static string GetHeaderElementName(SoapHeader header)
 {
     if (header is SoapUnknownHeader)
     {
         return ((SoapUnknownHeader) header).Element.LocalName;
     }
     return GetHeaderElementName(header.GetType());
 }
Пример #7
0
 public static void EnsureHeadersUnderstood(SoapHeaderCollection headers)
 {
     for (int i = 0; i < headers.Count; i++)
     {
         SoapHeader header = headers[i];
         if (header.MustUnderstand && !header.DidUnderstand)
         {
             throw new SoapHeaderException(System.Web.Services.Res.GetString("WebCannotUnderstandHeader", new object[] { GetHeaderElementName(header) }), new XmlQualifiedName("MustUnderstand", "http://schemas.xmlsoap.org/soap/envelope/"));
         }
     }
 }
Пример #8
0
 internal static void EnsureHeadersUnderstood(SoapHeaderCollection headers)
 {
     for (int i = 0; i < headers.Count; i++)
     {
         SoapHeader header = headers[i];
         if (header.MustUnderstand && !header.DidUnderstand)
         {
             throw new SoapHeaderException(Res.GetString(Res.WebCannotUnderstandHeader, GetHeaderElementName(header)),
                                           new XmlQualifiedName(Soap.MustUnderstandCode, Soap.Namespace));
         }
     }
 }
Пример #9
0
 internal void CollectHeaders(object target, HeaderInfo[] headers, SoapHeaderDirection direction)
 {
     Headers.Clear();
     foreach (HeaderInfo hi in headers)
     {
         if ((hi.Direction & direction) != 0 && !hi.Custom)
         {
             SoapHeader headerVal = hi.GetHeaderValue(target) as SoapHeader;
             if (headerVal != null)
             {
                 Headers.Add(headerVal);
             }
         }
     }
 }
 private static int FindMapping(SoapHeaderMapping[] mappings, SoapHeader header, SoapHeaderDirection direction)
 {
     if ((mappings != null) && (mappings.Length != 0))
     {
         Type c = header.GetType();
         for (int i = 0; i < mappings.Length; i++)
         {
             SoapHeaderMapping mapping = mappings[i];
             if ((((mapping.direction & direction) != 0) && mapping.custom) && mapping.headerType.IsAssignableFrom(c))
             {
                 return i;
             }
         }
     }
     return -1;
 }
Пример #11
0
 private static int FindMapping(SoapHeaderMapping[] mappings, SoapHeader header, SoapHeaderDirection direction)
 {
     if ((mappings != null) && (mappings.Length != 0))
     {
         Type c = header.GetType();
         for (int i = 0; i < mappings.Length; i++)
         {
             SoapHeaderMapping mapping = mappings[i];
             if ((((mapping.direction & direction) != 0) && mapping.custom) && mapping.headerType.IsAssignableFrom(c))
             {
                 return(i);
             }
         }
     }
     return(-1);
 }
Пример #12
0
		internal void SetHeaderValue (object ob, SoapHeader header)
		{
			object value = header;
			if (Custom && HeaderType.IsArray)
			{
				SoapUnknownHeader uheader = header as SoapUnknownHeader;
				SoapUnknownHeader[] array = (SoapUnknownHeader[]) GetHeaderValue (ob);
				if (array == null || array.Length == 0) {
					value = new SoapUnknownHeader[] { uheader };
				}
				else {
					SoapUnknownHeader[] newArray = new SoapUnknownHeader [array.Length+1];
					Array.Copy (array, newArray, array.Length);
					newArray [array.Length] = uheader;
					value = newArray;
				}
			}
			
			if (member is PropertyInfo)
				((PropertyInfo) member).SetValue (ob, value, null);
			else
				((FieldInfo) member).SetValue (ob, value);
		}
Пример #13
0
        public object[] GetHeaderValueArray(SoapHeaderDirection dir, SoapHeaderCollection headers)
        {
            HeaderInfo[] headerInfos = GetHeaders(dir);
            if (headerInfos == null)
            {
                return(null);
            }

            object[] hs = new object [headerInfos.Length];

            for (int n = 0; n < headers.Count; n++)
            {
                SoapHeader h = headers[n];
                Type       t = h.GetType();
                for (int i = 0; i < headerInfos.Length; i++)
                {
                    if (headerInfos [i].HeaderType == t)
                    {
                        hs [i] = h;
                    }
                }
            }
            return(hs);
        }
Пример #14
0
 internal static void SetHeaderMembers(SoapHeaderCollection headers, object target, SoapHeaderMapping[] mappings, SoapHeaderDirection direction, bool client)
 {
     bool[] headerHandled = new bool[headers.Count];
     for (int i = 0; i < mappings.Length; i++)
     {
         SoapHeaderMapping mapping = mappings[i];
         if ((mapping.direction & direction) == 0)
         {
             continue;
         }
         if (mapping.repeats)
         {
             ArrayList list = new ArrayList();
             for (int j = 0; j < headers.Count; j++)
             {
                 SoapHeader header = headers[j];
                 if (headerHandled[j])
                 {
                     continue;
                 }
                 if (mapping.headerType.IsAssignableFrom(header.GetType()))
                 {
                     list.Add(header);
                     headerHandled[j] = true;
                 }
             }
             MemberHelper.SetValue(mapping.memberInfo, target, list.ToArray(mapping.headerType));
         }
         else
         {
             bool handled = false;
             for (int j = 0; j < headers.Count; j++)
             {
                 SoapHeader header = headers[j];
                 if (headerHandled[j])
                 {
                     continue;
                 }
                 if (mapping.headerType.IsAssignableFrom(header.GetType()))
                 {
                     if (handled)
                     {
                         header.DidUnderstand = false;
                         continue;
                     }
                     handled = true;
                     MemberHelper.SetValue(mapping.memberInfo, target, header);
                     headerHandled[j] = true;
                 }
             }
         }
     }
     if (client)
     {
         for (int i = 0; i < headerHandled.Length; i++)
         {
             if (!headerHandled[i])
             {
                 SoapHeader header = headers[i];
                 if (header.MustUnderstand && !header.DidUnderstand)
                 {
                     throw new SoapHeaderException(Res.GetString(Res.WebCannotUnderstandHeader, GetHeaderElementName(header)),
                                                   new XmlQualifiedName(Soap.MustUnderstandCode, Soap.Namespace));
                 }
             }
         }
     }
 }
Пример #15
0
        internal void ReadHeaders(XmlReader reader, XmlSerializer serializer, SoapHeaderCollection headers, SoapHeaderMapping[] mappings, SoapHeaderDirection direction, string envelopeNs, string encodingStyle)
        {
            reader.MoveToContent();
            if (!reader.IsStartElement(Soap.Header, envelopeNs))
            {
                return;
            }
            if (reader.IsEmptyElement)
            {
                reader.Skip(); return;
            }

            this.unknownHeaders      = new SoapHeaderCollection();
            this.unreferencedHeaders = new SoapHeaderCollection();
            // thread hash code is used to differentiate between deserializations in event callbacks
            this.currentThread = Thread.CurrentThread.GetHashCode();
            this.envelopeNs    = envelopeNs;

            XmlElementEventHandler         unknownHandler      = new XmlElementEventHandler(this.OnUnknownElement);
            UnreferencedObjectEventHandler unreferencedHandler = new UnreferencedObjectEventHandler(this.OnUnreferencedObject);

            serializer.UnknownElement     += unknownHandler;
            serializer.UnreferencedObject += unreferencedHandler;

            reader.ReadStartElement();
            reader.MoveToContent();

            // SOAP12: not using encodingStyle
            //object[] headerValues = (object[])serializer.Deserialize(reader, encodingStyle);
            object[] headerValues = (object[])serializer.Deserialize(reader);
            for (int i = 0; i < headerValues.Length; i++)
            {
                if (headerValues[i] != null)
                {
                    SoapHeader header = (SoapHeader)headerValues[i];
                    header.DidUnderstand = true;
                    headers.Add(header);
                }
            }

            serializer.UnknownElement     -= unknownHandler;
            serializer.UnreferencedObject -= unreferencedHandler;
            this.currentThread             = 0;
            this.envelopeNs = null;

            foreach (SoapHeader header in this.unreferencedHeaders)
            {
                headers.Add(header);
            }
            this.unreferencedHeaders = null;

            foreach (SoapHeader header in this.unknownHeaders)
            {
                headers.Add(header);
            }
            this.unknownHeaders = null;

            while (reader.NodeType == XmlNodeType.Whitespace)
            {
                reader.Skip();
            }

            if (reader.NodeType == XmlNodeType.None)
            {
                reader.Skip();
            }
            else
            {
                reader.ReadEndElement();
            }
        }
Пример #16
0
        internal static void WriteHeaders(XmlWriter writer, XmlSerializer serializer, SoapHeaderCollection headers, SoapHeaderMapping[] mappings, SoapHeaderDirection direction, bool isEncoded, string defaultNs, bool serviceDefaultIsEncoded, string envelopeNs)
        {
            if (headers.Count == 0)
            {
                return;
            }
            if (isEncoded && writer is XmlSpecialTextWriter)
            {
                ((XmlSpecialTextWriter)writer).EncodeIds = true;
            }
            writer.WriteStartElement(Soap.Header, envelopeNs);
            // SOAP12: always soap 1.1, not using encodingStyle;
            //SoapProtocolVersion version;
            SoapProtocolVersion version = SoapProtocolVersion.Soap11;
            // SOAP12: not using encodingStyle

            /*string encodingStyle;
             * if (envelopeNs == Soap12.Namespace) {
             *  version = SoapProtocolVersion.Soap12;
             *  encodingStyle = Soap12.Encoding;
             * }
             * else {
             *  version = SoapProtocolVersion.Soap11;
             *  encodingStyle = Soap.Encoding;
             * }*/

            int       unknownHeaderCount = 0;
            ArrayList otherHeaders       = new ArrayList();

            SoapHeader[] headerArray = new SoapHeader[mappings.Length];
            bool[]       headerSet   = new bool[headerArray.Length];
            for (int i = 0; i < headers.Count; i++)
            {
                SoapHeader header = headers[i];
                if (header == null)
                {
                    continue;
                }
                int headerPosition;
                header.version = version;
                if (header is SoapUnknownHeader)
                {
                    otherHeaders.Add(header);
                    unknownHeaderCount++;
                }
                else if ((headerPosition = FindMapping(mappings, header, direction)) >= 0 && !headerSet[headerPosition])
                {
                    headerArray[headerPosition] = header;
                    headerSet[headerPosition]   = true;
                }
                else
                {
                    otherHeaders.Add(header);
                }
            }
            int otherHeaderCount = otherHeaders.Count - unknownHeaderCount;

            if (isEncoded && otherHeaderCount > 0)
            {
                SoapHeader[] newHeaderArray = new SoapHeader[mappings.Length + otherHeaderCount];
                headerArray.CopyTo(newHeaderArray, 0);

                // fill in the non-statically known headers (otherHeaders) starting after the statically-known ones
                int count = mappings.Length;
                for (int i = 0; i < otherHeaders.Count; i++)
                {
                    if (!(otherHeaders[i] is SoapUnknownHeader))
                    {
                        newHeaderArray[count++] = (SoapHeader)otherHeaders[i];
                    }
                }

                headerArray = newHeaderArray;
            }

            // SOAP12: not using encodingStyle
            //serializer.Serialize(writer, headerArray, null, isEncoded ? encodingStyle : null);
            serializer.Serialize(writer, headerArray, null);

            foreach (SoapHeader header in otherHeaders)
            {
                if (header is SoapUnknownHeader)
                {
                    SoapUnknownHeader unknown = (SoapUnknownHeader)header;
                    if (unknown.Element != null)
                    {
                        unknown.Element.WriteTo(writer);
                    }
                }
                else if (!isEncoded)   // encoded headers already appended to members mapping
                {
                    string ns = SoapReflector.GetLiteralNamespace(defaultNs, serviceDefaultIsEncoded);
                    new XmlSerializer(header.GetType(), ns).Serialize(writer, header);
                }
            }

            // reset the soap version
            for (int i = 0; i < headers.Count; i++)
            {
                SoapHeader header = headers[i];
                if (header != null)
                {
                    header.version = SoapProtocolVersion.Default;
                }
            }

            writer.WriteEndElement();
            writer.Flush();

            if (isEncoded && writer is XmlSpecialTextWriter)
            {
                ((XmlSpecialTextWriter)writer).EncodeIds = false;
            }
        }
 public void CopyTo(SoapHeader[] array, int index)
 {
     base.List.CopyTo(array, index);
 }
Пример #18
0
 static int FindMapping(SoapHeaderMapping[] mappings, SoapHeader header, SoapHeaderDirection direction) {
     if (mappings == null || mappings.Length == 0) return -1;
     Type headerType = header.GetType();
     for (int i = 0; i < mappings.Length; i++) {
         SoapHeaderMapping mapping = mappings[i];
         if ((mapping.direction & direction) == 0) continue;
         if (!mapping.custom) continue;
         if (mapping.headerType.IsAssignableFrom(headerType)) {
             return i;
         }
     }
     return -1;
 }
        public static System.Web.Services.Protocols.SoapHttpClientProtocol ClientProxyFactory(
            Parametro oParam,
            TServico TipoServico)
        {
            String ClassName = "";

            try
            {
                string nomeClasse = string.Empty;
                //buscar nome do metodo pelo tServico
                foreach (ClasseServico atr in TipoServico.GetType().GetField(TipoServico.ToString()).GetCustomAttributes(typeof(ClasseServico), false))
                {
                    if (String.IsNullOrEmpty(atr.value))
                    {
                        throw new Exception("Serviço não esta associado com nenhuma classe cliente.");
                    }
                    nomeClasse = atr.value;
                }

                //particularidades
                if (oParam.UF == TCodUfIBGE.Bahia && oParam.tipoEmissao == TNFeInfNFeIdeTpEmis.Normal)//Bahia
                {
                    if (TipoServico == TServico.Status && oParam.versao == VersaoXML.NFe_v310)
                    {
                        nomeClasse = "NfeStatusServico";
                    }

                    if (TipoServico == TServico.Consulta && oParam.versao == VersaoXML.NFe_v310)
                    {
                        nomeClasse = "NfeConsulta";
                    }

                    if (TipoServico == TServico.Inutilizacao && oParam.versao == VersaoXML.NFe_v310)
                    {
                        nomeClasse = "NfeInutilizacao";
                    }
                }

                ClassName =
                    "RDI.NFe2.Business."
                    + GetAmbWebService(oParam, TipoServico) + "."
                    + TipoServico.ToString() + ".";

                String headerClassName = ClassName + "nfeCabecMsg";
                ClassName += nomeClasse;

                Type classType = GetMyAssembly().GetType(ClassName);

                if (classType == null)
                {
                    throw new Exception("Não foi possível definir o tipo do cliente de webservice. #ClientProxyFactory");
                }

                System.Web.Services.Protocols.SoapHttpClientProtocol oServico =
                    (System.Web.Services.Protocols.SoapHttpClientProtocol)System.Activator.CreateInstance(classType);

                if (TipoServico != TServico.ConsultaDFe) //ConsultaDFe não tem header
                {
                    #region Instancia cabecalho

                    Type headerClassType = GetMyAssembly().GetType(headerClassName);

                    if (headerClassType == null)
                    {
                        throw new Exception("Não foi possível definir o tipo do header do cliente de webservice. #ClientProxyFactory");
                    }

                    System.Web.Services.Protocols.SoapHeader oCabecalho =
                        (System.Web.Services.Protocols.SoapHeader)System.Activator.CreateInstance(headerClassType);


                    if ((TipoServico == TServico.ManifestacaoDestinatario) || //ManifestacaoDestinatario deverá usar AN 91
                        (TipoServico == TServico.DownloadNF))                 //DownloadNF deverá usar AN 91
                    {
                        oCabecalho.GetType().GetProperty("cUF").SetValue(oCabecalho, "91", null);
                    }
                    else
                    {
                        oCabecalho.GetType().GetProperty("cUF").SetValue(oCabecalho,
                                                                         ((System.Xml.Serialization.XmlEnumAttribute)oParam.UF.GetType().GetField(
                                                                              oParam.UF.ToString()).GetCustomAttributes(
                                                                              typeof(System.Xml.Serialization.XmlEnumAttribute), false)[0]).Name,
                                                                         null);
                    }
                    string versao = oParam.versaoDados;

                    //particularidade para ConsSitNFe usando v200
                    if (TipoServico == TServico.Consulta && oParam.versao == VersaoXML.NFe_v200)
                    {
                        versao = "2.01";
                    }

                    //Particularidade para RecepcaoEvento
                    if (TipoServico == TServico.RecepcaoEvento)
                    {
                        versao = oParam.versaoDadosEventos;
                    }

                    //particularidade para consultaCadastro
                    if (TipoServico == TServico.Cadastro)
                    {
                        versao = "2.00";
                    }

                    //particularidade para manifestacao destinatario
                    if (TipoServico == TServico.ManifestacaoDestinatario || TipoServico == TServico.DownloadNF)
                    {
                        versao = "1.00";
                    }

                    oCabecalho.GetType().GetProperty("versaoDados").SetValue(oCabecalho, versao, null);
                    oServico.GetType().GetProperty("nfeCabecMsgValue").SetValue(oServico, oCabecalho, null);
                    #endregion
                }
                return(oServico);
            }
            catch (Exception ex)
            {
                throw new Exception("ClientProxyFactory # não foi possível criar o cliente (" + ClassName + ") para acesso aos webservices da SEFAZ. InnerException: " + ex.Message);
            }
        }
 public int Add(SoapHeader header)
 {
     return base.List.Add(header);
 }
Пример #21
0
 /// <include file='doc\SoapHeaders.uex' path='docs/doc[@for="SoapHeaderCollection.Add"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public int Add(SoapHeader header)
 {
     return(List.Add(header));
 }
Пример #22
0
 public int Add(SoapHeader header)
 {
     Insert(Count, header);
     return(Count - 1);
 }
 public void Insert(int index, SoapHeader header)
 {
     base.List.Insert(index, header);
 }
Пример #24
0
        public string ReadHeaders(XmlReader reader, XmlSerializer serializer, SoapHeaderCollection headers, SoapHeaderMapping[] mappings, SoapHeaderDirection direction, string envelopeNS, string encodingStyle, bool checkRequiredHeaders)
        {
            string headerElementName = null;

            reader.MoveToContent();
            if (!reader.IsStartElement("Header", envelopeNS))
            {
                if ((checkRequiredHeaders && (mappings != null)) && (mappings.Length > 0))
                {
                    headerElementName = GetHeaderElementName(mappings[0].headerType);
                }
                return(headerElementName);
            }
            if (reader.IsEmptyElement)
            {
                reader.Skip();
                return(headerElementName);
            }
            this.unknownHeaders      = new SoapHeaderCollection();
            this.unreferencedHeaders = new SoapHeaderCollection();
            this.currentThread       = Thread.CurrentThread.GetHashCode();
            this.envelopeNS          = envelopeNS;
            int depth = reader.Depth;

            reader.ReadStartElement();
            reader.MoveToContent();
            XmlDeserializationEvents events = new XmlDeserializationEvents {
                OnUnknownElement     = new XmlElementEventHandler(this.OnUnknownElement),
                OnUnreferencedObject = new UnreferencedObjectEventHandler(this.OnUnreferencedObject)
            };
            TraceMethod caller = Tracing.On ? new TraceMethod(this, "ReadHeaders", new object[0]) : null;

            if (Tracing.On)
            {
                Tracing.Enter(Tracing.TraceId("TraceReadHeaders"), caller, new TraceMethod(serializer, "Deserialize", new object[] { reader, encodingStyle }));
            }
            object[] objArray = (object[])serializer.Deserialize(reader, encodingStyle, events);
            if (Tracing.On)
            {
                Tracing.Exit(Tracing.TraceId("TraceReadHeaders"), caller);
            }
            for (int i = 0; i < objArray.Length; i++)
            {
                if (objArray[i] != null)
                {
                    SoapHeader header = (SoapHeader)objArray[i];
                    header.DidUnderstand = true;
                    headers.Add(header);
                }
                else if (checkRequiredHeaders && (headerElementName == null))
                {
                    headerElementName = GetHeaderElementName(mappings[i].headerType);
                }
            }
            this.currentThread = 0;
            this.envelopeNS    = null;
            foreach (SoapHeader header2 in this.unreferencedHeaders)
            {
                headers.Add(header2);
            }
            this.unreferencedHeaders = null;
            foreach (SoapHeader header3 in this.unknownHeaders)
            {
                headers.Add(header3);
            }
            this.unknownHeaders = null;
            while ((depth < reader.Depth) && reader.Read())
            {
            }
            if (reader.NodeType == XmlNodeType.EndElement)
            {
                reader.Read();
            }
            return(headerElementName);
        }
Пример #25
0
 /// <include file='doc\SoapHeaders.uex' path='docs/doc[@for="SoapHeaderCollection.Insert"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public void Insert(int index, SoapHeader header)
 {
     List.Insert(index, header);
 }
		public void Insert (int index, SoapHeader header)
		{
			if (index < 0 || index > Count)
				throw new ArgumentOutOfRangeException ();
			List.Insert (index, header);
		}
		public int Add (SoapHeader header)
		{
			Insert (Count, header);
			return (Count - 1);
		}
Пример #28
0
        // return first missing header name;
        public string ReadHeaders(XmlReader reader, XmlSerializer serializer, SoapHeaderCollection headers, SoapHeaderMapping[] mappings, SoapHeaderDirection direction, string envelopeNS, string encodingStyle, bool checkRequiredHeaders)
        {
            string missingHeader = null;

            reader.MoveToContent();
            if (!reader.IsStartElement(Soap.Element.Header, envelopeNS))
            {
                if (checkRequiredHeaders && mappings != null && mappings.Length > 0)
                {
                    missingHeader = GetHeaderElementName(mappings[0].headerType);
                }
                return(missingHeader);
            }
            if (reader.IsEmptyElement)
            {
                reader.Skip(); return(missingHeader);
            }

            this.unknownHeaders      = new SoapHeaderCollection();
            this.unreferencedHeaders = new SoapHeaderCollection();
            // thread hash code is used to differentiate between deserializations in event callbacks
            this.currentThread = Thread.CurrentThread.GetHashCode();
            this.envelopeNS    = envelopeNS;

            int depth = reader.Depth;

            reader.ReadStartElement();
            reader.MoveToContent();

            XmlDeserializationEvents events = new XmlDeserializationEvents();

            events.OnUnknownElement     = new XmlElementEventHandler(this.OnUnknownElement);
            events.OnUnreferencedObject = new UnreferencedObjectEventHandler(this.OnUnreferencedObject);

            TraceMethod caller = Tracing.On ? new TraceMethod(this, "ReadHeaders") : null;

            if (Tracing.On)
            {
                Tracing.Enter(Tracing.TraceId(Res.TraceReadHeaders), caller, new TraceMethod(serializer, "Deserialize", reader, encodingStyle));
            }
            object[] headerValues = (object[])serializer.Deserialize(reader, encodingStyle, events);
            if (Tracing.On)
            {
                Tracing.Exit(Tracing.TraceId(Res.TraceReadHeaders), caller);
            }
            for (int i = 0; i < headerValues.Length; i++)
            {
                if (headerValues[i] != null)
                {
                    SoapHeader header = (SoapHeader)headerValues[i];
                    header.DidUnderstand = true;
                    headers.Add(header);
                }
                else if (checkRequiredHeaders)
                {
                    // run time check for R2738 A MESSAGE MUST include all soapbind:headers specified on a wsdl:input or wsdl:output of a wsdl:operationwsdl:binding that describes it.
                    if (missingHeader == null)
                    {
                        missingHeader = GetHeaderElementName(mappings[i].headerType);
                    }
                }
            }
            this.currentThread = 0;
            this.envelopeNS    = null;

            foreach (SoapHeader header in this.unreferencedHeaders)
            {
                headers.Add(header);
            }
            this.unreferencedHeaders = null;

            foreach (SoapHeader header in this.unknownHeaders)
            {
                headers.Add(header);
            }
            this.unknownHeaders = null;

            // Consume soap:Body and soap:Envelope closing tags
            while (depth < reader.Depth && reader.Read())
            {
                // Nothing, just read on
            }
            // consume end tag
            if (reader.NodeType == XmlNodeType.EndElement)
            {
                reader.Read();
            }

            return(missingHeader);
        }
Пример #29
0
 public bool Contains(SoapHeader header)
 {
     return(List.Contains(header));
 }
 public static void WriteHeaders(XmlWriter writer, XmlSerializer serializer, SoapHeaderCollection headers, SoapHeaderMapping[] mappings, SoapHeaderDirection direction, bool isEncoded, string defaultNS, bool serviceDefaultIsEncoded, string envelopeNS)
 {
     if (headers.Count != 0)
     {
         SoapProtocolVersion version;
         string str;
         writer.WriteStartElement("Header", envelopeNS);
         if (envelopeNS == "http://www.w3.org/2003/05/soap-envelope")
         {
             version = SoapProtocolVersion.Soap12;
             str = "http://www.w3.org/2003/05/soap-encoding";
         }
         else
         {
             version = SoapProtocolVersion.Soap11;
             str = "http://schemas.xmlsoap.org/soap/encoding/";
         }
         int num = 0;
         ArrayList list = new ArrayList();
         SoapHeader[] o = new SoapHeader[mappings.Length];
         bool[] flagArray = new bool[o.Length];
         for (int i = 0; i < headers.Count; i++)
         {
             SoapHeader header = headers[i];
             if (header != null)
             {
                 header.version = version;
                 if (header is SoapUnknownHeader)
                 {
                     list.Add(header);
                     num++;
                 }
                 else
                 {
                     int num3;
                     if (((num3 = FindMapping(mappings, header, direction)) >= 0) && !flagArray[num3])
                     {
                         o[num3] = header;
                         flagArray[num3] = true;
                     }
                     else
                     {
                         list.Add(header);
                     }
                 }
             }
         }
         int num4 = list.Count - num;
         if (isEncoded && (num4 > 0))
         {
             SoapHeader[] array = new SoapHeader[mappings.Length + num4];
             o.CopyTo(array, 0);
             int length = mappings.Length;
             for (int k = 0; k < list.Count; k++)
             {
                 if (!(list[k] is SoapUnknownHeader))
                 {
                     array[length++] = (SoapHeader) list[k];
                 }
             }
             o = array;
         }
         TraceMethod caller = Tracing.On ? new TraceMethod(typeof(SoapHeaderHandling), "WriteHeaders", new object[0]) : null;
         if (Tracing.On)
         {
             object[] args = new object[5];
             args[0] = writer;
             args[1] = o;
             args[3] = isEncoded ? str : null;
             args[4] = "h_";
             Tracing.Enter(Tracing.TraceId("TraceWriteHeaders"), caller, new TraceMethod(serializer, "Serialize", args));
         }
         serializer.Serialize(writer, o, null, isEncoded ? str : null, "h_");
         if (Tracing.On)
         {
             Tracing.Exit(Tracing.TraceId("TraceWriteHeaders"), caller);
         }
         foreach (SoapHeader header2 in list)
         {
             if (header2 is SoapUnknownHeader)
             {
                 SoapUnknownHeader header3 = (SoapUnknownHeader) header2;
                 if (header3.Element != null)
                 {
                     header3.Element.WriteTo(writer);
                 }
             }
             else if (!isEncoded)
             {
                 string literalNamespace = SoapReflector.GetLiteralNamespace(defaultNS, serviceDefaultIsEncoded);
                 XmlSerializer target = new XmlSerializer(header2.GetType(), literalNamespace);
                 if (Tracing.On)
                 {
                     Tracing.Enter(Tracing.TraceId("TraceWriteHeaders"), caller, new TraceMethod(target, "Serialize", new object[] { writer, header2 }));
                 }
                 target.Serialize(writer, header2);
                 if (Tracing.On)
                 {
                     Tracing.Exit(Tracing.TraceId("TraceWriteHeaders"), caller);
                 }
             }
         }
         for (int j = 0; j < headers.Count; j++)
         {
             SoapHeader header4 = headers[j];
             if (header4 != null)
             {
                 header4.version = SoapProtocolVersion.Default;
             }
         }
         writer.WriteEndElement();
         writer.Flush();
     }
 }
Пример #31
0
 public int IndexOf(SoapHeader header)
 {
     return(List.IndexOf(header));
 }
Пример #32
0
 public static void WriteHeaders(XmlWriter writer, XmlSerializer serializer, SoapHeaderCollection headers, SoapHeaderMapping[] mappings, SoapHeaderDirection direction, bool isEncoded, string defaultNS, bool serviceDefaultIsEncoded, string envelopeNS)
 {
     if (headers.Count != 0)
     {
         SoapProtocolVersion version;
         string str;
         writer.WriteStartElement("Header", envelopeNS);
         if (envelopeNS == "http://www.w3.org/2003/05/soap-envelope")
         {
             version = SoapProtocolVersion.Soap12;
             str     = "http://www.w3.org/2003/05/soap-encoding";
         }
         else
         {
             version = SoapProtocolVersion.Soap11;
             str     = "http://schemas.xmlsoap.org/soap/encoding/";
         }
         int          num       = 0;
         ArrayList    list      = new ArrayList();
         SoapHeader[] o         = new SoapHeader[mappings.Length];
         bool[]       flagArray = new bool[o.Length];
         for (int i = 0; i < headers.Count; i++)
         {
             SoapHeader header = headers[i];
             if (header != null)
             {
                 header.version = version;
                 if (header is SoapUnknownHeader)
                 {
                     list.Add(header);
                     num++;
                 }
                 else
                 {
                     int num3;
                     if (((num3 = FindMapping(mappings, header, direction)) >= 0) && !flagArray[num3])
                     {
                         o[num3]         = header;
                         flagArray[num3] = true;
                     }
                     else
                     {
                         list.Add(header);
                     }
                 }
             }
         }
         int num4 = list.Count - num;
         if (isEncoded && (num4 > 0))
         {
             SoapHeader[] array = new SoapHeader[mappings.Length + num4];
             o.CopyTo(array, 0);
             int length = mappings.Length;
             for (int k = 0; k < list.Count; k++)
             {
                 if (!(list[k] is SoapUnknownHeader))
                 {
                     array[length++] = (SoapHeader)list[k];
                 }
             }
             o = array;
         }
         TraceMethod caller = Tracing.On ? new TraceMethod(typeof(SoapHeaderHandling), "WriteHeaders", new object[0]) : null;
         if (Tracing.On)
         {
             object[] args = new object[5];
             args[0] = writer;
             args[1] = o;
             args[3] = isEncoded ? str : null;
             args[4] = "h_";
             Tracing.Enter(Tracing.TraceId("TraceWriteHeaders"), caller, new TraceMethod(serializer, "Serialize", args));
         }
         serializer.Serialize(writer, o, null, isEncoded ? str : null, "h_");
         if (Tracing.On)
         {
             Tracing.Exit(Tracing.TraceId("TraceWriteHeaders"), caller);
         }
         foreach (SoapHeader header2 in list)
         {
             if (header2 is SoapUnknownHeader)
             {
                 SoapUnknownHeader header3 = (SoapUnknownHeader)header2;
                 if (header3.Element != null)
                 {
                     header3.Element.WriteTo(writer);
                 }
             }
             else if (!isEncoded)
             {
                 string        literalNamespace = SoapReflector.GetLiteralNamespace(defaultNS, serviceDefaultIsEncoded);
                 XmlSerializer target           = new XmlSerializer(header2.GetType(), literalNamespace);
                 if (Tracing.On)
                 {
                     Tracing.Enter(Tracing.TraceId("TraceWriteHeaders"), caller, new TraceMethod(target, "Serialize", new object[] { writer, header2 }));
                 }
                 target.Serialize(writer, header2);
                 if (Tracing.On)
                 {
                     Tracing.Exit(Tracing.TraceId("TraceWriteHeaders"), caller);
                 }
             }
         }
         for (int j = 0; j < headers.Count; j++)
         {
             SoapHeader header4 = headers[j];
             if (header4 != null)
             {
                 header4.version = SoapProtocolVersion.Default;
             }
         }
         writer.WriteEndElement();
         writer.Flush();
     }
 }
Пример #33
0
        public static void WriteHeaders(XmlWriter writer, XmlSerializer serializer, SoapHeaderCollection headers, SoapHeaderMapping[] mappings, SoapHeaderDirection direction, bool isEncoded, string defaultNS, bool serviceDefaultIsEncoded, string envelopeNS)
        {
            if (headers.Count == 0)
            {
                return;
            }
            writer.WriteStartElement(Soap.Element.Header, envelopeNS);
            SoapProtocolVersion version;
            string encodingStyle;

            if (envelopeNS == Soap12.Namespace)
            {
                version       = SoapProtocolVersion.Soap12;
                encodingStyle = Soap12.Encoding;
            }
            else
            {
                version       = SoapProtocolVersion.Soap11;
                encodingStyle = Soap.Encoding;
            }

            int       unknownHeaderCount = 0;
            ArrayList otherHeaders       = new ArrayList();

            SoapHeader[] headerArray = new SoapHeader[mappings.Length];
            bool[]       headerSet   = new bool[headerArray.Length];
            for (int i = 0; i < headers.Count; i++)
            {
                SoapHeader header = headers[i];
                if (header == null)
                {
                    continue;
                }
                int headerPosition;
                header.version = version;
                if (header is SoapUnknownHeader)
                {
                    otherHeaders.Add(header);
                    unknownHeaderCount++;
                }
                else if ((headerPosition = FindMapping(mappings, header, direction)) >= 0 && !headerSet[headerPosition])
                {
                    headerArray[headerPosition] = header;
                    headerSet[headerPosition]   = true;
                }
                else
                {
                    otherHeaders.Add(header);
                }
            }
            int otherHeaderCount = otherHeaders.Count - unknownHeaderCount;

            if (isEncoded && otherHeaderCount > 0)
            {
                SoapHeader[] newHeaderArray = new SoapHeader[mappings.Length + otherHeaderCount];
                headerArray.CopyTo(newHeaderArray, 0);

                // fill in the non-statically known headers (otherHeaders) starting after the statically-known ones
                int count = mappings.Length;
                for (int i = 0; i < otherHeaders.Count; i++)
                {
                    if (!(otherHeaders[i] is SoapUnknownHeader))
                    {
                        newHeaderArray[count++] = (SoapHeader)otherHeaders[i];
                    }
                }

                headerArray = newHeaderArray;
            }

            TraceMethod caller = Tracing.On ? new TraceMethod(typeof(SoapHeaderHandling), "WriteHeaders") : null;

            if (Tracing.On)
            {
                Tracing.Enter(Tracing.TraceId(Res.TraceWriteHeaders), caller, new TraceMethod(serializer, "Serialize", writer, headerArray, null, isEncoded ? encodingStyle : null, "h_"));
            }
            serializer.Serialize(writer, headerArray, null, isEncoded ? encodingStyle : null, "h_");
            if (Tracing.On)
            {
                Tracing.Exit(Tracing.TraceId(Res.TraceWriteHeaders), caller);
            }

            foreach (SoapHeader header in otherHeaders)
            {
                if (header is SoapUnknownHeader)
                {
                    SoapUnknownHeader unknown = (SoapUnknownHeader)header;
                    if (unknown.Element != null)
                    {
                        unknown.Element.WriteTo(writer);
                    }
                }
                else if (!isEncoded)   // encoded headers already appended to members mapping
                {
                    string        ns = SoapReflector.GetLiteralNamespace(defaultNS, serviceDefaultIsEncoded);
                    XmlSerializer headerSerializer = new XmlSerializer(header.GetType(), ns);

                    if (Tracing.On)
                    {
                        Tracing.Enter(Tracing.TraceId(Res.TraceWriteHeaders), caller, new TraceMethod(headerSerializer, "Serialize", writer, header));
                    }
                    headerSerializer.Serialize(writer, header);
                    if (Tracing.On)
                    {
                        Tracing.Exit(Tracing.TraceId(Res.TraceWriteHeaders), caller);
                    }
                }
            }

            // reset the soap version
            for (int i = 0; i < headers.Count; i++)
            {
                SoapHeader header = headers[i];
                if (header != null)
                {
                    header.version = SoapProtocolVersion.Default;
                }
            }

            writer.WriteEndElement();
            writer.Flush();
        }
 public bool Contains(SoapHeader header)
 {
     return base.List.Contains(header);
 }
Пример #35
0
 public void Remove(SoapHeader header)
 {
     List.Remove(header);
 }
 public int IndexOf(SoapHeader header)
 {
     return base.List.IndexOf(header);
 }
Пример #37
0
        public static void WriteHeaders(XmlWriter writer, XmlSerializer serializer, SoapHeaderCollection headers, SoapHeaderMapping[] mappings, SoapHeaderDirection direction, bool isEncoded, string defaultNS, bool serviceDefaultIsEncoded, string envelopeNS) {
            if (headers.Count == 0) return;
            writer.WriteStartElement(Soap.Element.Header, envelopeNS);
            SoapProtocolVersion version;
            string encodingStyle;
            if (envelopeNS == Soap12.Namespace) {
                version = SoapProtocolVersion.Soap12;
                encodingStyle = Soap12.Encoding;
            }
            else {
                version = SoapProtocolVersion.Soap11;
                encodingStyle = Soap.Encoding;
            }

            int unknownHeaderCount = 0;
            ArrayList otherHeaders = new ArrayList();
            SoapHeader[] headerArray = new SoapHeader[mappings.Length];
            bool[] headerSet = new bool[headerArray.Length];
            for (int i = 0; i < headers.Count; i++) {
                SoapHeader header = headers[i];
                if (header == null) continue;
                int headerPosition;
                header.version = version;
                if (header is SoapUnknownHeader) {
                    otherHeaders.Add(header);
                    unknownHeaderCount++;
                }
                else if ((headerPosition = FindMapping(mappings, header, direction)) >= 0 && !headerSet[headerPosition]) {
                    headerArray[headerPosition] = header;
                    headerSet[headerPosition] = true;
                }
                else {
                    otherHeaders.Add(header);
                }
            }
            int otherHeaderCount = otherHeaders.Count - unknownHeaderCount;
            if (isEncoded && otherHeaderCount > 0) {
                SoapHeader[] newHeaderArray = new SoapHeader[mappings.Length + otherHeaderCount];
                headerArray.CopyTo(newHeaderArray, 0);

                // fill in the non-statically known headers (otherHeaders) starting after the statically-known ones
                int count = mappings.Length;
                for (int i = 0; i < otherHeaders.Count; i++) {
                    if (!(otherHeaders[i] is SoapUnknownHeader))
                        newHeaderArray[count++] = (SoapHeader)otherHeaders[i];
                }

                headerArray = newHeaderArray;
            }

            TraceMethod caller = Tracing.On ? new TraceMethod(typeof(SoapHeaderHandling), "WriteHeaders") : null;
            if (Tracing.On) Tracing.Enter(Tracing.TraceId(Res.TraceWriteHeaders), caller, new TraceMethod(serializer, "Serialize", writer, headerArray, null, isEncoded ? encodingStyle : null, "h_"));
            serializer.Serialize(writer, headerArray, null, isEncoded ? encodingStyle : null, "h_");
            if (Tracing.On) Tracing.Exit(Tracing.TraceId(Res.TraceWriteHeaders), caller);

            foreach (SoapHeader header in otherHeaders) {
                if (header is SoapUnknownHeader) {
                    SoapUnknownHeader unknown = (SoapUnknownHeader)header;
                    if (unknown.Element != null)
                        unknown.Element.WriteTo(writer);
                }
                else if (!isEncoded) { // encoded headers already appended to members mapping
                    string ns = SoapReflector.GetLiteralNamespace(defaultNS, serviceDefaultIsEncoded);
                    XmlSerializer headerSerializer = new XmlSerializer(header.GetType(), ns);

                    if (Tracing.On) Tracing.Enter(Tracing.TraceId(Res.TraceWriteHeaders), caller, new TraceMethod(headerSerializer, "Serialize", writer, header));
                    headerSerializer.Serialize(writer, header);
                    if (Tracing.On) Tracing.Exit(Tracing.TraceId(Res.TraceWriteHeaders), caller);
                }
            }

            // reset the soap version
            for (int i = 0; i < headers.Count; i++) {
                SoapHeader header = headers[i];
                if (header != null)
                    header.version = SoapProtocolVersion.Default;
            }

            writer.WriteEndElement();
            writer.Flush();
        }
 public void Remove(SoapHeader header)
 {
     base.List.Remove(header);
 }
Пример #39
0
        public static System.Web.Services.Protocols.SoapHttpClientProtocol ClientProxyFactory(Parametro oParam, TService TipoServico)
        {
            if (oParam.versao == VersaoXML.NFe_v400 &&
                (TipoServico == TService.Autorizacao ||
                 TipoServico == TService.RetAutorizacao ||
                 TipoServico == TService.ConsultaProtocolo ||
                 TipoServico == TService.Inutilizacao ||
                 TipoServico == TService.RecepcaoEvento ||
                 TipoServico == TService.Cadastro ||
                 TipoServico == TService.Status))
            {
                if (oParam.conexao == TipoConexao.NFe)
                {
                    var    tServer  = TServer.NaoMapeado;
                    string Ambiente = oParam.tipoAmbiente.ToString();

                    var AtendidoPor = (NFe_AtendidoPor)typeof(TCodUfIBGE).GetField(oParam.UF.ToString()).GetCustomAttributes(typeof(NFe_AtendidoPor), false).FirstOrDefault();
                    if (AtendidoPor == null)
                    {
                        throw new Exception("UF não está associado com nenhum Servidor Autorizador.");
                    }

                    if (oParam.tipoEmissao == TNFeInfNFeIdeTpEmis.ContingenciaSVCAN || oParam.tipoEmissao == TNFeInfNFeIdeTpEmis.ContingenciaSVCRS)
                    {
                        tServer = AtendidoPor.ServidorAutorizadorSVC;
                    }
                    else
                    {
                        tServer = AtendidoPor.ServidorAutorizador;
                    }

                    return(RDI.NFe2.Webservices.WSUtils.SoapHttpClientFactory(tServer, Ambiente, TipoServico));
                }
                else if (oParam.conexao == TipoConexao.NFCe)
                {
                    var AtendidoPor = (NFCe_AtendidoPor)typeof(TCodUfIBGE).GetField(oParam.UF.ToString()).GetCustomAttributes(typeof(NFCe_AtendidoPor), false).FirstOrDefault();
                    if (AtendidoPor == null)
                    {
                        throw new Exception("UF não está associado com nenhum Servidor Autorizador.");
                    }

                    string Ambiente = oParam.tipoAmbiente.ToString();

                    return(RDI.NFe2.Webservices.WSUtils.SoapHttpClientFactory(AtendidoPor.ServidorAutorizador, Ambiente, TipoServico));
                }
                else
                {
                    throw new Exception("UF não está associado com nenhum Servidor Autorizador.");
                }
            }
            else
            {
                //TODO : enviar todos os webservices ativos para o projeto rdi.nfe.webservices após a desativação da versao 3.10

                String ClassName = "";
                try
                {
                    string nomeClasse = string.Empty;
                    //buscar nome do metodo pelo tServico
                    foreach (ClasseServico atr in TipoServico.GetType().GetField(TipoServico.ToString()).GetCustomAttributes(typeof(ClasseServico), false))
                    {
                        if (String.IsNullOrEmpty(atr.NomeClasse))
                        {
                            throw new Exception("Serviço não esta associado com nenhuma classe cliente.");
                        }
                        nomeClasse = atr.NomeClasse;
                    }

                    //particularidades
                    if (oParam.UF == TCodUfIBGE.Bahia && oParam.tipoEmissao == TNFeInfNFeIdeTpEmis.Normal && oParam.conexao == TipoConexao.NFe)//Bahia
                    {
                        if (TipoServico == TService.Status && oParam.versao == VersaoXML.NFe_v310)
                        {
                            nomeClasse = "NfeStatusServico";
                        }

                        if (TipoServico == TService.ConsultaProtocolo && oParam.versao == VersaoXML.NFe_v310)
                        {
                            nomeClasse = "NfeConsulta";
                        }

                        if (TipoServico == TService.Inutilizacao && oParam.versao == VersaoXML.NFe_v310)
                        {
                            nomeClasse = "NfeInutilizacao";
                        }
                    }

                    var subNamespace = TipoServico.ToString();

                    if (TipoServico == TService.ConsultaProtocolo)
                    {
                        subNamespace = "Consulta";
                    }
                    else if (TipoServico == TService.ManifestacaoDestinatario || TipoServico == TService.EPEC)
                    {
                        subNamespace = "Eventos";
                    }

                    ClassName = "RDI.NFe2.Business." + GetAmbWebService(oParam, TipoServico) + "." + subNamespace + ".";

                    String headerClassName = ClassName + "nfeCabecMsg";
                    ClassName += nomeClasse;

                    Type classType = GetMyAssembly().GetType(ClassName);

                    if (classType == null)
                    {
                        throw new Exception("Não foi possível definir o tipo do cliente de webservice. #ClientProxyFactory");
                    }

                    System.Web.Services.Protocols.SoapHttpClientProtocol oServico =
                        (System.Web.Services.Protocols.SoapHttpClientProtocol)System.Activator.CreateInstance(classType);

                    if (TipoServico != TService.ConsultaDFe) //ConsultaDFe não tem header
                    {
                        #region Instancia cabecalho

                        Type headerClassType = GetMyAssembly().GetType(headerClassName);

                        if (headerClassType == null)
                        {
                            throw new Exception("Não foi possível definir o tipo do header do cliente de webservice. #ClientProxyFactory");
                        }

                        System.Web.Services.Protocols.SoapHeader oCabecalho =
                            (System.Web.Services.Protocols.SoapHeader)System.Activator.CreateInstance(headerClassType);


                        if ((TipoServico == TService.ManifestacaoDestinatario) || //ManifestacaoDestinatario deverá usar AN 91
                            (TipoServico == TService.DownloadNF) ||               //DownloadNF deverá usar AN 91
                            (TipoServico == TService.EPEC))                       //DownloadNF deverá usar AN 91
                        {
                            oCabecalho.GetType().GetProperty("cUF").SetValue(oCabecalho, "91", null);
                        }
                        else
                        {
                            oCabecalho.GetType().GetProperty("cUF").SetValue(oCabecalho,
                                                                             ((System.Xml.Serialization.XmlEnumAttribute)oParam.UF.GetType().GetField(
                                                                                  oParam.UF.ToString()).GetCustomAttributes(
                                                                                  typeof(System.Xml.Serialization.XmlEnumAttribute), false)[0]).Name,
                                                                             null);
                        }
                        string versao = oParam.versaoDados;

                        //particularidade para ConsSitNFe usando v200
                        if (TipoServico == TService.ConsultaProtocolo && oParam.versao == VersaoXML.NFe_v200)
                        {
                            versao = "2.01";
                        }

                        //Particularidade para RecepcaoEvento
                        if (TipoServico == TService.RecepcaoEvento)
                        {
                            versao = oParam.versaoDadosEventos;
                        }

                        //particularidade para consultaCadastro
                        if (TipoServico == TService.Cadastro)
                        {
                            versao = "2.00";
                        }

                        //particularidade para manifestacao destinatario
                        if (TipoServico == TService.ManifestacaoDestinatario || TipoServico == TService.EPEC || TipoServico == TService.DownloadNF)
                        {
                            versao = "1.00";
                        }

                        oCabecalho.GetType().GetProperty("versaoDados").SetValue(oCabecalho, versao, null);
                        oServico.GetType().GetProperty("nfeCabecMsgValue").SetValue(oServico, oCabecalho, null);
                        #endregion
                    }
                    return(oServico);
                }
                catch (Exception ex)
                {
                    throw new Exception("ClientProxyFactory # não foi possível criar o cliente (" + ClassName + ") para acesso aos webservices da SEFAZ. InnerException: " + ex.Message);
                }
            }
        }