none
WCF REST Intercepter - Error - This stream does not support seek operations. RRS feed

  • Question

  • Further to my question I posted here I am trying to write a custom WCF Message Interceptor as per the tutorial given at below URL.

    https://msdn.microsoft.com/en-us/library/dn198277.aspx

    But, I am getting error in one method. Code snippet is here, 

     public string HttpPost(string URI, string Parameters)
        {
            WebRequest req = WebRequest.Create(URI);
            req.ContentType = "application/x-www-form-urlencoded";
            req.Method = "POST";
    
            // Add parameters to post
            byte[] data = Encoding.ASCII.GetBytes(Parameters);
            req.ContentLength = data.Length;
            System.IO.Stream os = req.GetRequestStream();
            os.Write(data, 0, data.Length);
            os.Close();
    
            // Do the post and get the response.
            System.Net.WebResponse resp = null;
            resp = req.GetResponse();
    
            StreamReader sr = new StreamReader(resp.GetResponseStream());
            return sr.ReadToEnd().Trim();
        }

    On step,  System.IO.Stream os = req.GetRequestStream(); I am getting error "This stream does not support seek operations."

    Can anyone help me put with this please ?

    Thanks in advance. 

    Thursday, July 21, 2016 5:16 AM

Answers

  • hello all,

    Problem was with "Parameters" string.

    I accidentally had left out the "?" that I copied from API doc.  :(

    Thursday, July 21, 2016 10:59 AM

All replies

  • Hi,

    Seems it is very generic error, couple of pointer you can try with.

    1) Instead of ASCII try to use UTF8

    2) Instead WebRequest try with HttpWebRequest like example below

    HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(url);

    please share the inner exception details to triage better.

    Hope this Help!!!

    Please Mark as Answered if you satisfy with Reply.

    • Proposed as answer by vikas.a.mehta Thursday, July 21, 2016 8:13 AM
    Thursday, July 21, 2016 8:13 AM
  • Hello Vikas,

    I have tried both the options.

    I am getting "The remote server returned an error: (400) Bad Request." at statement :

    resp = req.GetResponse();
    I have tried so many things. but nothing seems to be working :(
    Thursday, July 21, 2016 9:57 AM
  • hello all,

    Problem was with "Parameters" string.

    I accidentally had left out the "?" that I copied from API doc.  :(

    Thursday, July 21, 2016 10:59 AM