I have a WCF method which returns me an array of custom objects like "users", "roles", or something else, and it has page output. WCF method has out parameter, stored procedure select rows and return total records of all rows(not only selected), than i read return value in out parameter. But there is one problem i call WCF-method in lambda expression:
var client = MySvcRef.MySvcClient();
var assistant = FormsAuthenticationAssistant();
var result = assistant.Execute<MySvcRef.UserClass[]>(
() => client.GetAllUsers(out totalRecords, pageIndex, pageSize),
client.InnerChannel);
what better solution for my example?
I haven't tried lambdas with out parameters but normally you just need to declare the variable beforehand:
var client = MySvcRef.MySvcClient();
var assistant = FormsAuthenticationAssistant();
var totalRecords;
var result = assistant.Execute<MySvcRef.UserClass[]>(
()=>client.GetAllUsers(out totalRecords, pageIndex, pageSize),
client.InnerChannel);
Edit:
Your best bet may by to wrap GetAllUsers
with a separate class that can use the out
param:
Temp temp = new Temp();
var result = assistant.Execute<MySvcRef.UserClass[]>(()=>temp.GetAllUsers(client, pageIndex, pageSize),client.InnerChannel);
int totalRecords = temp.TotalRecords;
...
class Temp
{
public int TotalRecords;
public MySvcRef.UserClass[] GetAllUsers(MySvcClient client, int pageIndex, int pageSize)
{
int totalRecords;
var result = client.GetAllUsers(out totalRecords, pageIndex, pageSize);
TotalRecords = totalRecords;
return result;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With