Pessoal, bom dia.
Gerei a Classe a partir do XSD da nota eletrônica. Gerei a classe também a partir do WSDL.
Segue:
Classe a partir do XSD
using NfeNFCe.infNFe.ide;
using NfeNFCe.util;
using System.Xml.Serialization;
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.6.1055.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://www.portalfiscal.inf.br/nfe")]
[System.Xml.Serialization.XmlRootAttribute("consStatServ", Namespace="http://www.portalfiscal.inf.br/nfe", IsNullable=false)]
public partial class TConsStatServ {
private NfeNFCe.util.TAmb tpAmbField;
private TCodUfIBGE cUFField;
private TConsStatServXServ xServField;
private string versaoField;
/// <remarks/>
public NfeNFCe.util.TAmb tpAmb {
get {
return this.tpAmbField;
}
set {
this.tpAmbField = value;
}
}
/// <remarks/>
public TCodUfIBGE cUF {
get {
return this.cUFField;
}
set {
this.cUFField = value;
}
}
/// <remarks/>
public TConsStatServXServ xServ {
get {
return this.xServField;
}
set {
this.xServField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute(DataType="token")]
public string versao {
get {
return this.versaoField;
}
set {
this.versaoField = value;
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.6.1055.0")]
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://www.portalfiscal.inf.br/nfe")]
public enum TConsStatServXServ {
/// <remarks/>
STATUS,
}
E a classe, a partir do WSDL:
//------------------------------------------------------------------------------
// <auto-generated>
// O código foi gerado por uma ferramenta.
// Versão de Tempo de Execução:4.0.30319.42000
//
// As alterações ao arquivo poderão causar comportamento incorreto e serão perdidas se
// o código for gerado novamente.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Serialization;
//
// This source code was auto-generated by wsdl, Version=4.6.1055.0.
//
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.6.1055.0")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Web.Services.WebServiceBindingAttribute(Name="NFeStatusServico4Soap", Namespace="http://www.portalfiscal.inf.br/nfe/wsdl/NfeStatusServico2")]
public partial class NFeStatusServico4 : System.Web.Services.Protocols.SoapHttpClientProtocol {
private System.Threading.SendOrPostCallback nfeStatusServicoNFOperationCompleted;
/// <remarks/>
public NFeStatusServico4() {
this.Url = "https://www.sefazvirtual.fazenda.gov.br/NFeStatusServico4/NFeStatusServico4.asmx";
}
/// <remarks/>
public event nfeStatusServicoNFCompletedEventHandler nfeStatusServicoNFCompleted;
/// <remarks/>
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://www.portalfiscal.inf.br/nfe/wsdl/NfeStatusServico2/nfeStatusServicoNF", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Bare)]
[return: System.Xml.Serialization.XmlElementAttribute(Namespace="http://www.portalfiscal.inf.br/nfe/wsdl/NfeStatusServico2")]
public System.Xml.XmlNode nfeStatusServicoNF([System.Xml.Serialization.XmlElementAttribute(Namespace="http://www.portalfiscal.inf.br/nfe/wsdl/NfeStatusServico2")] string nfeDadosMsg) {
object[] results = this.Invoke("nfeStatusServicoNF", new object[] {
nfeDadosMsg});
return ((System.Xml.XmlNode)(results[0]));
}
/// <remarks/>
public System.IAsyncResult BeginnfeStatusServicoNF(string nfeDadosMsg, System.AsyncCallback callback, object asyncState) {
return this.BeginInvoke("nfeStatusServicoNF", new object[] {
nfeDadosMsg}, callback, asyncState);
}
/// <remarks/>
public System.Xml.XmlNode EndnfeStatusServicoNF(System.IAsyncResult asyncResult) {
object[] results = this.EndInvoke(asyncResult);
return ((System.Xml.XmlNode)(results[0]));
}
/// <remarks/>
public void nfeStatusServicoNFAsync(string nfeDadosMsg) {
this.nfeStatusServicoNFAsync(nfeDadosMsg, null);
}
/// <remarks/>
public void nfeStatusServicoNFAsync(string nfeDadosMsg, object userState) {
if ((this.nfeStatusServicoNFOperationCompleted == null)) {
this.nfeStatusServicoNFOperationCompleted = new System.Threading.SendOrPostCallback(this.OnnfeStatusServicoNFOperationCompleted);
}
this.InvokeAsync("nfeStatusServicoNF", new object[] {
nfeDadosMsg}, this.nfeStatusServicoNFOperationCompleted, userState);
}
private void OnnfeStatusServicoNFOperationCompleted(object arg) {
if ((this.nfeStatusServicoNFCompleted != null)) {
System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
this.nfeStatusServicoNFCompleted(this, new nfeStatusServicoNFCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
}
}
/// <remarks/>
public new void CancelAsync(object userState) {
base.CancelAsync(userState);
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.6.1055.0")]
public delegate void nfeStatusServicoNFCompletedEventHandler(object sender, nfeStatusServicoNFCompletedEventArgs e);
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.6.1055.0")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
public partial class nfeStatusServicoNFCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs {
private object[] results;
internal nfeStatusServicoNFCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) :
base(exception, cancelled, userState) {
this.results = results;
}
/// <remarks/>
public System.Xml.XmlNode Result {
get {
this.RaiseExceptionIfNecessary();
return ((System.Xml.XmlNode)(this.results[0]));
}
}
}
E aí o método de serviço que faz a consulta de Status
public TRetConsStatServ NfeStatusServico()
{
try
{
//Obtém Certificado Digital
X509Certificate certificado = null;
if(empresa.tipoCertificado == 1)
certificado = CertificadoDigital.SelecionarCertificadoA1(empresa.certificado, empresa.senhaCertificado);
else if (empresa.tipoCertificado == 3)
certificado = CertificadoDigital.SelecionarCertificadoA3(empresa.certificado, empresa.senhaCertificado);
//Objeto do Webservice
//NfeStatusServico2 ws2 = new NfeStatusServico2();
NFeStatusServico4 ws4 = new NFeStatusServico4();
//Url Destino
//ws2.Url = Conversoes.ObterUrlTipoServico(empresa, "STATUS");
ws4.Url = "https://homologacao.nfe.fazenda.sp.gov.br/ws/nfestatusservico4.asmx";
//Version SOAP
ws4.SoapVersion = System.Web.Services.Protocols.SoapProtocolVersion.Soap12;
//Cabecalho
//ws2.nfeCabecMsgValue = new nfeCabecMsg();
//ws2.nfeCabecMsgValue.cUF = Convert.ToString(cidade.codigoEstado);
//ws2.nfeCabecMsgValue.versaoDados = "3.10";
//Vinculação Certificado Digital do WebService
//ws2.ClientCertificates.Add(certificado);
ws4.ClientCertificates.Add(certificado);
//Montagem do objeto
TConsStatServ c = new TConsStatServ();
c.cUF = Conversoes.ObterEstado(cidade);
c.tpAmb = Conversoes.ObterTipoAmbiente(empresa);
c.versao = "4.00";//Ou 3.10
c.xServ = TConsStatServXServ.STATUS;
//Conversao do objeto em XML
String xmlConteudo = FuncoesXml.ClasseParaXmlString(c);
//Validação
//ValidarStatusServico.validar(empresa, xmlConteudo);
//Encapular XML no XmlDocumento para envio ao serviço (Somente na 3.10)
XmlDocument myXMLDoc = new XmlDocument();
myXMLDoc.PreserveWhitespace = true;
myXMLDoc.LoadXml(xmlConteudo);
//Chamada ao servico de Status NFe e conversão do retorno
//XmlNode respostaXml = ws2.nfeStatusServicoNF2(myXMLDoc);
XmlNode respostaXml4 = ws4.nfeStatusServicoNF(xmlConteudo);
//Conversão da Resposta do WebService
//TRetConsStatServ retorno2 = FuncoesXml.XmlStringParaClasse<TRetConsStatServ>(respostaXml.OuterXml);
TRetConsStatServ retorno4 = FuncoesXml.XmlStringParaClasse<TRetConsStatServ>(respostaXml4.OuterXml);
return retorno4;
//return retorno2;
}catch(Exception e)
{
throw new Exception(e.Message);
}
}
Na versão 3.10 funciona normalmente.
Na 4 não.
Ele retorna o erro:
{“Unable to handle request. The action ‘http://www.portalfiscal.inf.br/nfe/wsdl/NfeStatusServico2/nfeStatusServicoNF’ was not recognized.”}
Se alguém puder me ajudar por favor.
Obrigado.