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 ?
– Robss70
Because when I add, for some reason, it doesn’t show up for me to access the methods..
– novato
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
– Robss70
Validate? no... where did you validate? I need the xml it mounts.. how do I get this ??
– novato
https://www.wsdl-analyzer.com/ I also used wsdl.exe and the error was the same
– Robss70
I need the xml it mounts.. how do I get it to do this ??
– novato
Let’s go continue this discussion in chat.
– Robss70
It worked out the way it is now... except the url... I contacted the support and passed me another URL and it worked.
– novato