tags:

views:

120

answers:

3

I have a fixed-sized multidimensional collection exposed via a WCF contract, and I want to be able to return null for any coordinates in the collection that have not been populated. When I try this, I get an exception indicating that this is not supported: "FaultException`1: Object reference not set to an instance of an object."

I wondered whether some flag of OperationContract could be used, but none stand out.

Is what I want possible, or is there some intrinsic restriction within WCF?

Thanks

+3  A: 

Yes they can, mine do all the time. Could you post the relevant bits of your service contract and/or data contracts so we can see where the problem might be?

Christian Hayter
Thanks for the prompt reply. I'll check my workings again, and post further. My apologies for wasting your time, if it turns out I have.
dcw
+3  A: 

In WCF nothing prevents you from returning null from any operation contract method.

The exception you get is a FaultException<NullReferenceException> which means somewhere in your server-side code you are referencing an object which is set to null. Check your server-side code.

Gart
Thanks for the prompt reply. I'll check my workings again, and post further. My apologies for wasting your time, if it turns out I have.
dcw
+1  A: 

As both Gart and Christian stated, you can indeed return null from WCF contract methods. I was in fact caught by my own (attempt at) cleverness, where the external (contract) type was converted from the internal type via an implicit conversion operator, within the implementation of which properties of the internal type were accessed as arguments to the constructor of the external type. Hence the NullReferenceException.

Doh! to me. Cred to G & C. Gart gets the "accept" by a hair, since reading his gave me the lightbulb moment.

dcw