Hi all,
I'm somewhat new to development with CS, so please bear with me if I'm missing something simple. I'm using CS 2008.5, and trying to retrieve a log of all conversations that have taken place on the server. For each, I'm looking to log the User IDs of participants and date/userID/subject for each message.
I'm able to retrieve the set of conversations, and the IDs of each user participating in each conversation, but I'm getting errors when I try to access the individual messages. In the code below, "c" is the name for the conversation in a foreach loop, and any attempt to read c.Messages fails. I see the same behavior whether or not the conversations include the user for whom I've created the API key (conversation can't be created without at least impersonating a user who's a member of the conversation.) Likewise, any call to c.LoadMessages() (with any of the various overloads) fails. The code below references LoadMessages(), but I've also tried reading from c.Messages.
I'm using Fiddler to check the HTTP request/response for all of this. The Messages Endpoint in the response to GetConversations appears to be correct - if I put it into a browser, I get a page of XML with all the content I need (messages included). However, the Messages property of the "c in conv" Conversation throws "{System.InvalidOperationException} = {"The requested object was could not be found at this location, invalid Uri"}". This is the same exception I get with any call to LoadMessages().
An example LoadMessages GET/Response is
"GET http://[domain]/cs/api/membership.ashx/conversations/fd2ae371-633d-42bb-b2b4-66c8f924d858/messages/?pageindex=0&pagesize=20 HTTP/1.1"
"<?xml version="1.0" encoding="utf-8"?><Error xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><Type>NotFound</Type><Message>The requested object was could not be found at this location, invalid Uri</Message></Error>"
If I simply remove the "?pageindex=0&pagesize=20" portion of the request, the response contains all messages in the conversation. (I don't know if there's an upper limit to the # of messages this will get me - I don't have more than a few in any conversation.) However, even c.LoadAllMessages() still uses that query string, it just sets the pageindex/pagesize to 0.
How can I access this content? Is this a bug in the API? I'm running version 4.1.40407.4157
Thanks,
--Ethan
----------------------------
PagedList<User> siteUser = m_mbSrv.GetUsers();
foreach (User u in siteUser)
{
MembershipService userService = new MembershipService(CSServerConfig.SiteAddress, CSServerConfig.UserName, CSServerConfig.ApiKey, u.Username);
int pageSize = 20;
int pageNum = 0;
PagedList<Conversation> conv;
do
{
conv = userService.GetConversations(u.Id, pageNum++, pageSize);
foreach (Conversation c in conv)
{
foreach (UserInfo ui in c.Participants)
{
Console.WriteLine("\t" + ui.Id);
}
try
{
c.LoadAllMessages();
foreach (ConversationMessage msg in c.Messages)
{
Console.WriteLine("\tMessage" + msg.Id + ", by " + msg.Author.Id + " on " + msg.DateCreated.ToString());
}
}
catch (System.Net.WebException e)
{
string msg = e.Message;
}
}
}
} while (conv.Count == pageSize);
}
}