Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Indigo

Vista Tutorial - Serialization of DataContract with Unwrapped Array

 
 
Old 03-14-2008   #1 (permalink)
Shaun McDonnell
Guest


 
 

Serialization of DataContract with Unwrapped Array

I am having a problem getting a data contract to serialize correctly and I
haven't been able to come up with a solution yet.



Basically, I have the following Xml Schema that clients are sending to my
WCF Service as pure Xml:



http://docs.oasis-open.org/emergency...proved/cap.xsd



The method that my service implements looks like this:



[OperationContract(IsOneWay = true)]

[WebInvoke(BodyStyle = WebMessageBodyStyle.Bare, RequestFormat =
WebMessageFormat.Xml, ResponseFormat = WebMessageFormat.Xml)]

void PostCapAlert(Alert message);



where 'Alert' is my DataContract that matches the aforementioned schema.
Please bear with me as I will try to provide as many details as possible
without confusing the question.



Using fiddler, I send the following xml message to the service-method above:



<alert>

<identifier>43b080713727</identifier>
<sender>hsas@xxxxxx</sender>
<sent>2003-04-02T14:39:01-05:00</sent>
<status>Actual</status>
<msgType>Alert</msgType>
<scope>Public</scope>
<info>
<category>Security</category>
<event>Homeland Security Advisory System Update</event>
<urgency>Immediate</urgency>
<severity>Severe</severity>
<certainty>Likely</certainty>
<senderName>U.S. Government, Department of Homeland Security</senderName>
<headline>Homeland Security Sets Code ORANGE</headline>
<description>The Department of Homeland Security has elevated the Homeland
Security Advisory System threat level to ORANGE / High in response to
intelligence which may indicate a heightened threat of
terrorism.</description>
<instruction>A High Condition is declared when there is a high risk of
terrorist attacks. In addition to the Protective Measures taken in the
previous Threat Conditions, Federal departments and agencies should consider
agency-specific Protective Measures in accordance with their existing
plans.</instruction>
<web>http://www.dhs.gov/dhspublic/display?theme=29</web>
- <parameter>
<valueName>HSAS</valueName>
<value>ORANGE</value>
</parameter>
- <resource>
<resourceDesc>Image file (GIF)</resourceDesc>
<uri>http://www.dhs.gov/dhspublic/getAdvisoryImage</uri>
</resource>
- <area>
<areaDesc>U.S. nationwide and interests worldwide</areaDesc>
</area>
</info>
</alert>

Almost everything gets deserialized correctly except for the unwrapped
arrays (like the 'info' element). To troubleshoot the issue I took data
from an existing instance of the 'Alert' DataContract and serialized it into
xml. The resulting xml document is this:

<alert xmlns="urnasis:names:tc:emergency:cap:1.1"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">

<addresses i:nil="true" />
<code i:nil="true"
xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays" />
<identifier>43b080713727</identifier>
<incidents i:nil="true" />
- <info>
- <a:AlertInfo>
<a:area i:nil="true" />
<a:audience i:nil="true" />
<a:category i:nil="true" />
<a:certainty>Likely</a:certainty>
<a:contact>test</a:contact>
<a:description>test description</a:description>
<a:effective>0001-01-01T00:00:00</a:effective>
<a:event>lalalala</a:event>
<a:eventCode i:nil="true" />
<a:expires>0001-01-01T00:00:00</a:expires>
<a:headline i:nil="true" />
<a:instruction i:nil="true" />
<a:language>en-US</a:language>
<anSet>0001-01-01T00:00:00</anSet>
<aarameter i:nil="true" />
<a:resource i:nil="true" />
<a:responseType i:nil="true" />
<a:senderName i:nil="true" />
<a:severity>Extreme</a:severity>
<a:urgency>Immediate</a:urgency>
<a:web i:nil="true" />
</a:AlertInfo>
</info>
<msgType>Alert</msgType>
<note i:nil="true" />
<references i:nil="true" />
<restriction i:nil="true" />
<scope>Public</scope>
<sender>hsas@xxxxxx</sender>
<sent>2003-04-02T15:39:01-04:00</sent>
<source i:nil="true" />
<status>Actual</status>
</alert>

As you can see, my problem is that the 'info[]' array is being treated like
a collection and thus is being wrapped with the <info></info> tag following
by each one of the items in the array.

My question is how can make the serialization use a new <info></info> tag
for each item in the array as the previous xsd schema requires?

Thanks for your time.

-sm



My System SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
Fast copy method of sub array (=array range) possible? VB Script
Stupid Array Tricks: Initializing an Array to a Certain Size PowerShell
how to assign values to array and how to create array via variable PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46