Webservice in C# Reading Xml

Asked

Viewed 1,600 times

0

Good afternoon, I am building a Webservice in C#, I created a method that reads an XML sent as a request and should return the student’s name... The problem I’m actually facing is when I try to perform the test using Soapui, when sending XML I have an empty answer with error HTTP/1.1 400 Bad Request.

I would like help to solve this problem, because I don’t know how else to solve it...

Follow the code of my used classes:

Method of my webservice:

[WebMethod]
    public String CapturarDados(String Xml) {

        String retorno = "teste";

        try
        {
            LeitorXml p = new LeitorXml();

            retorno = p.LerXml(Xml);
        }
        catch (Exception ex )
        {

            retorno = ex.Message;
        }

        return retorno;
    }

Leitorxml class:

public class LeitorXml
{
    public String LerXml(String xml)
    {

        XmlDocument xDoc = new XmlDocument();
        xDoc.LoadXml(xml);
        XmlNodeList xnList = xDoc.GetElementsByTagName("Alunos");

        string sNome = xnList[0]["nome"].InnerXml;

        String retorno = sNome;



        System.IO.StreamWriter file = new System.IO.StreamWriter("c:\\test.txt");
        file.WriteLine(sNome);

        file.Close();

        return retorno;
    }
}

XML input :

  <Alunos>
           <nome>Caio</nome>
           <idade>21</idade>
           <email>[email protected]</email>
           <Endereco>
              <Rua>Av.Lins de Vasconcelos</Rua>
              <Bairro>Cambuci</Bairro>
              <Cidade>São Paulo</Cidade>
              <Estado>SP</Estado>
              <Cep>16520-005</Cep>
           </Endereco>
        </Alunos>

Using visual studio the answer is OK.

Utilizando o Visual Studio

But when using Soapui this is the problem presented:

inserir a descrição da imagem aqui

  • Theoretically, the 400 BAD REQUEST error says that something in your HTTP request is incorrect, IE, maybe the format of the envelope you are sending is wrong, give a good check.

  • It can even be a Soapui configuration.

  • The strange thing is that if I use the Helloworld method that already comes works in Soapui, only this method that I created does not return anything and returns this error.

  • But then it’s a completely different requisition, there’s no way to compare.

  • Have you tried using . NET Webservice Studio? It is much lighter and simpler than Soapui, test there with it and tell me what happens. link

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.