Saiyed Alam

Saiyed Alam

  • NA
  • 1
  • 0

How to pass generic object in wcf service....

Nov 5 2009 4:50 AM
Hello

I want to write a wcf service where there will be a generic list of object as a parameter and a enum to define the type of object. The generic object can have a single entity or multiple entities. And the entity can be a single Client or a collection of Clients or may be a single Employee or a Collections of Employees and so on. But the problem is wcf service don't take any kind of generic object as a parameter.

Is there any way to this?
What I want to do is something like below:

In the Client side the method will be..


public string EmployeeInformation(List<Employee> objEmployee)
{
try
{

string IsSuccess = "";
WCF_Service_Reference objWCFService = new WCF_Service_Reference();
List<Object> objList = objEmployee;
IsSuccess = objWCFService.ActionMapping(objList,(int)EnumEntities.Employee);
return IsSuccess;
}
catch()
{
-----
------
}
}



At the server in WCFService.svc.cs file the implementation of the service should be some thing similar like below:



public string ActionMapping(List<Object> objList, int nEntityInfo)
{

(EnumEntities) EnumEnt = (EnumEntities)nEntityInfo;

swicth(EnumEnt)
{
case EnumEnt.Employee :
List<Employee> objEmployee = objList;
PerformOperation(objEmployee);
break:

case EnumEnt.User:
List<User> objUser = objList;
PerformOperation(objUser);
break;

case EnumEnt.Bank:
List<Bank> objBank = objList;
PerformOperation(objBank);
break;

default:
break:

}
}



The problem is that the service not taking List<Object> objList as a Serialized object which is obvious why. But Is there any way to do the same some how. so that I can use only one service method for all of my entities. Any help or hints would be highly appreciated.


Thanking in Advance
Johnny

Answers (1)