0
So guys, the problem at hand now is that I have to pick up two lines that are in an XML, I get this XML through an httpRequest, and then apparently starts the problem.
What I’ve tried so far is:
...
[WebMethod]
public void PassaProtocolo(int numProtocolo) {
string url = System.Web.Configuration.WebConfigurationManager.AppSettings.Get("consulta");
url = url + numProtocolo.ToString();//adiciona numero do protocolo no endereço do http request
WebRequest req = WebRequest.Create(url);//acessa httprequest
WebResponse resp = req.GetResponse();//recebe pagina
XDocument XmlDoc = XDocument.Load(url);
string funfou = XmlDoc.Root.ToString();
}
...
the address I am using as the url variable there has already been tested and returns the page as it should:
<RetornoOfConsultaProtocoloResultulvhizZy><Codigo i:nil="true"/><Descricao i:nil="true"/><Lista><d2p1:ConsultaProtocoloResult><d2p1:cNPJField/><d2p1:cPFField>34780831687</d2p1:cPFField><d2p1:codAssuntoField>17</d2p1:codAssuntoField><d2p1:codAssuntoFieldSpecified>true</d2p1:codAssuntoFieldSpecified>
-Numbersqui2017-02-24T00:00:00truenumeroaqui0true
When executing the code I get the error:
System.xml.Xmlexception: Invalid root level data. Line 1, position 1. in System.xml.Xmltextreaderimpl.Throw(Exception e) in System.xml.Xmltextreaderimpl.Throw(String res, String Arg) in System.xml.Xmltextreaderimpl.Parserootlevelwhitespace() in System.xml.Xmltextreaderimpl.Parsedocumentcontent() in System.xml.Xmltextreaderimpl.Read() in System.xml.Linq.XDocument.Load(Xmlreader Reader, Loadoptions options) in System.xml.Linq.XDocument.Load(String Uri, Loadoptions options) in System.xml.Linq.XDocument.Load(String Uri) em wsIntegraCREA.ConsultaSGAasmx.PassaProtocolo(Int32 numProtocolo) na C:\Users\marcus\Dropbox\Projetos\Stoque\Clientes\CREA-MG\AtendimentoCREA_HOMOLOGACAO\wsIntegraCREA\ConsultaSGAasmx.asmx.cs:linha 41
This occurs when Xdocument tries to load the url. I’ve never tried to play something like this before, so I’m having a little trouble, I appreciate the help.