I think something must not be correct with the serialization. My class is:
[DataContract]
public class User
{
[DataMember]
public int id { get; set; }
[DataMember]
public string user_id { get; set; }
...
public User() { }
public User(int id, string user_id, ...)
{
this.id = id;
this.user_id = user_id;
...
}
}
[DataContract]
public class UserCollection
{
[DataMember]
public List<User> users { get; set; }
[DataMember]
public int count { get; set; }
[DataMember]
public int page { get; set; }
public UserCollection() { }
public UserCollection(List<User> users, int count, int page)
{
this.users = users;
this.count = count;
this.page = page;
}
}
The API call:
[WebGet(UriTemplate = "?promotion_id={promotion_id}&page={page}&format={format}")]
public UserCollection GetAllUsers(string promotion_id, string page, string format)
{
if (string.Equals("json", format, StringComparison.OrdinalIgnoreCase))
WebOperationContext.Current.OutgoingResponse.Format = WebMessageFormat.Json;
UserFactory factory = new UserFactory();
return factory.GetUsersByPromotionID(int.Parse(promotion_id), (int.Parse(page) - 1) * 50, 50);
}
The generated source:
<UserCollection xmlns="http://schemas.datacontract.org/2004/07/API.Library.Resources" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><count>0</count><page>0</page><users/></UserCollection>
It doesn’t display the xml on the page because it says the response type is text/html. Any ideas?
What kind of client are you using to invoke the web service?
You could try