Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. WCF and WF
  4. Use of Generic Object in WCF Service

Use of Generic Object in WCF Service

Scheduled Pinned Locked Moved WCF and WF
helpcsharpwcfsysadminquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Saiyed Alam
    wrote on last edited by
    #1

    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 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 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 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

    S 1 Reply Last reply
    0
    • S Saiyed Alam

      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 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 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 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

      S Offline
      S Offline
      Sir Dot Net
      wrote on last edited by
      #2

      The main thing is that the service needs to understand the message structure that it is expecting to receive, otherwise deserialization can't occur properly. The call you mentioned isn't really strongly typed, so you will have trouble getting it to work. If you had to try, you might look into the KnownType attribute for service contracts, however, I would highly recommend redesigning the service to utilize individual calls for each type, as it is more compliant with SOA standards. Something like: public string ActionMappingEmployee(Employee[] objList, int nEntityInfo); public string ActionMappingCompany(Company[] objList, int nEntityInfo); public string ActionMappingUser(User[] objList, int nEntityInfo);

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups