0

So, basically I am creating a Windows Service that is going to consult a SOAP Service and after that return an item. To find that item, who made the service created 2 "filters". customerFilter and itemFilter. So, when I create the web request I need to insert thoose 2 parameters.

I have this:

static string date = DateTime.Now.Date.ToString("yyyy_MM_dd");
        static string pathLog = "Logs/LogGetSalesLineDiscount/" + date + "LogGetSalesLineDiscount.txt";

        public static string[] CallWebService(IOrganizationService service)
        {
            var action = "http://...";
            var url = "http://...";
            var request = (HttpWebRequest)WebRequest.Create(url);
            var postData = "customerFilter=" + Uri.EscapeDataString("TESTE");
            postData += "&itemFilter=" + Uri.EscapeDataString("TESTE");
            var data = Encoding.ASCII.GetBytes(postData);

            request.Method = "POST";
            request.ContentType = "text/xml;charset=\"utf-8\"";
            request.Headers.Add("SOAPAction", action);
            request.ContentLength = data.Length;
            request.Accept = "text/xml";
            request.Credentials = new NetworkCredential("...", "...");

            using (var stream = request.GetRequestStream())
            {
                stream.Write(data, 0, data.Length);
            }

            var response = (HttpWebResponse)request.GetResponse();

            var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();

            using (System.IO.StreamWriter file = new System.IO.StreamWriter(AppDomain.CurrentDomain.BaseDirectory + pathLog, true))

            {
               file.WriteLine(responseString);
            }

            

            return null;
        }
    }

If I have that, it will return an error 500. I don´t know why.

If I remove the action, it will return something about all the actions in the service...

Please help me, I dont know what to do....

  • Why don't you create a soap client? – Fildor Sep 22 '21 at 12:18
  • @Fildor i have other services and in all of them I use the same logic (without the input parameters) and it works – Gonçalo Nogueira Sep 22 '21 at 12:20
  • That doesn't answer my question, though. – Fildor Sep 22 '21 at 12:24
  • Outside that, it looks like you want to use query-parameters but you post them in the body ... – Fildor Sep 22 '21 at 12:26
  • @Fildor I dont know to create a SOAP client I was following this post: https://stackoverflow.com/questions/4015324/how-to-make-an-http-post-web-request – Gonçalo Nogueira Sep 22 '21 at 12:28
  • That's for REST. SOAP is a bit more complicated, using envelopes and all that. But SOAP Servers provide (usually) a wsdl File, which you can use to have Tools create a Client for you automatically. For example you can "add service reference" in a project. – Fildor Sep 22 '21 at 12:34

0 Answers0