Ask a questionAsk a question
 

AnswerGetting HttpRequest Stream

  • Wednesday, October 28, 2009 2:31 PMacfalcon2001 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    I have a dll that calls a client's web service and passes a SoapEnvelope object in the stream (we can't do a web reference) via the code in the code block at the bottom. The issue is that I'm trying to build an imitation client to test my dll, and I'm so used to web references, how do I get the SoapEnvelope passed by the code below on my client imitator. I've tried the following and they all are null.

    [WebMethod]
    [SoapDocumentMethod(Action="OrderData")]
    public string OrderData(SoapEnvelope env)
    {
    //env is null
    }

    [WebMethod]
    [SoapDocumentMethod(Action="OrderData")]
    public string OrderData()
    {
    //Context.Request.QueryString has no Keys
    //Context.Request.Params doesn't have the envelope
    //SoapContext.Current.Envelope is null 
    }

    Any ideas??????

    HttpWebRequest webRequest = (HttpWebRequest)WebRequest.CreateDefault(new Uri(sURI);
    webRequest.ContentType = "text/xml; charset=utf-8";
    webRequest.Accept = "text/xml";
    webRequest.Method = "POST";
    webRequest.Headers.Add("SOAPAction", "OrderData");
    StreamWriter sw = new StreamWriter(webRequest.GetRequestStream(), Encoding.UTF8);
    sw.Write(sendSoapEnv.Envelope.InnerXml);
    sw.Flush();
    sw.Close();
    WebResponse webResponse = webRequest.GetResponse();
    

Answers

All Replies

  • Wednesday, October 28, 2009 11:54 PMDan Glick - MSFTModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Proposed Answer
    Have you looked at your XML on the wire (e.g. using Fiddler, or enabling System.Net or ASMX tracing) and compared it to what an auto-generated client sends? At a minimum, I would guess you want to write the Envelope's OutterXml, to include the envelope element. But comparing the actual XML should help you find the issue fairly quickly.
  • Thursday, October 29, 2009 7:55 PMacfalcon2001 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    I used a debugger to look at the XML on the wire, and at first there was an error with the SOAP that was being written (you were right I needed to use OuterXML of the envelope), but even after I did that I can't seem to get it on my client web service via any of the methods I mentioned.

    [WebMethod]
    [SoapDocumentMethod(Action="OrderData")]
    public string OrderData(SoapEnvelope env)
    {
    //env is null
    }

    [WebMethod]
    [SoapDocumentMethod(Action="OrderData")]
    public string OrderData()
    {
    //Context.Request.QueryString has no Keys
    //Context.Request.Params doesn't have the envelope
    //SoapContext.Current.Envelope is null 
    }

    But the debugger now says it is going across fine. How do I get that value???

  • Friday, October 30, 2009 12:54 AMDan Glick - MSFTModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Does the same service code work correctly if you use an auto-generated client?

  • Friday, October 30, 2009 2:49 PMacfalcon2001 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    What do you mean by auto-generated client? Do you mean setup a web reference in my dll server project that is calling the web service?

    I'm just wondering when calling a web service via a httprequest and writing the soap to the request's stream how does the client access the soap on that stream?

    Thanks
  • Friday, October 30, 2009 7:10 PMacfalcon2001 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Actually I just figured it out. I had to create a class that inherits from the SoapExtensions class. Found an example at the following URL.

    http://msdn.microsoft.com/en-us/magazine/cc188761.aspx