471,111 Members | 1,485 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,111 software developers and data experts.

Problems validating a SOAP request in a SOAP Extension

I am recieving the "The root element is missing" error from my soap extension
while attempting to validate an incoming SOAP message request. I suspect the
problem resides in the ChainStream method but I'm not sure. Below is a
water-downed version of the code that I'm working on. While debugging, I
noticed that if I pass an invalid SOAP request, the schema validation catches
it and throws the error appropriately. However, when I pass in a valid SOAP
request, the root element error is returned but not from the validation
handler. With this, I don't believe the problem is arising from the
XmlValidatingReader process. Any advise on how to resolve this issue is

public class MySolSoapExtension : SoapExtension
private Stream inputStream;
private Stream outputStream;
private bool bPostDeserialize;

public override object GetInitializer( Type serviceType )
return GetType();

public override object GetInitializer( LogicalMethodInfo methodInfo,
SoapExtensionAttribute attribute )
return null;

public override void Initialize( object initializer )
bPostDeserialize = false;

public override Stream ChainStream( Stream stream )
//This flag will be set to true during the AfterDeserialize handler in
if( !bPostDeserialize)
this.inputStream = stream;
this.outputStream = new MemoryStream();
this.inputStream.Position = 0;
return outputStream;

this.inputStream = new MemoryStream();
this.outputStream = stream;
this.outputStream.Position = 0;
return inputStream;
public override void ProcessMessage(SoapMessage msg)
case SoapMessageStage.BeforeDeserialize:
// read incoming xml soap message
XmlTextReader tr = new XmlTextReader(new StreamReader(msg.Stream));

// validate xml
XmlValidatingReader vr = new XmlValidatingReader(tr);
vr.ValidationType = ValidationType.Schema;

// create a schema collection
XmlSchemaCollection xsc = new XmlSchemaCollection();
xsc.Add("http://schemas.xmlsoap.org/soap/envelope/", "envelope.xml");
xsc.Add("http://schemas.xmlsoap.org/soap/encoding/", "encoding.xml");

// load schema collection

// add validation event handler
vr.ValidationEventHandler += new
ValidationEventHandler(reader_ValidationEventHandl er);
while (vr.Read());

bPostDeserialize = true;
// reset stream position
msg.Stream.Position = 0;

case SoapMessageStage.AfterDeserialize:
case SoapMessageStage.BeforeSerialize:
case SoapMessageStage.AfterSerialize:

private static void reader_ValidationEventHandler(object sender,
ValidationEventArgs e)
throw new SoapException("Schema Error: " + e.Exception.Message, new
Nov 23 '05 #1
0 2806

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by John Doe. | last post: by
4 posts views Thread by pepcag | last post: by
1 post views Thread by MarkoH | last post: by
reply views Thread by Matt Wood | last post: by
2 posts views Thread by Frederik Vanderhaegen | last post: by
reply views Thread by Patrick Brunmayr | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.