Error when creating a new thread using the REST API

This post has 15 Replies | 4 Followers

Not Ranked
Posts 23
Points 360
Paras Wadehra Posted: Wed, May 14 2008 12:03 AM

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

Not Ranked
Posts 23
Points 360

 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

Top 10 Contributor
Posts 5,284
Points 49,035
CS Developers

Have you tried checking the exception report from within the CS control panel to see if any errors were captured?

  • | Post Points: 35
Not Ranked
Posts 23
Points 360

Yes, I did check but the exception report is empty!

  • | Post Points: 5
Not Ranked
Posts 27
Points 450

Ken,

I encountered the same issue.

And the exception was not found in CS control panel exception report.

Any thoughts?

dr

  • | Post Points: 5
Top 500 Contributor
Posts 48
Points 715

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

  • | Post Points: 20
Not Ranked
Posts 27
Points 450

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.

dr

 

  • | Post Points: 20
Not Ranked
Posts 10
Points 170
ashmach replied on Mon, Sep 15 2008 4:17 PM

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....

  • | Post Points: 35
Not Ranked
Posts 6
Points 105

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);

  • | Post Points: 20
Not Ranked
Posts 27
Points 450
dragonar replied on Wed, Sep 17 2008 1:24 PM

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

  • | Post Points: 35
Not Ranked
Posts 27
Points 450
dragonar replied on Wed, Sep 17 2008 1:28 PM

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.

- dr

  • | Post Points: 5
Not Ranked
Posts 16
Points 200
lsubirana replied on Wed, Sep 17 2008 1:33 PM

Thanks!

  • | Post Points: 5
Not Ranked
Posts 16
Points 200
lsubirana replied on Wed, Sep 17 2008 1:54 PM

Thanks, that worked perfectly.

Once the post is added, is there a way to obtain the post id?

Louis

  • | Post Points: 20
Not Ranked
Posts 27
Points 450
dragonar replied on Wed, Sep 17 2008 2:00 PM

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.

dr

  • | Post Points: 35
Not Ranked
Posts 23
Points 360

ThreadID is not always the same as PostID of the first post in the thread.

Page 1 of 2 (16 items) 1 2 Next > | RSS
Powered by Community Server (Commercial Edition), by Telligent Systems

Copyright© 2008 Telligent Systems Inc. All rights reserved
CommunityServer.com  •  Telligent.com