I'm new to RestSharp and trying to access my subsonic server through the subsonic-api. Every Response in wrapped in a subsonic-response Tag, e.g.
<subsonic-response xmlns="http://subsonic.org/restapi"
status="ok" version="1.10.1">
<artists ignoredArticles="The El La Los Las Le Les">
<index name="A">
<artist id="5449" name="A-Ha" coverArt="ar-5449" albumCount="4"/>
<artist id="5421" name="ABBA" coverArt="ar-5421" albumCount="6"/>
<artist id="5432" name="AC/DC" coverArt="ar-5432" albumCount="15"/>
<artist id="6633" name="Aaron Neville" coverArt="ar-6633" albumCount="1"/>
</index>
<index name="B">
<artist id="5950" name="Bob Marley" coverArt="ar-5950" albumCount="8"/>
<artist id="5957" name="Bruce Dickinson" coverArt="ar-5957" albumCount="2"/>
</index>
</artists>
Xsd generated the following classes for serialization:
public partial class Response
{
private object itemField;
private ItemChoiceType itemElementNameField;
private ResponseStatus statusField;
private string versionField;
[System.Xml.Serialization.XmlChoiceIdentifierAttribute("ItemElementName")]
public object Item
{
get
{
return this.itemField;
}
set
{
this.itemField = value;
}
}
[System.Xml.Serialization.XmlIgnoreAttribute()]
public ItemChoiceType ItemElementName
{
get
{
return this.itemElementNameField;
}
set
{
this.itemElementNameField = value;
}
}
public ResponseStatus status
{
get
{
return this.statusField;
}
set
{
this.statusField = value;
}
}
public string version
{
get
{
return this.versionField;
}
set
{
this.versionField = value;
}
}
}
public partial class ArtistsID3
{
private List<IndexID3> indexField;
public ArtistsID3()
{
this.indexField = new List<IndexID3>();
}
public List<IndexID3> index
{
get
{
return this.indexField;
}
set
{
this.indexField = value;
}
}
}
public enum ItemChoiceType
{
/// <remarks/>
album,
/// <remarks/>
albumList,
--- snip ----
When I'm trying to deserialize into a Response-Object the field Item is always null and ItemElementName gets the first value from the enum ItemChoiceType but version and status are correctly set. The retrieved xml-output looks like expected (see sample). What works though is deserializing into ArtistsID3 but then I loose the status.
Here's the code:
SubsonicApi api = new SubsonicApi();
var request = new RestRequest();
request.Resource = "getArtists.view";
request.AddParameter("v", "1.10.2");
request.AddParameter("c", "no name yet");
// Item always null!
// var response = api.Execute<Response>(request);
var response = api.Execute<ArtistsID3>(request);
public T Execute<T>(RestRequest request)
where T : new()
{
var client = new RestClient();
client.BaseUrl = new System.Uri(BaseUrl);
client.Authenticator = new HttpBasicAuthenticator(_accountSid, _secretKey);
var response = client.Execute<T>(request);
Console.WriteLine("RESPONSE-DATA: " + response.Content);
return response.Data;
}
I'd be glad if somebody could point me in the right direction as I think the right way should be accessing the data through an Response object. Really don't know how to debug this not expected behaviour.
try this