title: Getting the underlying stream from a wcf streaming webservice
body: <p>I am building a streaming webservice in WCF and have an issue getting access to the underlying stream.</p>
  
  <p>I am implementing an existing contract based on a wsdl but I would like to make the service streaming. Since I cannot change the contract, I cannot use the Stream as a parameter option (because this changes the contract).</p>
  
  <p>So I have settled on using a Message as parameter and return. This works flawlessly.</p>
  
  <p>But I would like to have access to the Stream object (which must be somewhere inside the Message object or its properties). But the only thing that the Message gives me is a XmlDictionaryReader and this does not allow access to the Stream.</p>
  
  <pre><code>public Message GetMessage(Message message)
      {
          // We need some way to access the underlying stream from the message - the GetReaderAtBodyContents is not usable
          XmlDictionaryReader reader = message.GetReaderAtBodyContents();
          CopyReaderToFile(reader);
          return Message.CreateMessage(MessageVersion.Soap11, "http://tempuri.org/IStreamingService/GetMessageResponse", "Hej med dig fra GetMessage. MessageLength ");
      }
  </code></pre>
  
  <p>The above shows my service implementation. The major problem with the XmlDictionaryReader is that it does not give me access to the precise data sent by the client - in other words I cannot reproduce the content from the client on the service. This is bad because I then cannot verify the signature which is present in the MessageHeaders.</p>
  
  <p>So is there a way of accessing the underlying stream? Can this be achieved by behaviours?</p>
  
  <p>Thanks in advance</p>