Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Designing WCF interface: no out or ref parameters

Tags:

c#

.net

I have a WCF service and web client. Web service implements one method SubmitOrders. This method takes a collection of orders. The problem is that service must return an array of results for each order - true or false. Marking WCF paramters as out or ref makes no sense. What would you recommend?

[ServiceContact]
public bool SubmitOrders(OrdersInfo)

[DataContract]
public class OrdersInfo
{
  Order[] Orders;
}
like image 297
Captain Comic Avatar asked May 21 '10 12:05

Captain Comic


2 Answers

Marking WCF paramters as out or ref makes no sense.

out parameters do make sense in WCF.

What would you recommend?

I recommend to use out parameters.


Note 1: It will move your out parameter to be the first parameter on you.

Note 2: Yes you can return objects with complex types in WCF. Tag your class with an attribute of [DataContract] and your properties with an attribute of [DataMember].

like image 142
Brian R. Bondy Avatar answered Nov 01 '22 02:11

Brian R. Bondy


Use complex type(another class with DataContract attribute) in return.

Like

[ServiceContact]
public OrdersResult SubmitOrders(OrdersInfo)

[DataContract]
public class OrdersInfo
{
  Order[] Orders;
}

[DataContract]
public class OrdersResult
{
  .....
}

Also add DataMember on Order[] Orders;

like image 37
Incognito Avatar answered Nov 01 '22 02:11

Incognito