Last post Aug 09, 2013 06:54 PM by Lee Z
Aug 01, 2013 05:43 PM|Lee Z|LINK
I apologize if this is not the correct forum (if so, please direct me to the correct forum).
I have the following architecture that I am attempting to implement in a RESTful web service:
Implementation of OperationContract calls Facade method.
Facade method returns List<object>
Factory classes are used to return List<object> where each concrete class returns its specific List<object>.
Implementation of OperationContract in Web service takes the data and serializes it to either JSON or XML Message based upon input parameter.
The problem that I am having is that the Message is empty since the List returned is List<object>. I must then convert the List<object> back to a strongly typed list which goes against all of the design put in place. For reference, below is the code from
my implementation of OperationContract. Is there a better way to serialize the list of objects? Is there any way to do so without having to iterate through every record?
public Message GetData(string szEntity, string szFunctionCall, string szResponseFormat)
Message msgResult = null;
Facade facade = new Facade();
string szSessionId = string.Empty;
if (WebOperationContext.Current.IncomingRequest != null)
szSessionId = HttpUtility.UrlEncode(HttpContext.Current.Request["token"]);
List<object> entities = facade.GetData(szEntity, WebOperationContext.Current.IncomingRequest.UriTemplateMatch.QueryParameters);
List<Loan> loans = StronglyTypeList<Loan>(entities);
if (szResponseFormat.ToUpper() == "JSON")
msgResult = WebOperationContext.Current.CreateJsonResponse(loans);
msgResult = WebOperationContext.Current.CreateXmlResponse(loans);
private List<T> StronglyTypeList<T>(List<object> entity)
List<T> typedList = new List<T>(entity.Count);
foreach (T item in entity)
Aug 01, 2013 06:04 PM|sukumarraju|LINK
Aug 09, 2013 06:54 PM|Lee Z|LINK
I am going to close this thread as there really is no solution. A dirtier approach (non-factory pattern) had to be used to resolve this.