How can you force WCF to use xs: All instead of xs: Sequence, so the order of the SOAP elements doesn't matter?

How can you use WCF xs: All instead of xs: Sequence when it defines complex object types in wsdl / xsd for a web service?

The problem I am facing is that xs: Sequence requires that the calling application pass the items in the soap message in the order specified in the generated WCF xsd (by default this is alphabetical). xs: Everyone (or the choice for that matter) does not care about the order.

Is it possible to change this behavior simply using a configuration parameter somewhere?

+6
wcf
source share
3 answers

Above my head, I think you can’t. Instead, you can write the WSDL file manually, and then use svcutil.exe to generate the code.

If all you want to do is order items in a different order than alphabetically, you can order the items in a DataContract using the Order parameter (starting with 1, not 0 as arrays) in the [DataMember] ([DataMember () Order = 1)], [DataMember (Order = 2)], etc.).

+3
source share

You can switch WCF to use XmlSerializer instead of DataContractSerializer. XmlSerializer supports xs: all. See http://msdn.microsoft.com/en-us/library/ms733901.aspx

+2
source share

Even if you can force WCF to do this, the deserializer will not work correctly to support input. Examples and explanations below.

Input 1 (good):

<MyOperation> <AField>value A</AField> <BField>value B</BField> </MyOperation> 

Input 2 (bad):

 <MyOperation> <BField>value B</BField> <AField>value A</AField> </MyOperation> 

So, if input 1 is deserialized correctly, then input 2 will not - BField would have the value that was set, but the AField property would be null.

If WCF cannot handle this input out of sequence, I strongly believe that it should throw an exception, but based on my testing (.NET 3.5 in IIS) it does not, it just skips some element values.

In addition, WCF also ignores completely dummy input if it does not affect the valid values ​​of the elements it searches. So this entry

 <MyOperation> <bogusField>with or without data</bogusField> <AField>value A</AField> <bogusField2 /> <BField>value B</BField> <bogusField3></bogusField3> </MyOperation> 

will not cause any errors and actually deserializes the values ​​in AField and BField.

0
source share

All Articles