This question is very similar to this one: Not all parameters in WCF data contract make it through the web service call. However, the answer provided there did not solve my problem.
This is my service-code:
using System.Runtime.Serialization;
using System.ServiceModel;
namespace SoapUiToWcf
{
[ServiceContract]
public interface IWcfTest
{
[OperationContract]
WcfData ReturnRequest(WcfData wcfData);
}
[DataContract]
public class WcfData
{
[DataMember(Order = 1)]
public WcfDataNested NestedData { get; set; }
public class WcfDataNested
{
[DataMember(Order = 2)]
public string Foo { get; set; }
[DataMember(Order = 3)]
public string Bar { get; set; }
}
}
public class WcfTest : IWcfTest
{
public WcfData ReturnRequest(WcfData wcfData)
{
return wcfData;
}
}
}
The service should return the identical data which was sent to it. When i send a request through SoapUI with the data below, everything works fine and i get all the values back which have been sent:
<soapenv:Envelope><soapenv:Header/><soapenv:Body><tem:ReturnRequest><tem:wcfData>
<soap:NestedData>
<soap:Bar>bar</soap:Bar>
<soap:Foo>foo</soap:Foo>
</soap:NestedData>
</tem:wcfData></tem:ReturnRequest></soapenv:Body></soapenv:Envelope>
but if i swap the Bar
- and Foo
-fields in the request, the wcf-service only receives the foo-value, the other one is null:
<a:Bar i:nil="true"/>
<a:Foo>foo</a:Foo>
EDIT
Screenshot 1 (request and respone in SoapUI):
Screenshot 2 (Debugging in Visual Studio):
How do i have to implement the wcf-service in order not to be dependent of the sort-order of the fields in the request?