Hi
I try to get listitem from Sharepoint, and I receive this message
Exception of type Microsoft.SharePoint.SoapS
erver.Soap
ServerExce
ption was thrown
This is my code. I have a reference to my Sharepoint Server and I work on my localhost on my work computer.
I have a problem with this line of code after de command try:
System.Xml.XmlNode nodeListItems = listService.GetListItems(l
istName, viewName, ndQuery, ndViewFields, rowLimit, ndQueryOptions);
Thanks for your help
[WebMethod]
public string GetItemList(string sListName)
{
string sReturn="";
WindowsPrincipal p =(WindowsPrincipal)HttpCon
text.Curre
nt.User;
WindowsIdentity id = (WindowsIdentity)p.Identit
y;
//Response.Output.Write("<
h2>Process
running as {0}</h2>",
//WindowsIdentity.GetCurre
nt().Name)
;
// impersonate temporarily
WindowsImpersonationContex
t wic = id.Impersonate();
// Declare and initialize a variable for the Lists Web Service.
SharepointList.Lists listService = new SharepointList.Lists();
// Set the Url property of the service for the path to a subsite.
listService.Url = "
https://intranet.2020.net/_vti_bin/Lists.asmx";
/* Authenticate the current user by passing their default
credentials to the Web Service from the system credential cache.*/
listService.Credentials = System.Net.CredentialCache
.DefaultCr
edentials;
// Instantiate an XmlDocument object
System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
/* Assign values to the string parameters of the GetListItems method,
using GUIDs for the listName and viewName variables*/
string listName = "{17991794-81BB-494F-9910-
CFBF1093A7
CF}";
string viewName = "{7137FFF8-48FF-4C69-8C76-
0E3BBD1EA7
F9}";
string rowLimit = "150";
/*Use the CreateElement method of the document object to create elements
for the parameters that use XML*/
System.Xml.XmlElement ndQuery = xmlDoc.CreateElement("Quer
y");
System.Xml.XmlElement ndViewFields = xmlDoc.CreateElement("View
Fields");
System.Xml.XmlElement ndQueryOptions = xmlDoc.CreateElement("Quer
yOptions")
;
/*To specify values for the parameter elements (optional), assign CAML fragments
to the InnerXml property of each element*/
ndQuery.InnerXml = "<Where><Gt><FieldRef Name=\"ID\" />" +
"<Value Type=\"Counter\">3</Value>
</Gt></Whe
re>";
ndViewFields.InnerXml = "<FieldRef Name=\"Title\" />";
ndQueryOptions.InnerXml = "";
/* Declare an XmlNode object and initialize it with the XML response from
the GetListItems method.*/
try
{
System.Xml.XmlNode nodeListItems = listService.GetListItems(l
istName, viewName, ndQuery, ndViewFields, rowLimit, ndQueryOptions);
// Loop through each node in the XML response and display each item.
foreach (System.Xml.XmlNode listItem in nodeListItems)
{
sReturn += listItem.OuterXml;
}
}
catch(Exception e)
{
sReturn = e.Message;
}
finally
{
wic.Undo();
}
return sReturn;
}