user2866761
user2866761

Reputation: 1

Lost prefix's definitions after deserialization of WCF message

I develop WCF-client. My client should validate incoming messages.

One of the messages has the following structure:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope" xmlns:SOAP-ENC="http://www.w3.org/2003/05/soap-encoding" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <SOAP-ENV:Header>...</SOAP-ENV:Header>
  <SOAP-ENV:Body>
    <OpDescriptionResponse>
      <Field Name="DateTime" Type="xsd:dateTime">
    </OpDescriptionResponse>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

In this case the client should validate: the field "DateTime" has type "dateTime" from namespace "http://www.w3.org/2001/XMLSchema".

This response is deserialized in structure containing array of XmlElement.

But I have an issue: after message is deserialized and I received corresponding variable, containing all Field nodes I can't determine value of prefix "xsd", i.e. if I take any elementof type XMLElement corresponding to Field node in reply and call element.GetNamespaceOfPrefix("xsd") I get empty string as result.

How can I get prefix's definitions are saved after deserialization?

Help me please to overcome this issue.

Upvotes: 0

Views: 186

Answers (1)

Seymour
Seymour

Reputation: 7067

In order to influence the namespace/prefix, you need to use XmlSerializerNamespaces.

The following code provides a rough reference:

XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces();
namespaces.Add("prefixHere", "http://namespace.here/");
XmlSerializer tempSerializer = new XmlSerializer(messageObject.GetType());
tempSerializer.Serialize(Console.Out, messageObject, namespaces);  

Regards,

Upvotes: 0

Related Questions