MessageParameterAttribute - using dashes
Hi everyone,
I have spent most of the day searhing for an answer to my question, but have not found anything that solves my problem. I hope some of you can help me out.
I am implementing a WCF service which will accept calls from a third party application. The third pary app has a fixed XML it sends for each of the methods I am required to handle. All simple methods are working, except one where the method accepts an array of custom types as parameter.
My method definition looks like this:
[OperationContract]
[XmlSerializerFormat(Style = OperationFormatStyle.Document, SupportFaults = true, Use = OperationFormatUse.Literal)]
public bool NewDataDeviceRecords(DeviceRecord[] deviceRecords);
By creating a sample project and referencing my service I have verified that most of the XML looks correct. The only problem is the part concerning the 'deviceRecords' parameter.
When the third party app posts, the XML looks like this (for method parameter(s) only!):
<param-1>
<DeviceRecord>
<DeviceId>Item 1</DeviceId>
</DeviceRecord>
<DeviceRecord>
<DeviceId>Item 2</DeviceId>
</DeviceRecord>
</param-1>
When I post with my test client, I get the following (naturally)
<deviceRecords>
<DeviceRecord>
<DeviceId>Item 1</DeviceId>
</DeviceRecord>
<DeviceRecord>
<DeviceId>Item 2</DeviceId>
</DeviceRecord>
</deviceRecords>
The result is that the service fails to parse the <param-1> parameter when the third party app posts.
I have tried using [MessageParameter(Name = "param-1")] in front of the method parameter, but this simply results in the following:
<param1>
<DeviceRecord>
<DeviceId>Item 1</DeviceId>
</DeviceRecord>
<DeviceRecord>
<DeviceId>Item 2</DeviceId>
</DeviceRecord>
</param1>
It simply ignores the dash! Very frustrating!! I have tried HTML encoding and URL encoding without luck. I then decided to try and wrap the static array in a wrapper class DeviceRecordArray which simply holds an array of DeviceRecord objects. I then used the [DataContract(Name = "param-1")] on the class, and [XmlElement("DeviceRecord")] on the contained array. The method signature is now changed to this:
public bool NewDataDeviceRecords(DeviceRecordArray deviceRecords);
This does not solve my problem though. It gives me the correct XML structure now, but it is still encapsulated in an extra (outer) element:
<deviceRecords>
<param-1>
<DeviceRecord>
<DeviceId>Item 1</DeviceId>
</DeviceRecord>
<DeviceRecord>
<DeviceId>Item 2</DeviceId>
</DeviceRecord>
</param-1>
</deviceRecords>
Is there a way to either force the MessageParameterAttribute to accept my dash, or can I use the latter option and somehow remove the extra (outer) element 'deviceRecords'?
Any help is much appreciated!!
/Nicolai