I am building a web service to pass back a list of (artist) objects. Inside of the artist object there is a list of (album) objects. Inside the Album object there is a list of songs.
SO basically I am building a big parent child tree of music.
My question is, how to I pass this using SOAP?
What is the best method to use.
Right now All I get is
<Artist>
<Name>string</Name>
<Albums>
<AlbumName>string</AlbumName>
<Album xsi:nil="true" />
<Album xsi:nil="true" />
</Albums>
<Albums>
<AlbumName>string</AlbumName>
<Album xsi:nil="true" />
<Album xsi:nil="true" />
</Albums>
</Artist>
It breaks down at albums but it shows two albums which I have stored.
Any Suggestions would be appreciated!
The good news is that a .NET web service will take care of the XML for you. All you have to do is declare the return type as List<Artist>
or similar. The web service will take care of serializing your objects into XML for you. It's not clear if you were rolling your own XML.
The XML you've pasted looks like it came from the WSDL.
Run your project in Visual Studio, and browse to the web service .asmx page. You'll find something like this.
To test the operation using the HTTP POST protocol, click the 'Invoke' button.
Click that button to have your method run.
Perhaps try this simple test WebMethod if your own isn't working as you expect: The result will be this XML doc.
[WebMethod]
public List<Artist> ListAllArtists()
{
List<Artist> all = new List<Artist>();
Album one = new Album { Name = "hi", SongNames = new List<string> { "foo", "bar", "baz" } };
Album two = new Album { Name = "salut", SongNames = new List<string> { "green", "orange", "red" } };
Album three = new Album { Name = "hey", SongNames = new List<string> { "brown", "pink", "blue" } };
Album four = new Album { Name = "hello", SongNames = new List<string> { "apple", "orange", "pear" } };
all.Add(new Artist { Albums = new List<Album> { one }, Name = "Mr Guy" });
all.Add(new Artist { Albums = new List<Album> { two }, Name = "Mr Buddy" });
all.Add(new Artist { Albums = new List<Album> { three, four }, Name = "Mr Friend" });
return all;
}
public class Artist
{
public List<Album> Albums;
public string Name;
}
public class Album
{
public string Name;
public List<string> SongNames;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With