0

I have to make Xml post request to an Api, and don't know what am missing, am always getting two erros. and my request is..

         string oRequest = "";
        oRequest = "<soapenv:Envelope   xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\""
                        +"xmlns:typ=\"http://www.website.net/lmsglobal/ws/v1/extint/types\"" 
                        +"xmlns:typ1=\"http://www.website.net/lmsglobal/xsd/v1/types\">";
            oRequest = oRequest + "<soapenv:Header/>";
            oRequest = oRequest + "<soapenv:Body>";
            oRequest = oRequest + "<typ:GetAccountBalanceRequest>";
            oRequest = oRequest + "<typ:Authentication>";
            oRequest = oRequest + "<typ1:Principal>";
            oRequest = oRequest + "<typ1:PrincipalValue >88888888888</ typ1:PrincipalValue>";
            oRequest = oRequest + "<typ1:PrincipalClassifier >0</ typ1:PrincipalClassifier>";
            oRequest = oRequest + "</typ1:Principal>";
            oRequest = oRequest + "</typ:Authentication>";               
            oRequest = oRequest + "</typ:GetAccountBalanceRequest>";
            oRequest = oRequest + "</soapenv:Body>";
            oRequest = oRequest + "</soapenv:Envelope>";

            byte[] data = Encoding.UTF8.GetBytes(oRequest);
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://mywebsite.in/Services/v1/soap");
            request.Method = "POST";
            request.ContentType = "text/xml;charset=UTF-8";

            Stream dataStream = request.GetRequestStream();
            dataStream.Write(data, 0, data.Length);
            dataStream.Close();

            HttpWebResponse resp = (HttpWebResponse)request.GetResponse();
            string result = new StreamReader(resp.GetResponseStream()).ReadToEnd();

errors:

  • ((System.Net.ConnectStream)newStream).Length threw an exception of type 'System.NotSupportedException'

  • ((System.Net.ConnectStream)newStream).Lengththrew an exception of type 'System.NotSupportedException' getting these errors at

    Stream dataStream = request.GetRequestStream();

and finally 500 internal server error. what am i missing any thing is wrong ? and this request when do from SOAP UI tools it's giving responce too.

Ray
  • 188
  • 2
  • 17
  • Did you set contents length? http://stackoverflow.com/questions/7908972/how-to-write-a-http-request – jdweng Dec 15 '16 at 12:12
  • i just did after saw your comment,as request.ContentLength = data.Length; but still same error – Ray Dec 15 '16 at 12:14
  • The 500 internal error is a general error that covers lots of different issues. The best way of getting more info is to use a sniffer like wireshark or fiddler. I'n not sure if the issue is with the client isn't sending the data because Net Library found error, the data is being sent and is not formatted correctly, or the server rejected message, or a firewall blocked data (needed proxy server) due to credentials. – jdweng Dec 15 '16 at 13:00

0 Answers0