Calling Sharepoint 2013 methods as services using WCF

webservice can transfer dataset but not generic lists
where as wcf can transfer both dataset and lists

sp object model cant be accessed in normal appln.sp context will come only if appln is hosted in sp like gmc ,ecg applns.

for accessing sp object model in web appln u have to expose those sp methods as webservices in sp machine and consume them in the web appln.

host webservice in sharepoint and consuming (2007 sharepoint.using disco command)

sharepoint service network credentials authentication

how to add a new item to sharepoint list programmatically

addding files to doc library
document library

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\LOGS

host wcf service in sharepoint and consuming : (select sharpoint 2010 empty project sharepoint template.add service reference and not web reference)
authentication : anonymous enabled
error :The HTTP request is unauthorized with client authentication scheme ‘Negotiate’. The authentication header received from the server was ‘NTLM’.

wcf specified column is added
Failed to convert key to token – The public key for assembly ‘(null)’ was invalid when running the sn command to know the publickeytoken of an asembly

ERROR: When trying to know the Public key token fo the strong assembly using sn command you may receive an error as below:
Failed to convert key to token — The public key for assembly ‘(null)’ was inval id.

SOLUTION: This error comes because the command options are case sensitive. The option Tp is case sensitive.
C:\Program Files\Microsoft Visual Studio 9.0\VC>sn -Tp \PendingTaskReport.dll

Error : Service Reference Error: Failed to generate code for the service reference
soln: Have to uncheck the Reuse types in all referenced assemblies from Configure service reference option

An unhandled exception of type ‘System.TimeoutException’ occurred in mscorlib.dll

Additional information: The request channel timed out while waiting for a reply after 00:00:59.8750656. Increase the timeout value passed to the call to Request or increase the SendTimeout value on the Binding. The time allotted to this operation may have been a portion of a longer timeout.


if u have people as column in document library or list then u have to insert value there like below (use elevateprivileges)
How to Insert?

Let us suppose, you need to add more than one user at single time in SharePoint List. Users’ values may come from an Active Directory or metadata. All the users are in a string as comma or semicolon separated value. Let us suppose users are in below format.

string usercontrolvalue = “dhananjay,arun,anoj,patra,mub”;

We need to inert these multiple users in a column of type People or Group in SharePoint list.

Step 1

First we need to split name of all the users from the string. Since in our case users are comma separated so below code will make a string array with users as value at different index.

string[] userarray = usercontrolvalue.Split(‘,’);

Step 2

Now we need to convert users as string to SPFieldUserValue. Below function is taking user name as string and converting that into SPFieldUserValue.

_Web variable is denoting current web where List is part of.

public SPFieldUserValue ConvertLoginName(string userid)
SPUser requireduser = _web.EnsureUser(userid);
SPFieldUserValue uservalue = new SPFieldUserValue(_web, requireduser.ID, requireduser.LoginName);
return uservalue;

Step 3

We need to make instance of SPFieldUserValueCollection

SPFieldUserValueCollection usercollection = new SPFieldUserValueCollection();

Step 4

For all the user; we need to convert that as SPFieldUserValue then add that them to SPFieldUserValueCollection instance

for (int i = 0; i < userarray.Length; i++)
SPFieldUserValue usertoadd = ConvertLoginName(userarray[i]);

Only we need to perform above said task. For your reference entire code as below,

Entire code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.SharePoint;
namespace TestingMultipleUsre
public partial class _Default : System.Web.UI.Page
SPWeb _web;
SPSite _site;
SPList myList
protected void Page_Load(object sender, EventArgs e)
string usercontrolvalue = "dhananjay,arun,anoj,patra,mub";
_site = new SPSite("http://adfsaccount:2222/&quot;);
_web = _site.OpenWeb();
myList = _web.Lists["TestingUser"];
_web.AllowUnsafeUpdates = true ;
myList = _web.Lists["TestingUser"];
SPListItem item = myList.Items.Add();
SPFieldUserValueCollection usercollection = new SPFieldUserValueCollection();
string[] userarray = usercontrolvalue.Split(',');
for (int i = 0; i cd c:\windows\syswow64\inetsrv

c:\Windows\SysWOW64\inetsrv>appcmd.exe list config -section:system.webServer/ser

c:\Windows\SysWOW64\inetsrv>appcmd.exe set config -section:system.webServer/serv
erRuntime /uploadReadAheadSize:”204800″
Applied configuration changes to section “system.webServer/serverRuntime” for “M

in vs command prompt :
at the solution/bin/debug folder type : sn -T “dllname” (for getting strong name) …u will get publickeytoken of that assembly
at the solution/bin/debug foder type : gacutil -i “dllname”(for keeping into gac)
at C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI type disco http://skeltadtptest:1111/_vti_bin/final/service.asmx.

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: