RETORNO WEBSERVICE
Boa noite colegas
estou acessando um webservice conforme este link
está funcionando legal só que a resposta está vindo assim
<transmissaoSNGPC> <cabecalho> <CODIGOHASH>e4e8541d2ccdc66d6e18e6e8ac89cba</CODIGOHASH> <DATATRANSMISSAO>09/03/2011</DATATRANSMISSAO> <DATAVALIDACAO>09/03/2011</DATAVALIDACAO> <INICIOREFERENCIA>23/02/2011</INICIOREFERENCIA> <FIMREFERENCIA>01/03/2011</FIMREFERENCIA> </cabecalho></transmissaoSNGPC>
quando deveria ser assim
<transmissaoSNGPC>
<cabecalho>
<CODIGOHASH>147981faaa7752c54c2de4fdee66c5ad</CODIGOHASH>
<DATATRANSMISSAO>13/10/2009</DATATRANSMISSAO>
<DATAVALIDACAO>13/10/2009</DATAVALIDACAO>
<INICIOREFERENCIA>15/09/2009</INICIOREFERENCIA>
<FIMREFERENCIA>22/09/2009</FIMREFERENCIA>
</cabecalho></transmissaoSNGPC>
o codigo segue abaixo
strURL = [Ô]http://sngpc.anvisa.gov.br/webservice/sngpc.asmx[Ô]
strSoapAction = [Ô]http://tempuri.org/ConsultaDadosArquivoSNGPC[Ô]
strXml = [Ô]<?xml version=[Ô][Ô]1.0[Ô][Ô] encoding=[Ô][Ô]ISO-8859-1[Ô][Ô]?>[Ô] & _
[Ô]<soap:Envelope xmlns:xsi=[Ô][Ô]http://www.w3.org/2001/XMLSchema-instance[Ô][Ô] xmlns:xsd=[Ô][Ô]http://www.w3.org/2001/XMLSchema[Ô][Ô] xmlns:soap=[Ô][Ô]http://schemas.xmlsoap.org/soap/envelope/[Ô][Ô]>[Ô] & _
[Ô]<soap:Body>[Ô] & _
[Ô]<ConsultaDadosArquivoSNGPC xmlns=[Ô][Ô]http://tempuri.org/[Ô][Ô]>[Ô] & _
[Ô]<Email>[Ô] & [Ô]xxxxxxxxxxxxx[Ô] & [Ô]</Email>[Ô] & _
[Ô]<Senha>[Ô] & [Ô]xxxxxxx[Ô] & [Ô]</Senha>[Ô] & _
[Ô]<CNPJ>[Ô] & [Ô]xxxxxxxxxxx[Ô] & [Ô]</CNPJ>[Ô] & _
[Ô]<Hash>[Ô] & [Ô]xxxxxxxxxxx[Ô] & [Ô]</Hash>[Ô] & _
[Ô]</ConsultaDadosArquivoSNGPC>[Ô] & _
[Ô]</soap:Body>[Ô] & _
[Ô]</soap:Envelope>[Ô] [ô]
Me.Text1 = PostWebservice(strURL, strSoapAction, strXml) [ô]
Private Function PostWebservice(ByVal AsmxUrl As String, ByVal SoapActionUrl As String, ByVal XmlBody As String) As String
Dim objDom As Object
Dim objXmlHttp As Object
Dim strRet As String
Dim intPos1 As Integer
Dim intPos2 As Integer
On Error GoTo Err_PW
[ô][ô] Create objects to DOMDocument and XMLHTTP
Set objDom = CreateObject([Ô]MSXML2.DOMDocument[Ô])
Set objXmlHttp = CreateObject([Ô]MSXML2.XMLHTTP[Ô])
[ô][ô] Load XML
objDom.async = False
objDom.LoadXML XmlBody
[ô][ô] Open the webservice
objXmlHttp.Open [Ô]POST[Ô], AsmxUrl, False
[ô][ô] Create headings
objXmlHttp.setRequestHeader [Ô]Content-Type[Ô], [Ô]text/xml; charset=ISO-8859-1[Ô]
objXmlHttp.setRequestHeader [Ô]SOAPAction[Ô], SoapActionUrl
[ô][ô] Send XML command
objXmlHttp.send objDom.xml
[ô][ô] Get all response text from webservice
strRet = objXmlHttp.responseText
[ô][ô] Close object
Set objXmlHttp = Nothing
[ô][ô] Extract result
intPos1 = InStr(strRet, [Ô]Result>[Ô]) + 7
intPos2 = InStr(strRet, [Ô]</[Ô])
If intPos1 > 7 And intPos2 > 0 Then
strRet = Mid(strRet, intPos1, intPos2 - intPos1)
End If
[ô][ô] Return result
PostWebservice = strRet
Exit Function
Err_PW:
PostWebservice = [Ô]Error: [Ô] & Err.Number & [Ô] - [Ô] & Err.Description
End Function
estou acessando um webservice conforme este link
está funcionando legal só que a resposta está vindo assim
<transmissaoSNGPC> <cabecalho> <CODIGOHASH>e4e8541d2ccdc66d6e18e6e8ac89cba</CODIGOHASH> <DATATRANSMISSAO>09/03/2011</DATATRANSMISSAO> <DATAVALIDACAO>09/03/2011</DATAVALIDACAO> <INICIOREFERENCIA>23/02/2011</INICIOREFERENCIA> <FIMREFERENCIA>01/03/2011</FIMREFERENCIA> </cabecalho></transmissaoSNGPC>
quando deveria ser assim
<transmissaoSNGPC>
<cabecalho>
<CODIGOHASH>147981faaa7752c54c2de4fdee66c5ad</CODIGOHASH>
<DATATRANSMISSAO>13/10/2009</DATATRANSMISSAO>
<DATAVALIDACAO>13/10/2009</DATAVALIDACAO>
<INICIOREFERENCIA>15/09/2009</INICIOREFERENCIA>
<FIMREFERENCIA>22/09/2009</FIMREFERENCIA>
</cabecalho></transmissaoSNGPC>
o codigo segue abaixo
strURL = [Ô]http://sngpc.anvisa.gov.br/webservice/sngpc.asmx[Ô]
strSoapAction = [Ô]http://tempuri.org/ConsultaDadosArquivoSNGPC[Ô]
strXml = [Ô]<?xml version=[Ô][Ô]1.0[Ô][Ô] encoding=[Ô][Ô]ISO-8859-1[Ô][Ô]?>[Ô] & _
[Ô]<soap:Envelope xmlns:xsi=[Ô][Ô]http://www.w3.org/2001/XMLSchema-instance[Ô][Ô] xmlns:xsd=[Ô][Ô]http://www.w3.org/2001/XMLSchema[Ô][Ô] xmlns:soap=[Ô][Ô]http://schemas.xmlsoap.org/soap/envelope/[Ô][Ô]>[Ô] & _
[Ô]<soap:Body>[Ô] & _
[Ô]<ConsultaDadosArquivoSNGPC xmlns=[Ô][Ô]http://tempuri.org/[Ô][Ô]>[Ô] & _
[Ô]<Email>[Ô] & [Ô]xxxxxxxxxxxxx[Ô] & [Ô]</Email>[Ô] & _
[Ô]<Senha>[Ô] & [Ô]xxxxxxx[Ô] & [Ô]</Senha>[Ô] & _
[Ô]<CNPJ>[Ô] & [Ô]xxxxxxxxxxx[Ô] & [Ô]</CNPJ>[Ô] & _
[Ô]<Hash>[Ô] & [Ô]xxxxxxxxxxx[Ô] & [Ô]</Hash>[Ô] & _
[Ô]</ConsultaDadosArquivoSNGPC>[Ô] & _
[Ô]</soap:Body>[Ô] & _
[Ô]</soap:Envelope>[Ô] [ô]
Me.Text1 = PostWebservice(strURL, strSoapAction, strXml) [ô]
Private Function PostWebservice(ByVal AsmxUrl As String, ByVal SoapActionUrl As String, ByVal XmlBody As String) As String
Dim objDom As Object
Dim objXmlHttp As Object
Dim strRet As String
Dim intPos1 As Integer
Dim intPos2 As Integer
On Error GoTo Err_PW
[ô][ô] Create objects to DOMDocument and XMLHTTP
Set objDom = CreateObject([Ô]MSXML2.DOMDocument[Ô])
Set objXmlHttp = CreateObject([Ô]MSXML2.XMLHTTP[Ô])
[ô][ô] Load XML
objDom.async = False
objDom.LoadXML XmlBody
[ô][ô] Open the webservice
objXmlHttp.Open [Ô]POST[Ô], AsmxUrl, False
[ô][ô] Create headings
objXmlHttp.setRequestHeader [Ô]Content-Type[Ô], [Ô]text/xml; charset=ISO-8859-1[Ô]
objXmlHttp.setRequestHeader [Ô]SOAPAction[Ô], SoapActionUrl
[ô][ô] Send XML command
objXmlHttp.send objDom.xml
[ô][ô] Get all response text from webservice
strRet = objXmlHttp.responseText
[ô][ô] Close object
Set objXmlHttp = Nothing
[ô][ô] Extract result
intPos1 = InStr(strRet, [Ô]Result>[Ô]) + 7
intPos2 = InStr(strRet, [Ô]</[Ô])
If intPos1 > 7 And intPos2 > 0 Then
strRet = Mid(strRet, intPos1, intPos2 - intPos1)
End If
[ô][ô] Return result
PostWebservice = strRet
Exit Function
Err_PW:
PostWebservice = [Ô]Error: [Ô] & Err.Number & [Ô] - [Ô] & Err.Description
End Function
Isto ocorre porque a estrutura do retorno XML está sendo enviada como STRING e sem os comandos de quebra de linha (CR e LF).
Mas, isso está causando algum erro?
Mas, isso está causando algum erro?
o retorno está como abaixo no lugar de [Ô]<[Ô] vem -->> < e no lugar de [Ô]>[Ô] vem -->>>
estranho quando posto o retorno aparece certo
<transmissaoSNGPC> <cabecalho> <CODIGOHASH>e4e8541d2ccdc66d6e18e6e8ac89cba</CODIGOHASH> <DATATRANSMISSAO>09/03/2011</DATATRANSMISSAO> <DATAVALIDACAO>09/03/2011</DATAVALIDACAO> <INICIOREFERENCIA>23/02/2011</INICIOREFERENCIA> <FIMREFERENCIA>01/03/2011</FIMREFERENCIA> </cabecalho></transmissaoSNGPC>
estranho quando posto o retorno aparece certo
<transmissaoSNGPC> <cabecalho> <CODIGOHASH>e4e8541d2ccdc66d6e18e6e8ac89cba</CODIGOHASH> <DATATRANSMISSAO>09/03/2011</DATATRANSMISSAO> <DATAVALIDACAO>09/03/2011</DATAVALIDACAO> <INICIOREFERENCIA>23/02/2011</INICIOREFERENCIA> <FIMREFERENCIA>01/03/2011</FIMREFERENCIA> </cabecalho></transmissaoSNGPC>
Tópico encerrado , respostas não são mais permitidas