I'm integrating with BigBlueButton API with Asp Net MVC. But I can't read the response xml file back from api . It's a force module project.
My code:
public ActionResult GetMeetings()
{
List<AllMeetings> allMeetings = new List<AllMeetings>();
XmlSerializer serializer = new XmlSerializer(typeof(List<AllMeetings>), "response");
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://bbb.hsu.ac.ir/bigbluebutton/api/getMeetings?checksum=aca692f682f06312cb43f14564ddf96cb76925ed");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream dataStream = response.GetResponseStream();
StreamReader sr = new StreamReader(dataStream);
List<AllMeetings> allMeeting =(List<AllMeetings>)serializer.Deserialize(sr);
return View(allMeeting);
}
I coded a class so that I could define attributes as xml element and I use them as an enumerable model
namespace BBBJavaScriptTest
{
[Serializable]
[XmlType("response")]
public class AllMeetings
{
[XmlElement(ElementName = "meetingName")]
public string meetingName { get; set; }
[XmlElement(ElementName = "meetingID")]
public string meetingID { get; set; }
[XmlElement(ElementName = "createDate")]
public string createDate { get; set; }
[XmlElement(ElementName = "voiceBridge")]
public string voiceBridge { get; set; }
[XmlElement(ElementName = "moderatorPW")]
public string moderatorPW { get; set; }
public AllMeetings()
{
}
}
and the view part is Razor View:
@model IEnumerable<AllMeetings>
@{
ViewBag.Title = "GetMeetings";
Layout = null;
}
<h2>GetMeetings</h2>
<table class="table table-bordered">
<tr>
<td>meetingID</td>
<td>meetingName</td>
<td>createDate</td>
<td>voiceBridge</td>
<td>moderatorPW</td>
</tr>
@foreach (var item in Model)
{
<tr>
<td>@item.meetingID</td>
<td>@item.meetingName</td>
<td>@item.createDate</td>
<td>@item.voiceBridge</td>
<td>@item.moderatorPW</td>
</tr>
}
</table>
Response sample:
<response>
<returncode>SUCCESS</returncode>
<meetings>
<meeting>
<meetingName>****</meetingName>
<meetingID>****</meetingID>
<internalMeetingID>
****
</internalMeetingID>
<createTime>1603543982183</createTime>
<createDate>Sat Oct 24 16:23:02 IRST 2020</createDate>
<voiceBridge>78409</voiceBridge>
<dialNumber>****</dialNumber>
<attendeePW>ap</attendeePW>
<moderatorPW>mp</moderatorPW>
<running>true</running>
<duration>400</duration>
<hasUserJoined>true</hasUserJoined>
<recording>false</recording>
<hasBeenForciblyEnded>false</hasBeenForciblyEnded>
<startTime>1603543982435</startTime>
<endTime>0</endTime>
<participantCount>1</participantCount>
<listenerCount>1</listenerCount>
<voiceParticipantCount>0</voiceParticipantCount>
<videoCount>0</videoCount>
<maxUsers>0</maxUsers>
<moderatorCount>1</moderatorCount>
<attendees>
<attendee>
<userID>****</userID>
<fullName>****</fullName>
<role>MODERATOR</role>
<isPresenter>true</isPresenter>
<isListeningOnly>true</isListeningOnly>
<hasJoinedVoice>false</hasJoinedVoice>
<hasVideo>false</hasVideo>
<clientType>HTML5</clientType>
</attendee>
</attendees>
<metadata> </metadata>
<isBreakout>false</isBreakout>
</meeting>
</meetings>
</response>
I solved the problem , And here is the solution :
XDocument doc = XDocument.Load(sr);
List<AllMeetings> meetings = new List<AllMeetings>();
foreach (XElement element in doc.Element("response").Elements("meetings").Elements("meeting"))
{
AllMeetings newMeeting = new AllMeetings();
newMeeting.meetingName = (string)element.Element("meetingName");
meetings.Add(newMeeting);
}
return View(meetings);