Bom Dia a Todos
Estou fazendo integração da NFSe com Prefeitura Rio de Janeiro - RJ
Consegui conectar ao WebService [https://notacarioca.rio.gov.br/WSNacional/nfse.asmx?wsdl] e também consumir o serviço [http://notacarioca.rio.gov.br/GerarNfse], porém ao enviar o xml na tag esta retornando erro: O servidor remoto retornou um erro: (400) Solicitação Incorreta.
Abaixo vou colocar mais detalhes, quem puder ajudar:
Programação VB .NET
URL_Wsdl = "https://notacarioca.rio.gov.br/WSNacional/nfse.asmx?wsdl"
SoapAction = "http://notacarioca.rio.gov.br/GerarNfse"
strXML = xmlNFSe_GerarNFSe(cls.Base(Page), Request.QueryString("nf_id"))
strRequisicao = "<?xml version=""1.0"" encoding=""utf-8""?>" &
"<soapenv:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" " &
"xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" " &
"xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"">" &
"<soapenv:Body>" &
"<GerarNfseRequest xmlns=""http://notacarioca.rio.gov.br/"">" &
"<inputXML>" & strXML & "</inputXML>" &
"</GerarNfseRequest>" &
"</soapenv:Body>" &
"</soapenv:Envelope>"
strErroNfeVa = wsNFSe(URL_Wsdl, SoapAction, strRequisicao, strRetorno)
Protected Function wsNFSe(strURL_Wsdl As String,
strSoapAction As String,
strRequisicao As String,
ByRef strRetorno As String) As String
Try
'***********************************************************************************************
'WebService NFSe (INICIO)
'***********************************************************************************************
'Informações Certificado
'***********************************************************************************************
Dim certificado() As String = cls.CertificadoDigital().Split("|")
Dim Cert As X509Certificate2 = New X509Certificate2(certificado(1), certificado(2)) 'Parametro Adicional X509KeyStorageFlags.MachineKeySet
Dim webReq As HttpWebRequest, webRes As HttpWebResponse
Dim byteArray As Byte()
'***********************************************************************************************
webReq = CType(WebRequest.Create(strURL_Wsdl), HttpWebRequest)
webReq.Headers.Add("SOAPAction", strSoapAction)
webReq.ContentType = "text/xml; charset=utf-8;"
webReq.Accept = "text/xml"
webReq.Method = "POST"
webReq.Timeout = 100000
byteArray = System.Text.Encoding.UTF8.GetBytes(strRequisicao) 'Informando dados
webReq.ContentLength = byteArray.Length 'Tamanho
webReq.ClientCertificates.Clear() 'Limpando dados certificados
webReq.ClientCertificates.Add(Cert) 'Incluindo Certificados
Dim strErro As String = ""
Try
strErro = "[dataStream]"
Using dataStream As Stream = webReq.GetRequestStream()
dataStream.Write(byteArray, 0, byteArray.Length) 'Incluindo dados a serem enviados
End Using
strErro = "[webRes = CType(webReq.GetResponse(), HttpWebResponse)]"
webRes = CType(webReq.GetResponse(), HttpWebResponse) 'Checando Dados a serem recebidos
If (webRes.StatusDescription = "OK") Then
Dim responseStream As Stream = webRes.GetResponseStream()
Dim enc As Encoding = System.Text.Encoding.GetEncoding("utf-8")
Dim responseStreamReader As StreamReader = New StreamReader(responseStream, enc)
strErro = "[Lendo Retorno XML]"
strRetorno = responseStreamReader.ReadToEnd()
End If
Catch ex As Exception
strRetorno = ex.Message
Return " [a1] " & ex.Message
End Try
webReq = Nothing
webRes = Nothing
'***********************************************************************************************
'WebService NFSe (FIM)
'***********************************************************************************************
Return ""
Catch ex As Exception
strRetorno = ex.Message
Return " [a2] " & ex.Message
End Try
End Function
XML Requisição Gerado (<Envelope… + <InputXML)
<?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><GerarNfseRequest xmlns="http://notacarioca.rio.gov.br/"><inputXML><?xml version="1.0" encoding="UTF-8"?><GerarNfseEnvio xmlns="http://notacarioca.rio.gov.br/WSNacional/XSD/1/nfse_pcrj_v01.xsd"><Rps><InfRps xmlns="http://www.abrasf.org.br/ABRASF/arquivos/nfse.xsd" Id="R000023"><IdentificacaoRps><Numero>000023</Numero><Serie>1</Serie><Tipo>1</Tipo></IdentificacaoRps><DataEmissao>2021-09-27T22:42:00</DataEmissao><NaturezaOperacao>1</NaturezaOperacao><OptanteSimplesNacional>2</OptanteSimplesNacional><IncentivadorCultural>2</IncentivadorCultural><Status>1</Status><Servico><Valores><ValorServicos>1</ValorServicos><ValorDeducoes>0</ValorDeducoes><ValorPis>0</ValorPis><ValorCofins>0</ValorCofins><ValorInss>0</ValorInss><ValorIr>0</ValorIr><ValorCsll>0</ValorCsll><IssRetido></IssRetido><ValorIss>0</ValorIss><OutrasRetencoes>0</OutrasRetencoes><Aliquota>0</Aliquota><DescontoIncondicionado>0</DescontoIncondicionado><DescontoCondicionado>0</DescontoCondicionado></Valores><ItemListaServico>0702</ItemListaServico><CodigoTributacaoMunicipio>3304557</CodigoTributacaoMunicipio><Discriminacao>SERVICO (DESCRICAO)Esta nota esta sendo feita para integracao com sistema ERP</Discriminacao><CodigoMunicipio>3304557</CodigoMunicipio></Servico><Prestador><Cnpj>07860645000143</Cnpj><InscricaoMunicipal>78137118</InscricaoMunicipal></Prestador><Tomador><IdentificacaoTomador><CpfCnpj><Cnpj>05330137000128</Cnpj></CpfCnpj></IdentificacaoTomador><RazaoSocial>EXA-RIO SERVICOS LTDA</RazaoSocial><Endereco><Endereco>DOM HELDER CAMARA</Endereco><Numero>5644</Numero><Complemento></Complemento><Bairro>ENGENHO DE DENTRO</Bairro><CodigoMunicipio>3304557</CodigoMunicipio><Uf>3304557</Uf><Cep>20771004</Cep></Endereco></Tomador><ConstrucaoCivil><CodigoObra>COI</CodigoObra><Art/></ConstrucaoCivil></InfRps><Signature xmlns="http://www.w3.org/2000/09/xmldsig#"><SignedInfo><CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" /><SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" /><Reference URI="#R000023"><Transforms><Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" /><Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" /></Transforms><DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" /><DigestValue>zJiECYr4kJ840K2aNYLt0agdG0U=</DigestValue></Reference></SignedInfo><SignatureValue>Ng4q2jc7kS+NiFNO5ThkY6L7SHJ9HbcfwLboZDgj3eVbSobHQu+s8Eiw70YuupVjSPICQcL6aTdJdwXhW0FYjLpExldiOKjtEdWs+T6jtOJKK1nPRPNleJH9quRE7Z84I0c1DWpdZ4o2I228TkSXHQdkSvKdlt+LLclfaiuYrmdYQM3uDaAmf3Lr6YXDoRisvlT83G+C4bbCimQWd5x7YnVyWKXRLTcohoGWWGXDkXYPbt9VTSFerS6M48LSXtMdw0WtOq2zvrI9hPl2CbZxHR9jpHcRSYlgASNirUALRKyE4RkZaGjYDoemGT7RKG6v+9ECryLTTiEz6mCuTmApOA==</SignatureValue><KeyInfo><X509Data><X509Certificate>MIIIIjCCBgqgAwIBAgIQW3OGo0TXGSu4y9MS3NviwTANBgkqhkiG9w0BAQsFADB4MQswCQYDVQQGEwJCUjETMBEGA1UEChMKSUNQLUJyYXNpbDE2MDQGA1UECxMtU2VjcmV0YXJpYSBkYSBSZWNlaXRhIEZlZGVyYWwgZG8gQnJhc2lsIC0gUkZCMRwwGgYDVQQDExNBQyBDZXJ0aXNpZ24gUkZCIEc1MB4XDTIxMDUwNjIxMjg1M1oXDTIyMDUwNjIxMjg1M1owggEXMQswCQYDVQQGEwJCUjETMBEGA1UECgwKSUNQLUJyYXNpbDELMAkGA1UECAwCUkoxFzAVBgNVBAcMDlJpbyBkZSBKYW5laXJvMRkwFwYDVQQLDBBWaWRlb0NvbmZlcmVuY2lhMRcwFQYDVQQLDA4yMzA4NzAzMDAwMDE4MjE2MDQGA1UECwwtU2VjcmV0YXJpYSBkYSBSZWNlaXRhIEZlZGVyYWwgZG8gQnJhc2lsIC0gUkZCMRYwFAYDVQQLDA1SRkIgZS1DTlBKIEExMUkwRwYDVQQDDEBWTSBFTkdFTkhBUklBIERFIFJFVkVTVElNRU5UT1MgREUgQUxUTyBERVNFTVBFT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