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
Danatas GerviPosted Nov 5, 2009, 11:35 AM
You cannot pass throth WCF object – but you do can send any kind of your own class, - just add to contract interface the atribute
[ServiceKnownType(typeof(TaskStatusEntity))]
[ServiceKnownType(typeof(TaskLocationEntity))]
- that will allow to WCF to know, how to serilize all your classes.
Sure, the client and service both must have the assembly with this types….