Getting xsi:nil’s on array items which are null instances  
Author Message
Kris M.





PostPosted: ASMX Web Services and XML Serialization, Getting xsi:nil’s on array items which are null instances Top

Hello,

i have two DTO-classes (Data Transfer Objects) A and B. Class A contains a member which is an array of Class B instances. I have to pass class A to an Java-WebService. The Encoding of the Java-WebService is RpcEncoded. So my WebService-Client has SoapRpcMethodAttribute’s on each method. This works so far.

The problem is, when i have null references in the array (~of Class B instances), i always get for them xsi:nil’s in my SOAP-message like you can see below - never mind what Attributes i set on the property in Class A (the name of the property is "infos").


These are the relevant lines of the SOAP-message:

..
<infos href="#id2" />
..
<soapenc:Array id="id2" soapenc:arrayType="tns:B[5]">
<Item xsi:nil="true" />
<Item xsi:nil="true" />
<Item xsi:nil="true" />
<Item xsi:nil="true" />
<Item xsi:nil="true" />
</soapenc:Array>

..

Like you can see, there are 5 times xsi:nil’s resulting for an array, containing 5 times a null reference.

How can i prevent the .NET-Framework from "nilling" those null-references I don’t want to encode them to xsi:nil! I just want to let out those lines, if there is a null reference in the array on that position. I have tried nearly any Attribute from System.Xml.Serialization!

Who can help, please

Thx and best regards,
Kris


ps: I am using .NET-Framework v1.1.





.NET Development36  
 
 
Elena Kharitidi





PostPosted: ASMX Web Services and XML Serialization, Getting xsi:nil’s on array items which are null instances Top

If you are using [SoapRpcMethod], the serialization of your messages no longer conforms to schema, but done using Soap Section 5 encoding (see http://www.w3.org/TR/2000/NOTE-SOAP-20000508/#_Toc478383512 for the details). You can change the message a little by using [SoapElementAttribute] attributes, but not the Array serializatoin.

If you want to have better control over the message, you need to use [SoapRpcMethod(Use=SoapBindingUse.Literal)], in which case the [Xml..Attribute] serialization attributes will controll the serialization of the message.

Thanks,

Elena


 
 
Elena Kharitidi





PostPosted: ASMX Web Services and XML Serialization, Getting xsi:nil’s on array items which are null instances Top

I just noticed that you are using .Net Framework V1.1, unfortunately support for rpc\literal messages was added only in V2.0.

Can you preo-precess your array to remove the nulls


 
 
Kristijan M.





PostPosted: ASMX Web Services and XML Serialization, Getting xsi:nil’s on array items which are null instances Top

 Hi,

 

thank you for your reply.

 

Yes, thats exactly the workaround which i implemented now: i pre-processed the array, so i have no null-elements in it. Now, the Axis WebService (RPC-encoded) can handle my messages, BUT only if i have 1 or more elements in it. If the array is empty, the result of the Message-Serialization is looking something like this:

..
<infos href="#id2" />
..
<soapenc:Array id="id2" soapenc:arrayType="tns:B[0]">
..

This cause the Axis-WebService to throw again a NullReferenceException. My partner already told me, that this is probably an Axis-Bug. He will hotfix this soon. But, nevertheless, i would like to know, what to change to get my serialization producing this for an empty array:

..
<infos xsi:null="true" />
..

 

Regards,

Kris


 
 
Elena Kharitidi





PostPosted: ASMX Web Services and XML Serialization, Getting xsi:nil’s on array items which are null instances Top

This is not a bug: the serialization attributes starting with "Xml" prefix will not work for rpc\encoded messages, they only work for literal messages (this is by design). when you use rpc\encoded messages ([SoapRpcMethodAttribute] will result in rpc\encoded messages) you have very little control over the way message is serialized.

I sugested to switch to rpc\literal messages, but the .net 1.1 does not support the feature: it was added in V2.

Thanks,

Elena


 
 
Kristijan M.





PostPosted: ASMX Web Services and XML Serialization, Getting xsi:nil’s on array items which are null instances Top



I