Updating SharePoint from Silverlight using WCF

Jun 6, 2009 at 7:14 PM

Hello,

Can I update a SP list from a WCF service saved on the SP site?  Pulling from SP works fine; adding/updating a SP list is not.  Code goes through when debugging WCF, no problems, but no update happens.  Any ideas?  Thanx.

SPWeb web = SPContext.Current.Site.OpenWeb();

 

<font size="2">

 

</font>

 

SPList myList = web.Lists["Conference Room Requests"];<font size="2">

 

</font>

SPListItem myItem = myList.Items.Add();

<font size="2" color="#2b91af"><font size="2" color="#2b91af">

 

</font></font><font size="2" color="#2b91af">

 

</font>

myItem["Title"] = req.RequestTitle.ToString();<font size="2">

myItem[

</font>

"Conference Room"] = req.RequestLocation.ToString();<font size="2">

myItem[

</font>

"Request Start Time"] = req.RequestStart.ToString();<font size="2">

myItem[

</font>

"Request End Time"] = req.RequestEnd.ToString();

myList.Update();

Also tried converting req.RequestStart and req.RequestEnd to DateTime.  No different.

<font size="2">

 

</font>

 

Jun 6, 2009 at 7:18 PM

Sorry for not clearing the HTML first.

SPWeb web = SPContext.Current.Site.OpenWeb();
SPList myList = web.Lists["Conference Room Requests"];
SPListItem myItem = myList.Items.Add();
myItem["Title"] = req.RequestTitle.ToString();
myItem["Conference Room"] = req.RequestLocation.ToString();
myItem["Request Start Time"] = req.RequestStart.ToString();
myItem["Request End Time"] = req.RequestEnd.ToString();
myList.Update();

Thanks,

David

Coordinator
Jun 15, 2009 at 1:58 AM

David - Yes you should be able to update as well. Any specifics on why it doesn't seem to work for you? What's the error message!?

Jun 16, 2009 at 7:57 PM

No error message. Nothing in App logs, SP logs or Fiddler.  I debug through WCF assembly with no errors, but no results.  I am instead building an ASPX page in SP for data entry, and linking from SL control, since this must be deployed soon.

Thx,

David

Jun 24, 2009 at 10:30 PM
Sahil,
Here are some details:
- The WCF works fine when pulling information from any SharePoint list, but updating is another story.
- clientaccesspolicy.xml in place and working from root of SharePoint site
- in my code (which makes API call to add a record to a list), I can debug to see that SPContext.Current.Site is correct, and SPContext.Current.Web.CurrentUser is SHAREPOINT/System
- I set web.AllowUnsafeUpdates = true
- Fiddler reports the following, which does not make sense:

You are not authorized to view this page


You do not have permission to view this directory or page using the credentials that you supplied.
...........

HTTP Error 401.1 - Unauthorized: Access is denied due to invalid credentials.
Internet Information Services (IIS)

Any ideas?
Thanks,
David


From: sahilmalik [mailto:notifications@codeplex.com]
Sent: Sunday, June 14, 2009 8:59 PM
To: Ridenour, David A
Subject: Re: Updating SharePoint from Silverlight using WCF [SPWCFSupport:58656]

From: sahilmalik

David - Yes you should be able to update as well. Any specifics on why it doesn't seem to work for you? What's the error message!?

Coordinator
Jun 27, 2009 at 6:12 AM

Okay 401 can have MANY reasons, so this is one of the toughest errors to diagnose remotely. Think of 401 as a WTF catch-all error in fact. If you're using Win2k8, try enabling trace logging, and see exactly where the 401 is getting generated from.

Jul 2, 2009 at 5:12 PM

David, the problem is you are calling .Update() on the SPList instead of the SPListItem you created. change myList.Update() to myItem.Update() and it should work.

 In terms of the 401 in fiddler, 401's are normal on a site that requires authentication as an anonymous attempt is made first, and the 401 triggers a second HTTP request which contains the credentials you need. It's when you get a 401 from the follow up request that you've got a problem (or if the follow up request never happens, which can be the case for a variety of reasons.)

Jul 4, 2009 at 12:31 AM
That was correct. Thanks for your help!
David


From: jbongaarts [mailto:notifications@codeplex.com]
Sent: Thursday, July 02, 2009 12:13 PM
To: Ridenour, David A
Subject: Re: Updating SharePoint from Silverlight using WCF [SPWCFSupport:58656]

From: jbongaarts

David, the problem is you are calling .Update() on the SPList instead of the SPListItem you created. change myList.Update() to myItem.Update() and it should work.

In terms of the 401 in fiddler, 401's are normal on a site that requires authentication as an anonymous attempt is made first, and the 401 triggers a second HTTP request which contains the credentials you need. It's when you get a 401 from the follow up request that you've got a problem (or if the follow up request never happens, which can be the case for a variety of reasons.)