I have a built a WCF web service against a pre-existing XSD schema which uses the XmlSerializer
serializer.
I would like to validate incoming requests and outgoing requests against this pre-existing schema. MSDN contains a worked example of how this can be accomplished using WCF MessageInspectors. The technique described involves creating an XmlReader
at the body contents:
XmlReader bodyReader = message.GetReaderAtBodyContents().ReadSubtree();
And then using validating against the SchemaSet
using an XMLDictionaryReader
create from this reader.
I have encountered a problem whereby my xml body contents contains several instances of xsi:type="xsd:string"
against elements. The namespace prefixes for xsi
and xsd
are generated by WCF against the body
element and so my validation fails due to xsd
not being declared.
Example XML message:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://www.abc.com/Service/Response</Action>
</s:Header>
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<foo xmlns="http://www.abc.com">
<aaa xsi:type="xsd:string">true</aaa>
</foo>
</s:Body>
</s:Envelope>
Validation error:
"The value 'xsd:string' is invalid according to its schema type 'QName' - 'xsd' is an undeclared namespace."
Is there any WCF configuration options that allow me to push down these xmlns
declarations into the body?