c# - Get Current User within WCF Web service using CSOM on Sharepoint 2010 -
the key part here application running within wcf web service application, , being called url. setup wcf service identical tutorial - https://jobrocol.wordpress.com/2012/06/03/custom-rest-wcf-service-in-sharepoint-2010/comment-page-1/
i created small test, console application. code works intended:
using sp = microsoft.sharepoint.client; public static void addnewitemtosplist() { string siteurl = "http://my.domain.com/"; string subsite = "temp/subsite"; string splist = "generictestlist"; bool returnval = false; try { using (clientcontext clientctx = new clientcontext(siteurl + subsite)) { // default credentials clientctx.credentials = credentialcache.defaultnetworkcredentials; if (doesuserhavepermissions(clientctx, splist, permissionkind.addlistitems)) { sp.list olist = clientctx.web.lists.getbytitle(splist); listitemcreationinformation itemcreateinfo = new listitemcreationinformation(); listitem olistitem = olist.additem(itemcreateinfo); olistitem["title"] = "test"; olistitem.update(); // add new list item clientctx.executequery(); } } } catch (exception e) { console.writeline(e.tostring()); } } public static bool doesuserhavepermissions(clientcontext ctx, string listname, permissionkind permmask) { try { sp.list targetlist = ctx.web.lists.getbytitle(listname); ctx.load(targetlist, t => t.effectivebasepermissions); ctx.executequery(); return targetlist.effectivebasepermissions.has(permmask); } catch { return false; } } static void main(string[] args) { addnewitemtosplist(); }
however, when try similar within wcf application, errors. pretty 401 access denied errors.
i pretty sure issue how i'm getting clientctx.credentials
, i've tried of ways logged in user creds sp site none seem working.
any advice? can include of wcf code pretty identical stand-alone console app proof-of-concept code above.
Comments
Post a Comment