I am trying to add threads to a forum programmatically using the REST API, but get the following error every time:<!------------------------------------------------------------------------------!>System.Net.WebException: 500 : Exception has been thrown by the target of an invocation. : at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at CommunityServer.WebServices.Services.Common.Rest.RequestHandler.GetResponse(RequestInfo ri, MethodInfo method) at CommunityServer.WebServices.Services.Common.Rest.RequestHandler.ProcessRequest(HttpContext context)
at CommunityServer.WebServices.Common.BaseService.PostResponse(String url, Object body)
at CommunityServer.WebServices.Forums.ForumsService.AddThread(ForumPost post)
at MigrationProject.Form1.btnForums_Click(Object sender, EventArgs e) in C:\Work\CS_Code\Websites\AARF_Code\MigrationProject\Form1.cs:line 142<!------------------------------------------------------------------------------!>My code is as follows:
<!------------------------------------------------------------------------------!>ForumsService serviceThread = new ForumsService("http://localhost/cs/", "admin", "dhu8cbu7");ForumPost forumThread = new ForumPost();forumThread.Body = sqlRdr2["T_Message"].ToString();forumThread.ForumId = Convert.ToInt32(sqlRdr["Forum_ID"]);forumThread.Subject = sqlRdr2["T_Subject"].ToString();serviceThread.AddThread(forumThread); //**************** ERROR ON THIS LINE ****************//<!------------------------------------------------------------------------------!>Can somebody please help me resolve this? I have been scratching my head on this for a while now!Thanks,Paras Wadehra
http://blogs.msdn.com/ParasWadehra
Well, I got past the previous error. But, I am getting another one now:<!------------------------------------------------------------------------------!>System.Net.WebException: The operation has timed out at System.Net.HttpWebRequest.GetResponse() at CommunityServer.WebServices.Serialization.Common.Request.GetResponse() at CommunityServer.WebServices.Common.BaseService.PostResponse(String url, Object body) at CommunityServer.WebServices.Forums.ForumsService.AddThread(ForumPost post) at MigrationProject.Form1.btnForums_Click(Object sender, EventArgs e) in C:\Work\CS_Code\Websites\AARF_Code\MigrationProject\Form1.cs:line 143<!------------------------------------------------------------------------------!>
It is at the same line as before. The interesting thing is that it does add the thread to the database but it still throws the timeout error!Any clues?Regards,Paras Wadehra
Have you tried checking the exception report from within the CS control panel to see if any errors were captured?
Yes, I did check but the exception report is empty!
Ken,
I encountered the same issue.
And the exception was not found in CS control panel exception report.
Any thoughts?
dr
Hi aaarf,
Which version of Community Server did you using? CS2007 or CS2008 SP1 or CS2008.5?
Did you enable REST API?
Take SharePoint to new height
Hi slnavn2000,
I'm using CS 2008 + SP1 for the website and REST API.
I was able to determine the cause of the error, which was due to a special 'box' ASCII (127) character in the body.
Let me know if there are other causes too.
Thanks.
So, I take it threads cannot contain upper ASCII? And no error was reported?
Or, was it something in your String block or Application that thwarted completion. Would appreciate knowing more....
I am trying to use the API to import Threads from our old forums. I am able to create the thread, but the post.Author does not seem to work. The post author ends up being the User I am logging in to the service with.
Can I programatically set the author of a newly created forum post?? If so, how?
Here's my code:
ForumPost post = new ForumPost();User u = ms.GetUser( username );UserInfo ui = new UserInfo(u.Id);post.Author = ui; post.Body = reader.GetString(reader.GetOrdinal("body"));post.ForumId = forumid;post.DateCreated = dateposted;post.Subject = subject;fs.AddThread(post);
Yes, you have to impersonate the author to create his/her post.
Thread below answers your question
http://dev.communityserver.com/forums/p/500054/630408.aspx#630408
- dr
Whenever, the body or subject of the post had this special character (box) during creation,REST API would throw the exception.
Yes, this exception was not recorded as I did not find it in the control panel.
Thanks!
Thanks, that worked perfectly.
Once the post is added, is there a way to obtain the post id?
Louis
The 'FirstPost' of the thread object will provide all that.
I think for threads, the ThreadId is the same as PostId of the first post.
ThreadID is not always the same as PostID of the first post in the thread.
Copyright© 2008 Telligent Systems Inc. All rights reserved CommunityServer.com • Telligent.com