1

I am running a custom web service on a sharepoint server (2010). My script works fine until I make a call to update a database. I get this error:

Exception calling "Update" with "0" argument(s): "Access denied." ---> Access denied.

My web service is written in C#, I'm not sure if I need to add some credentials to my code or I need to make some security changes on the server.

Exception caught:

System.Management.Automation.MethodInvocationException: Exception calling "Update" with "0" argument(s): "Access denied." ---> System.Security.SecurityException: Access denied. at Microsoft.SharePoint.Administration.SPPersistedObject.BaseUpdate() at Microsoft.SharePoint.Administration.SPDatabase.Update() at Update(Object , Object[] ) at System.Management.Automation.DotNetAdapter.AuxiliaryMethodInvoke(Object target, Object[] arguments, MethodInformation methodInformation, Object[] originalArguments) The Zone of the assembly that failed was: MyComputer --- End of inner exception stack trace --- at System.Management.Automation.DotNetAdapter.AuxiliaryMethodInvoke(Object target, Object[] arguments, MethodInformation methodInformation, Object[] originalArguments) at System.Management.Automation.DotNetAdapter.MethodInvokeDotNet(String methodName, Object target, MethodInformation[] methodInformation, Object[] arguments) at System.Management.Automation.Adapter.BaseMethodInvoke(PSMethod method, Object[] arguments) at System.Management.Automation.ParserOps.CallMethod(Token token, Object target, String methodName, Object[] paramArray, Boolean callStatic, Object valueToSet) at System.Management.Automation.MethodCallNode.InvokeMethod(Object target, Object[] arguments, Object value) at System.Management.Automation.MethodCallNode.Execute(Array input, Pipe outputPipe, ExecutionContext context) at System.Management.Automation.ParseTreeNode.Execute(Array input, Pipe outputPipe, ArrayList& resultList, ExecutionContext context) at System.Management.Automation.StatementListNode.ExecuteStatement(ParseTreeNode statement, Array input, Pipe outputPipe, ArrayList& resultList, ExecutionContext context) Exception caught.

Doug
  • 11
  • 2
  • Questions: [1] is the webservice hosted in the same IIS website as the SPS site? [2] what Trust level is your web service running under? [3] where is the DLL for the service? (bin or GAC) –  Jun 13 '14 at 12:32
  • @SujaySarma I deployed the web service files in the ISAPI folder w/ the rest of the web services. My dll is in GAC and C:\inetpub\wwwroot\wss\VirtualDirectories\80\bin – Doug Jun 13 '14 at 12:36
  • Ensure that your SPS site is running with Full Trust and your DLL is codesigned (or has codesign check turned off). –  Jun 13 '14 at 12:53
  • The trust level is WSS_Minimal, would that cause the error? And I did sign the assembly when I created the web service – Doug Jun 13 '14 at 13:01
  • Without more logs, I would say yes. Have you checked the SPS trace log file? Should be in "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\LOGS\" –  Jun 13 '14 at 13:09
  • Actually, my SharePoint Web Services site is running full trust, I do not see a log file from when I ran the web service – Doug Jun 13 '14 at 13:17
  • Just noticed you're updating a database.. Is the connection string set up correctly? Username/password? Is the connection string picked up correctly when your webservice loads? Implement some kind of custom tracing in your webservice to help debug (Event Log is best place to put them). –  Jun 13 '14 at 13:19
  • First off, thanks for the help so far. I've yet to setup any username/password credentials in my code. I'm fairly new to all this so sorry I can't anser your questions perfectly. I added the script that is running above in the question, the web service being called from a workflow in sharepoint and it runs powershell commands. The commands work when I run them in powershell when logged into the server – Doug Jun 13 '14 at 13:27
  • Sharepoint requires code that runs outside of its context to be fully trustable and trustworthy. Because of this, plenty of stuff that would otherwise work in regular IIS websites, win forms or console code will not run when tried from within SPS code. And, it is VERY VERY hard to debug code that is not working. To debug your issue, put plenty of System.Diagnostics.EventLog.WriteEntry() calls in your Update method to find out exactly what line is failing and why (do a Try-catch around the whole thing and write your exception out to the log as well). –  Jun 13 '14 at 13:30
  • I added a try catch and above in my question is the exception I caught – Doug Jun 13 '14 at 13:51
  • Uh oh! You cannot fire updates like that on the SPS Content Database! :( –  Jun 13 '14 at 13:54
  • So there is no way around that access denied error or running those commands I wanted through a web service? :( – Doug Jun 13 '14 at 13:57
  • Have you tried using `AllowUnsafeUpdates`? Some great info on the topic can be found here: http://omicron-llama.co.uk/2014/02/06/fun-with-allowunsafeupdates/ – iOnline247 Jun 15 '14 at 21:38

0 Answers0