1

I'm experiencing a weird problem with one of methods of my wcf service. I have a generic response model, which is working fine for all other services. but for one case, it has a problem. My model is something like:

public class ResponseModel
{
  dynamic Model { get; set; }
  bool success { get; set; }
  string Message { get; set; }
}

I have a method called LoadUsers. If users are found, i populate a list, create a new ResponseModel object, and assign list to Model property. like,

List<UserModel> usersList = GetUsersList(ids);
ResponseModel response = new ResponseModel();
response.Model = usersList;
response.success = true;
return response;

All the logic is executed fine. But i get no response at all. I checked, response is populated fine till the end using breakpoint, but still no response.

Thing that's weird to me is, when usersList is null, which means Model property of the response is null, it works fine. i get response. & secondly, it is my generic model, and working fine for all other methods. I can't figure out the possible reason. Checked out several related questions at SO, but most of them were related to size issues, etc.

services are created for Android devices, and return Json. like:

[OperationContract]
[WebGet(UriTemplate = "LoadUsersList?Key={Key}", ResponseFormat = WebMessageFormat.Json)]
ResponseModel LoadUsersList(string Key);

Rest of the services are being consumed successfully. Kindly help/suggest me to figure out the reason.

Zeeshan
  • 2,884
  • 3
  • 28
  • 47

1 Answers1

0

The reason you do not get a response, but debugging works is because the problem is occurring outside the scope of your service dll. It works for null because the serializer knows about null. It does know about what it is otherwise. The dynamic type will not work in this case and does not make sense in the scope of a data contract. If you know that the Model will be a user List, you should change the type to be List. If it can be other types in addition to List I would recommend setting the type as an interface and marking the possible types in the class with the [ServiceKnownType] attribute.

reference

James Ralston
  • 1,170
  • 8
  • 11