svaros Posted February 19, 2014 at 03:44 PM Report #545804 Posted February 19, 2014 at 03:44 PM olá antes demais 🙂 bem o meu problema é o seguinte: deram me um ficheiro .asp que consulta um webservice e retorna uma string com os resultados todos provenientes do webservice. a minha questao é: como posso manipular os dados dessa string como quiser? por exemplo pegar no nome retornado e coloca lo numa tabela. agradeço desde já a resposta, cumprimentos -------------------------- ficheiro: <% Class SoapServiceRequest Private oWinHttp,sContentType Public sWebServiceURL, sSOAPRequest,sResponse,servicename,sHost Private Sub Class_Initialize() Set oWinHttp = CreateObject("WinHttp.WinHttpRequest.5.1") sContentType ="text/xml;charset=UTF-8" End Sub Public Function SetSoapAction(servicename) sWebServiceURL = servicename End Function Public Function SendRequest oWinHttp.Open "POST", sWebServiceURL, False oWinHttp.setRequestHeader "Content-Type", sContentType oWinHttp.SetCredentials "block", "block", 0 oWinHttp.Send sSOAPRequest sResponse = oWinHttp.ResponseText End Function Public Function Close Set oWinHttp = Nothing End Function End Class Set oSoapRequest = New SoapServiceRequest oSoapRequest.SetSoapAction("http://block") oSoapRequest.sSOAPRequest = "<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:por=""http:/block""><soapenv:Header/><soapenv:Body><por:ZisuWebBapiCheckPremise><XAccount>108898511001</XAccount><XBukrs>2800</XBukrs><XNif>PT196186935</XNif><XPremise>001931506</XPremise><Entity>SEP</Entity></por:ZisuWebBapiCheckPremise></soapenv:Body></soapenv:Envelope>" oSoapRequest.SendRequest() %> <html> <head> <title>SOAP Teste</title> </head> <body> <p> Teste SOAP Service </p> <p> <%=oSoapRequest.sResponse %> </p> </body> </html> output: Teste SOAP Service 108898511001NBARREIRASJOSE SEVERINO GROSSINHOESTR NACIONAL 90 , 907400-114N9003144827PT0002000019315062CXPT160420113B1931506BARREIRASESTR NACIONAL 90 907400-114PONTE DE SOR00TE100X
nelsonr Posted February 19, 2014 at 03:59 PM Report #545810 Posted February 19, 2014 at 03:59 PM Boas, esse retorno é mesmo isso que mostras, sem caracter a separar o conteúdo? O tamanho de cada campo é fixo?
svaros Posted February 19, 2014 at 04:04 PM Author Report #545814 Posted February 19, 2014 at 04:04 PM o file de cima resulta no output que coloquei, se fizer view source apresenta se assim: <html> <head> <title>SOAP Teste</title> </head> <body> <p> Teste SOAP Service </p> <p> <SOAP:Envelope xmlns:SOAP='http://schemas.xmlsoap.org/soap/envelope/'> <SOAP:Header/><SOAP:Body> <n0:ZisuWebBapiCheckPremiseResponse xmlns:n0='http:/block' xmlns:prx='urn:sap.com:proxy:Mblock5:/1SAI/TASblock82B:701:2009/02/10'> <YAccount>108898511001</YAccount> <YBpType>N</YBpType> <YCaCity>BARREIRAS</YCaCity> <YCaName>JOSE SEVERINO GROSSINHO</YCaName> <YCaStreet>ESTR NACIONAL 90 , 90</YCaStreet> <YCaZipcode>7400-114</YCaZipcode> <YCaracteristica>N</YCaracteristica> <YContract>9003144827</YContract> <YCpe>PT0002000019315062CX</YCpe> <YNif>PT160420113</YNif> <YNivelTensao>B</YNivelTensao> <YPremise>1931506</YPremise> <YPremiseCity>BARREIRAS</YPremiseCity> <YPremiseStreet>ESTR NACIONAL 90 90</YPremiseStreet> <YPremiseZipcode>7400-114</YPremiseZipcode> <YPremiseZipcodeDesc>PONTE DE SOR</YPremiseZipcodeDesc> <YReturn>00</YReturn> <YSendControl>TE10</YSendControl> <YTelecontagem>0</YTelecontagem> <YValid>X</YValid> </n0:ZisuWebBapiCheckPremiseResponse></SOAP:Body></SOAP:Envelope> </p> </body> </html>
nelsonr Posted February 19, 2014 at 04:09 PM Report #545820 Posted February 19, 2014 at 04:09 PM Ah ok, então o retorno vem com a estrutura XML. Então usas o XmlDocument para ler esse conteúdo http://msdn.microsoft.com/en-us/library/875kz807%28v=vs.110%29.aspx Depois tens metodos para aceder aos nodes. Exemplo: http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.selectsinglenode%28v=vs.110%29.aspx
svaros Posted February 19, 2014 at 04:30 PM Author Report #545822 Posted February 19, 2014 at 04:30 PM se calhar e coisa de noob mas, esses metodos e se o ficheiro for xml, mas neste caso o ficheiro tem extensao .asp, assim funcionaria da mesma maneira?
nelsonr Posted February 19, 2014 at 04:37 PM Report #545825 Posted February 19, 2014 at 04:37 PM Usas o load do XmlDocument e passas por parametro o oSoapRequest.sResponse.
svaros Posted February 19, 2014 at 05:28 PM Author Report #545837 Posted February 19, 2014 at 05:28 PM meah, estou a ficar com um nó na cabeça :\ : seria algo parecido a isto? <% XmlDocument document = new XmlDocument(); document.LoadXml(oSoapRequest.sResponse); //loading soap message as string XmlNamespaceManager manager = new XmlNamespaceManager(document.NameTable); manager.AddNamespace("n0", "http://block/PortalCliente"); manager.AddNamespace("prx", "urn:sap.com:proxy:block:/1SAI/TAS64C0DB63CBEF34F0182B:701:2009/02/10"); XmlNodeList xnList = document.SelectNodes("//n0:ZisuWebBapiCheckPremiseResponse", manager); int nodes = xnList.Count; foreach (XmlNode xn in xnList) { Status = xn["s:YCaCity"].InnerText; } %> isto deve ser msm coisa de noob x_x
nelsonr Posted February 19, 2014 at 05:36 PM Report #545841 Posted February 19, 2014 at 05:36 PM Experimenta assim: XmlDocument document = new XmlDocument(); document.LoadXml(oSoapRequest.sResponse); // Status = document.DocumentElement.SelectSingleNode("//YCaCity").InnerText; // Status fica com "BARREIRAS"
svaros Posted February 19, 2014 at 05:51 PM Author Report #545844 Posted February 19, 2014 at 05:51 PM da 500-internal server error. eu coloquei o que disseste no ficheiro quetenho, .asp, assim: <% Class SoapServiceRequest Private oWinHttp,sContentType Public sWebServiceURL, sSOAPRequest,sResponse,servicename,sHost Private Sub Class_Initialize() Set oWinHttp = CreateObject("WinHttp.WinHttpRequest.5.1") sContentType ="text/xml;charset=UTF-8" End Sub Public Function SetSoapAction(servicename) sWebServiceURL = servicename End Function Public Function SendRequest oWinHttp.Open "POST", sWebServiceURL, False oWinHttp.setRequestHeader "Content-Type", sContentType oWinHttp.SetCredentials "block", "block", 0 oWinHttp.Send sSOAPRequest sResponse = oWinHttp.ResponseText End Function Public Function Close Set oWinHttp = Nothing End Function End Class Set oSoapRequest = New SoapServiceRequest oSoapRequest.SetSoapAction("http://block") oSoapRequest.sSOAPRequest = "<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:por=""http:/block""><soapenv:Header/><soapenv:Body><por:ZisuWebBapiCheckPremise><XAccount>108898511001</XAccount><XBukrs>2800</XBukrs><XNif>PT196186935</XNif><XPremise>001931506</XPremise><Entity>SEP</Entity></por:ZisuWebBapiCheckPremise></soapenv:Body></soapenv:Envelope>" oSoapRequest.SendRequest() %> <html> <head> <title>SOAP Teste</title> </head> <body> <p> Teste SOAP Service </p> <p> <% XmlDocument document = new XmlDocument(); document.LoadXml(oSoapRequest.sResponse); Status = document.DocumentElement.SelectSingleNode("//YCaCity").InnerText; // Status fica com "BARREIRAS" %> </p> </body> </html> deve ser uma coisa tão simples e eu a stressar :x, ainda me vou rir disto
nelsonr Posted February 19, 2014 at 05:54 PM Report #545846 Posted February 19, 2014 at 05:54 PM (edited) o exemplo que tinhas posto era C#, por isso tb fiz em C#, mas parece que estás a usar o VB.NET. Dim document As System.Xml.XmlDocument = New System.Xml.XmlDocument() document.LoadXml(sResponse) ' Status = document.DocumentElement.SelectSingleNode("//YCaCity").InnerText ' Status fica com "BARREIRAS" Edited February 19, 2014 at 05:59 PM by nelsonr
svaros Posted February 20, 2014 at 10:13 AM Author Report #545909 Posted February 20, 2014 at 10:13 AM not this time :\, vou procurar a ver se retorna algo com vbscript... :x
nelsonr Posted February 20, 2014 at 10:30 AM Report #545910 Posted February 20, 2014 at 10:30 AM Mas qual é o erro exactamente? Ali naquele exemplo tinha posto sResponse (porque era a variavel que usei para teste), mas tens de por oSoapRequest.sResponse
svaros Posted February 20, 2014 at 10:49 AM Author Report #545915 Posted February 20, 2014 at 10:49 AM (edited) sim sim, eu meti como tu dizes, mas da erro : 500-internal server error. consegui passar o response para uma variavel, que resulta na mesma estrutura xml que postei anteriormente, sera que assim ja da para seleccionar so o YCaCity? :\ Edited February 20, 2014 at 12:15 PM by svaros
svaros Posted February 20, 2014 at 02:59 PM Author Report #545943 Posted February 20, 2014 at 02:59 PM coloquei assim e não deu erro, finalmente, mas também não aparece o pretendido :\ o que estará errado? <% Dim myVar myVar = oSoapRequest.sResponse Response.Write(myVar) Set XMLDom = CreateObject("MSXML2.Domdocument.6.0") XMLDom.async = false XMLDom.LoadXML (oSoapRequest.sResponse) Set NodeList = XMLDom.documentElement.selectNodes("/YCaStreet") For Each Node In NodeList Response.Write(NodeList.value & "<br>") Next %>
nelsonr Posted February 20, 2014 at 03:16 PM Report #545945 Posted February 20, 2014 at 03:16 PM Experimenta com //YCaStreet
svaros Posted February 20, 2014 at 03:31 PM Author Report #545948 Posted February 20, 2014 at 03:31 PM Assim já dá erro lol n error occurred on the server when processing the URL. Please contact the system administrator. If you are the system administrator please click here to find out more about this error.
nelsonr Posted February 20, 2014 at 04:12 PM Report #545952 Posted February 20, 2014 at 04:12 PM Bem, criei aqui uma web app para testar. Isto funciona: <% Dim sResponse As String = "<SOAP:Envelope xmlns:SOAP='http://schemas.xmlsoap.org/soap/envelope/'>" + _ " <SOAP:Header/><SOAP:Body>" + _ " <n0:ZisuWebBapiCheckPremiseResponse xmlns:n0='http:/block' xmlns:prx='urn:sap.com:proxy:Mblock5:/1SAI/TASblock82B:701:2009/02/10'>" + _ " <YAccount>108898511001</YAccount>" + _ " <YBpType>N</YBpType>" + _ " <YCaCity>BARREIRAS</YCaCity>" + _ " <YCaName>JOSE SEVERINO GROSSINHO</YCaName>" + _ " <YCaStreet>ESTR NACIONAL 90 , 90</YCaStreet>" + _ " <YCaZipcode>7400-114</YCaZipcode>" + _ " <YCaracteristica>N</YCaracteristica>" + _ " <YContract>9003144827</YContract>" + _ " <YCpe>PT0002000019315062CX</YCpe>" + _ " <YNif>PT160420113</YNif>" + _ " <YNivelTensao>B</YNivelTensao>" + _ " <YPremise>1931506</YPremise>" + _ " <YPremiseCity>BARREIRAS</YPremiseCity>" + _ " <YPremiseStreet>ESTR NACIONAL 90 90</YPremiseStreet>" + _ " <YPremiseZipcode>7400-114</YPremiseZipcode>" + _ " <YPremiseZipcodeDesc>PONTE DE SOR</YPremiseZipcodeDesc>" + _ " <YReturn>00</YReturn>" + _ " <YSendControl>TE10</YSendControl>" + _ " <YTelecontagem>0</YTelecontagem>" + _ " <YValid>X</YValid>" + _ " </n0:ZisuWebBapiCheckPremiseResponse></SOAP:Body></SOAP:Envelope>" Dim XMLDom As Object = CreateObject("MSXML2.Domdocument.6.0") XMLDom.async = False XMLDom.LoadXML(sResponse) Response.Write(XMLDom.documentElement.selectSingleNode("//YCaStreet").Text) %> E com o exemplo que tinha dado antes, também funciona <% Dim sResponse As String = "<SOAP:Envelope xmlns:SOAP='http://schemas.xmlsoap.org/soap/envelope/'>" + _ " <SOAP:Header/><SOAP:Body>" + _ " <n0:ZisuWebBapiCheckPremiseResponse xmlns:n0='http:/block' xmlns:prx='urn:sap.com:proxy:Mblock5:/1SAI/TASblock82B:701:2009/02/10'>" + _ " <YAccount>108898511001</YAccount>" + _ " <YBpType>N</YBpType>" + _ " <YCaCity>BARREIRAS</YCaCity>" + _ " <YCaName>JOSE SEVERINO GROSSINHO</YCaName>" + _ " <YCaStreet>ESTR NACIONAL 90 , 90</YCaStreet>" + _ " <YCaZipcode>7400-114</YCaZipcode>" + _ " <YCaracteristica>N</YCaracteristica>" + _ " <YContract>9003144827</YContract>" + _ " <YCpe>PT0002000019315062CX</YCpe>" + _ " <YNif>PT160420113</YNif>" + _ " <YNivelTensao>B</YNivelTensao>" + _ " <YPremise>1931506</YPremise>" + _ " <YPremiseCity>BARREIRAS</YPremiseCity>" + _ " <YPremiseStreet>ESTR NACIONAL 90 90</YPremiseStreet>" + _ " <YPremiseZipcode>7400-114</YPremiseZipcode>" + _ " <YPremiseZipcodeDesc>PONTE DE SOR</YPremiseZipcodeDesc>" + _ " <YReturn>00</YReturn>" + _ " <YSendControl>TE10</YSendControl>" + _ " <YTelecontagem>0</YTelecontagem>" + _ " <YValid>X</YValid>" + _ " </n0:ZisuWebBapiCheckPremiseResponse></SOAP:Body></SOAP:Envelope>" Dim document As System.Xml.XmlDocument = New System.Xml.XmlDocument() document.LoadXml(sResponse) Response.Write(document.DocumentElement.SelectSingleNode("//YCaCity").InnerText) %> Tens a certeza que estás a fazer em ASP.NET+VB.NET e não apenas ASP?
svaros Posted February 21, 2014 at 12:39 PM Author Report #546060 Posted February 21, 2014 at 12:39 PM E assim deu: <% Set XMLDom = CreateObject("MSXML2.Domdocument.6.0") XMLDom.LoadXML (oSoapRequest.sResponse) set Resultado=XMLDOM.SelectSingleNode("//YCaStreet") Response.Write(Resultado.Text) %> Obrigado pela ajuda 😉 podem encerrar o topico 😄
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now