Keshavdas M
Keshavdas M

Reputation: 702

WCF: Is it good practice to send null response from Server

I have WCF service where I am processing Customer object and based on that I need to send array of Products related to customer.

So I question is, if there is no products for particular Customer should I return the Null value or empty array of Products to the WCF Client?

Please advise the best approach to do this.

 [OperationContract]   
 Product[] DoProcess(Customer customer);

 if(Product not found by Customer)
 {
      // return null;
      // or
      // return new Product[];
 }

Many thanks in advance.

Upvotes: 2

Views: 384

Answers (2)

Jordi
Jordi

Reputation: 2797

There is no correct answer for that.

If you choose to return nulls on your environment as a "not found", it is ok. If your app is expecting empty arrays, go ahead.

Upvotes: 2

Dhaval Patel
Dhaval Patel

Reputation: 7601

it's better to return new Product[] so at the client side you don't need to check the condition of null.

Upvotes: 2

Related Questions