Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can WCF contract methods return null?

Tags:

.net

wcf

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

like image 986
dcw Avatar asked Dec 31 '25 19:12

dcw


1 Answers

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.

like image 104
Gart Avatar answered Jan 02 '26 08:01

Gart