function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
mcclurecmcclurec 

Outbound message in workflow doesn't seem to be sending a response

I am trying to consume an Outbound Message from Saleforce by sending my workflow to an ashx handler page with the following code:

public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/xml";
            context.Response.ContentEncoding = System.Text.Encoding.UTF8;
           
            HttpResponse response = null;
            response = context.Response;

            string sfXMLPayload = "";
          
                Stream strm = response.OutputStream;
                StreamReader sr = new StreamReader(strm);
                string sfXML = sr.ReadToEnd();
                       
                sfXMLPayload = sfXML;

                WriteTextFile( sfXMLPayload);
          
  }

public void WriteTextFile(string inputStr)
        {

            string text = inputStr;
            System.IO.File.WriteAllText(@"C:\temp\sfXML.xml", text);
           
        }



I see this error in my Saleforce logs:
org.xml.sax.SAXParseException: Premature end of file.

And the sfXML that is written to the text file is:
System.ArgumentException: Stream was not readable.    
at System.IO.StreamReader..ctor(Stream stream, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize)    
at System.IO.StreamReader..ctor(Stream stream)    
at salesForceReceive.ProcessRequest(HttpContext context)

Best Answer chosen by Admin (Salesforce Developers) 
SuperfellSuperfell

Well, you're trying to read the response stream, when you should be reading the request stream (and writing to the response stream).

All Answers

SuperfellSuperfell

Well, you're trying to read the response stream, when you should be reading the request stream (and writing to the response stream).

This was selected as the best answer
mcclurecmcclurec

That must be the WCF equivalent of forgetting a semicolon! Thank you SOOOO much, this has been blocking us for way too long. I knew it was simple, but this is re-defining :)