Pessoal
Boa tarde, depois de algumas mudanças em meu código, estou com o seguinte erro :
Estava querendo mandar o cabeçario não por serialização tem como ?
<retConsStatServ versao="2.00" xmlns="http://www.portalfiscal.inf.br/nfe"><tpAmb>1</tpAmb><verAplic>SP_NFE_PL_006q</verAplic><cStat>242</cStat><xMotivo>Rejeição: Cabeçalho - Falha no Schema XML</xMotivo><cUF>35</cUF><dhRecbto>2014-12-01T12:59:47</dhRecbto></retConsStatServ>"
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
Try
Dim cl_Consulta_Status As New NFe_Statusxa1.NFeStatusxa1
cl_Consulta_Status.Consulta_Statusxa1()
Catch ex As Exception
End Try
End Sub
Imports System.Xml
Imports System.Security
Imports System.Security.Cryptography
Imports System.Security.Cryptography.X509Certificates
Imports System.Windows.Forms
Imports System.Globalization
Imports nfelib.ws_nfeStatusa1
Namespace NFe_Statusxa1
Public Class NFeStatusxa1
Public Sub Consulta_Statusxa1()
Dim result As XmlNode = Nothing
Try
Dim cert As X509Certificate2 = SelecionarCertificadox()
Dim xmlns As New Serialization.XmlSerializerNamespaces
Dim xmlDados As New XmlDocument
Dim xmlCab As New XmlDocument
Dim nfeStatusServ As New NfeStatusServico2a1
nfeStatusServ.ClientCertificates.Add(cert)
xmlCab.LoadXml("<?xml version=""1.0"" encoding=""UTF-8""?><nfeCabecMsg xmlns=""http://www.portalfiscal.inf.br/nfe"" versao=""2.00""><versaoDados>2.00</versaoDados><cUF>35</cUF></nfeCabecMsg>")
xmlDados.LoadXml("<?xml version=""1.0"" encoding=""utf-8""?><consStatServ xmlns=""http://www.portalfiscal.inf.br/nfe"" versao=""2.00""><tpAmb>1</tpAmb><cUF>35</cUF><xServ>STATUS</xServ></consStatServ>")
result = nfeStatusServ.nfeStatusServicoNF2(xmlCab, xmlDados)
Dim cTeste As String = String.Empty
cTeste = "ok"
Console.WriteLine(result.OuterXml)
Console.Read()
MsgBox(result.OuterXml)
Catch ex As Exception
MsgBox(result.OuterXml)
End Try
End Sub
Public Shared Function SelecionarCertificadox() As X509Certificate2
'Listando certificados
Dim store As New X509Store(StoreName.My)
store.Open(OpenFlags.ReadOnly Or OpenFlags.OpenExistingOnly)
Dim validCertificates As X509Certificate2Collection = store.Certificates.Find(X509FindType.FindByTimeValid, Now, True)
If validCertificates.Count <= 0 Then Return Nothing
Dim selected As X509Certificate2Collection = X509Certificate2UI.SelectFromCollection(validCertificates, "Selecione um certificado", "", X509SelectionFlag.SingleSelection)
If selected.Count > 0 Then
IO.File.AppendAllText("certificate.selection.log", Now.ToString("[yyyy-MM-dd HH:mm:ss]") & "Last public key selected: " & vbNewLine & selected(0).GetPublicKeyString & vbNewLine)
Return selected(0)
End If
Return Nothing
End Function
End Class
End Namespace
Option Strict On
Option Explicit On
Imports System.ComponentModel
Imports System.Diagnostics
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Xml.Serialization
Namespace ws_nfeStatusa1
<System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services", "2.0.50727.3053"), _
System.Diagnostics.DebuggerStepThroughAttribute(), _
System.ComponentModel.DesignerCategoryAttribute("code"), _
System.Web.Services.WebServiceBindingAttribute(Name:="NfeStatusServico2Soap12", [Namespace]:="http://www.portalfiscal.inf.br/nfe/wsdl/NfeStatusServico2")> _
Partial Public Class NfeStatusServico2a1
Inherits System.Web.Services.Protocols.SoapHttpClientProtocol
Private nfeStatusServicoNF2OperationCompleted As System.Threading.SendOrPostCallback
Private useDefaultCredentialsSetExplicitly As Boolean
''' <remarks/>
Public Sub New()
MyBase.New()
Me.SoapVersion = System.Web.Services.Protocols.SoapProtocolVersion.Soap12
Me.Url = "https://nfe.fazenda.sp.gov.br/nfeweb/services/nfestatusservico2.asmx"
If (Me.IsLocalFileSystemWebService(Me.Url) = True) Then
Me.UseDefaultCredentials = True
Me.useDefaultCredentialsSetExplicitly = False
Else
Me.useDefaultCredentialsSetExplicitly = True
End If
End Sub
Public Shadows Property Url() As String
Get
Return MyBase.Url
End Get
Set(ByVal value As String)
If (((Me.IsLocalFileSystemWebService(MyBase.Url) = True) _
AndAlso (Me.useDefaultCredentialsSetExplicitly = False)) _
AndAlso (Me.IsLocalFileSystemWebService(value) = False)) Then
MyBase.UseDefaultCredentials = False
End If
MyBase.Url = value
End Set
End Property
Public Shadows Property UseDefaultCredentials() As Boolean
Get
Return MyBase.UseDefaultCredentials
End Get
Set(ByVal value As Boolean)
MyBase.UseDefaultCredentials = value
Me.useDefaultCredentialsSetExplicitly = True
End Set
End Property
''' <remarks/>
Public Event nfeStatusServicoNF2Completed As nfeStatusServicoNF2CompletedEventHandler
'''<remarks/>
<System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://www.portalfiscal.inf.br/nfe/wsdl/NfeStatusServico2/nfeStatusServicoNF2", Use:=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle:=System.Web.Services.Protocols.SoapParameterStyle.Bare)> _
Public Function nfeStatusServicoNF2(<System.Xml.Serialization.XmlElementAttribute([Namespace]:="http://www.portalfiscal.inf.br/nfe/wsdl/NfeStatusServico2")> ByVal nfeCabecMsg As System.Xml.XmlNode, <System.Xml.Serialization.XmlElementAttribute([Namespace]:="http://www.portalfiscal.inf.br/nfe/wsdl/NfeStatusServico2")> ByVal nfeDadosMsg As System.Xml.XmlNode) As <System.Xml.Serialization.XmlElementAttribute([Namespace]:="http://www.portalfiscal.inf.br/nfe/wsdl/NfeStatusServico2")> System.Xml.XmlNode
Dim results() As Object = Me.Invoke("nfeStatusServicoNF2", New Object() {nfeCabecMsg, nfeDadosMsg})
Return CType(results(0), System.Xml.XmlNode)
End Function
'''<remarks/>
Public Overloads Sub nfeStatusServicoNF2Async(ByVal nfeCabecMsg As System.Xml.XmlNode, ByVal nfeDadosMsg As System.Xml.XmlNode)
Me.nfeStatusServicoNF2Async(nfeCabecMsg, nfeDadosMsg, Nothing)
End Sub
'''<remarks/>
Public Overloads Sub nfeStatusServicoNF2Async(ByVal nfeCabecMsg As System.Xml.XmlNode, ByVal nfeDadosMsg As System.Xml.XmlNode, ByVal userState As Object)
If (Me.nfeStatusServicoNF2OperationCompleted Is Nothing) Then
Me.nfeStatusServicoNF2OperationCompleted = AddressOf Me.OnnfeStatusServicoNF2OperationCompleted
End If
Me.InvokeAsync("nfeStatusServicoNF2", New Object() {nfeCabecMsg, nfeDadosMsg}, Me.nfeStatusServicoNF2OperationCompleted, userState)
End Sub
Private Sub OnnfeStatusServicoNF2OperationCompleted(ByVal arg As Object)
If (Not (Me.nfeStatusServicoNF2CompletedEvent) Is Nothing) Then
Dim invokeArgs As System.Web.Services.Protocols.InvokeCompletedEventArgs = CType(arg, System.Web.Services.Protocols.InvokeCompletedEventArgs)
RaiseEvent nfeStatusServicoNF2Completed(Me, New nfeStatusServicoNF2CompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState))
End If
End Sub
'''<remarks/>
Public Shadows Sub CancelAsync(ByVal userState As Object)
MyBase.CancelAsync(userState)
End Sub
Private Function IsLocalFileSystemWebService(ByVal url As String) As Boolean
If ((url Is Nothing) _
OrElse (url Is String.Empty)) Then
Return False
End If
Dim wsUri As System.Uri = New System.Uri(url)
If ((wsUri.Port >= 1024) _
AndAlso (String.Compare(wsUri.Host, "localHost", System.StringComparison.OrdinalIgnoreCase) = 0)) Then
Return True
End If
Return False
End Function
End Class
''<remarks/>
<System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services", "2.0.50727.3053")> _
Public Delegate Sub nfeStatusServicoNF2CompletedEventHandler(ByVal sender As Object, ByVal e As nfeStatusServicoNF2CompletedEventArgs)
'''<remarks/>
<System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services", "2.0.50727.3053"), _
System.Diagnostics.DebuggerStepThroughAttribute(), _
System.ComponentModel.DesignerCategoryAttribute("code")> _
Partial Public Class nfeStatusServicoNF2CompletedEventArgs
Inherits System.ComponentModel.AsyncCompletedEventArgs
Private results() As Object
Friend Sub New(ByVal results() As Object, ByVal exception As System.Exception, ByVal cancelled As Boolean, ByVal userState As Object)
MyBase.New(exception, cancelled, userState)
Me.results = results
End Sub
'''<remarks/>
Public ReadOnly Property Result() As System.Xml.XmlNode
Get
Me.RaiseExceptionIfNecessary()
Return CType(Me.results(0), System.Xml.XmlNode)
End Get
End Property
End Class
End Namespace