Send XML via POST

Asked

Viewed 1,061 times

0

I have the following example to send XML via POST:

public string EnviarXmlSoap(string methodName, string body)
    {
        WebRequest webRequest = WebRequest.Create("https://loja-s.tray.com.br/webservice/v2/ws_servidor.php?wsdl");
        HttpWebRequest httpRequest = (HttpWebRequest)webRequest;
        httpRequest.Method = "POST";
        httpRequest.ContentType = "text/xml; charset=utf-8";
        httpRequest.Headers.Add("SOAPAction: http://tempuri.org/" + methodName);
        httpRequest.ProtocolVersion = HttpVersion.Version11;
        httpRequest.Credentials = CredentialCache.DefaultCredentials;
        Stream requestStream = httpRequest.GetRequestStream();
        //Create Stream and Complete Request             
        StreamWriter streamWriter = new StreamWriter(requestStream, Encoding.ASCII);

        StringBuilder soapRequest = new StringBuilder("<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
        soapRequest.Append(" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" ");
        soapRequest.Append("xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body>");
        soapRequest.Append(body);
        soapRequest.Append("</soap:Body></soap:Envelope>");

        streamWriter.Write(soapRequest.ToString());
        streamWriter.Close();
        //Get the Response    
        HttpWebResponse wr = (HttpWebResponse)httpRequest.GetResponse();
        StreamReader srd = new StreamReader(wr.GetResponseStream());
        string resulXmlFromWebService = srd.ReadToEnd();
        return resulXmlFromWebService;
    }

I edited the code and now is returning me the following error:

O servidor remoto retornou um erro: (404) Não Localizado.

  • Why you do not add a Reference service from this webservice ?

  • Because when I add, for some reason, it doesn’t show up for me to access the methods..

  • Have you tried validating this wsdl ? I tried it here and it didn’t validate. The error was as follows: The datatype 'http://loja-s.tray.com.br/webservice/v2/ws_servor.php:Value' is Missing. But I did a test and it includes this "Value" in wsdl and the class was generated normally

  • Validate? no... where did you validate? I need the xml it mounts.. how do I get this ??

  • https://www.wsdl-analyzer.com/ I also used wsdl.exe and the error was the same

  • I need the xml it mounts.. how do I get it to do this ??

  • It worked out the way it is now... except the url... I contacted the support and passed me another URL and it worked.

Show 3 more comments
No answers

Browser other questions tagged

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