F
fraser.elder
I've written a web service that returns an xml document with some
information about documents in a Sharepoint Server, however when I try
to consume the web service I get this error:
Server was unable to process request. --> There was an error generating
the XML document. --> Object reference not set to an instance of an
object.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.
Exception Details: System.Web.Services.Protocols.SoapException: Server
was unable to process request. --> There was an error generating the
XML document. --> Object reference not set to an instance of an object.
Source Error:
Line 35:
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/GetFolder",
RequestNamespace="http://tempuri.org/",
ResponseNamespace="http://tempuri.org/",
Use=System.Web.Services.Description.SoapBindingUse.Literal,
ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
Line 36: public System.Xml.XmlNode GetFolder(string strSite,
string guidWebID, string strURL) {
Line 37: object[] results = this.Invoke("GetFolder", new
object[] {
Line 38: strSite,
Line 39: guidWebID,
Source File: c:\inetpub\wwwroot\SPInterface\Web
References\SPFileInfo\Reference.cs Line: 37
My webmethod looks like this:
[WebMethod]
public XmlDocument GetFolder(string strSite, string guidWebID, string
strURL)
{
StreamWriter sw = new
StreamWriter("C:\\inetpub\\wwwroot\\SPInterface\\LogFile.txt",true);
Guid guidWebID2 = new Guid(guidWebID);
XmlDocument xml = new XmlDocument();
//Find the Sharepoint site
SPSite site = new SPSite(strSite);
//Find the WebID on the Sharepoint site
SPWeb web = site.OpenWeb(guidWebID2);
//Find the folder we need
SPFolder folder = web.GetFolder(strURL);
if (folder.Exists)
{
//Get all the files in the folder
SPFileCollection fileCollection = folder.Files;
foreach (SPFile file in fileCollection)
{
sw.WriteLine("Adding details to array!");
sw.WriteLine("Time : " + DateTime.Now.ToLongTimeString());
sw.WriteLine("Created new document!");
sw.WriteLine("Time : " + DateTime.Now.ToLongTimeString());
XmlElement fileInfo = xml.CreateElement("FileInfo");
sw.WriteLine("Created new element!");
sw.WriteLine("Time : " + DateTime.Now.ToLongTimeString());
fileInfo.SetAttribute("Name", file.Name.ToString());
fileInfo.SetAttribute("FileURL", file.Url.ToString());
fileInfo.SetAttribute("Site", strSite.ToString());
fileInfo.SetAttribute("LastMod", file.TimeLastModified.ToString());
fileInfo.SetAttribute("URL", strURL.ToString());
sw.WriteLine("Adding attributes to element!");
sw.WriteLine("Time : " + DateTime.Now.ToLongTimeString());
}
sw.Flush();
sw.Close();
return xml;
}
After I've added the attributes to the element do I need to do anything
else to the XML document?
My web service runs sucessfully (I know because it writes to the
logfile at each step above).
I'm consuming the web service by doing this:
SPFileInfo.SPFileInfo fileInfo = new SPFileInfo.SPFileInfo();
fileInfo.Credentials = System.Net.CredentialCache.DefaultCredentials;
fileInfo.Url = strWSURL;
XmlNode node = fileInfo.GetFolder(strSite, guidWebID, strURL);
Am I missing anything obvious here? (This is my first go at a
sharepoint interface and web services for that matter!)
Any help is greatly appreciated!
Cheers,
Fraser
information about documents in a Sharepoint Server, however when I try
to consume the web service I get this error:
Server was unable to process request. --> There was an error generating
the XML document. --> Object reference not set to an instance of an
object.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.
Exception Details: System.Web.Services.Protocols.SoapException: Server
was unable to process request. --> There was an error generating the
XML document. --> Object reference not set to an instance of an object.
Source Error:
Line 35:
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/GetFolder",
RequestNamespace="http://tempuri.org/",
ResponseNamespace="http://tempuri.org/",
Use=System.Web.Services.Description.SoapBindingUse.Literal,
ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
Line 36: public System.Xml.XmlNode GetFolder(string strSite,
string guidWebID, string strURL) {
Line 37: object[] results = this.Invoke("GetFolder", new
object[] {
Line 38: strSite,
Line 39: guidWebID,
Source File: c:\inetpub\wwwroot\SPInterface\Web
References\SPFileInfo\Reference.cs Line: 37
My webmethod looks like this:
[WebMethod]
public XmlDocument GetFolder(string strSite, string guidWebID, string
strURL)
{
StreamWriter sw = new
StreamWriter("C:\\inetpub\\wwwroot\\SPInterface\\LogFile.txt",true);
Guid guidWebID2 = new Guid(guidWebID);
XmlDocument xml = new XmlDocument();
//Find the Sharepoint site
SPSite site = new SPSite(strSite);
//Find the WebID on the Sharepoint site
SPWeb web = site.OpenWeb(guidWebID2);
//Find the folder we need
SPFolder folder = web.GetFolder(strURL);
if (folder.Exists)
{
//Get all the files in the folder
SPFileCollection fileCollection = folder.Files;
foreach (SPFile file in fileCollection)
{
sw.WriteLine("Adding details to array!");
sw.WriteLine("Time : " + DateTime.Now.ToLongTimeString());
sw.WriteLine("Created new document!");
sw.WriteLine("Time : " + DateTime.Now.ToLongTimeString());
XmlElement fileInfo = xml.CreateElement("FileInfo");
sw.WriteLine("Created new element!");
sw.WriteLine("Time : " + DateTime.Now.ToLongTimeString());
fileInfo.SetAttribute("Name", file.Name.ToString());
fileInfo.SetAttribute("FileURL", file.Url.ToString());
fileInfo.SetAttribute("Site", strSite.ToString());
fileInfo.SetAttribute("LastMod", file.TimeLastModified.ToString());
fileInfo.SetAttribute("URL", strURL.ToString());
sw.WriteLine("Adding attributes to element!");
sw.WriteLine("Time : " + DateTime.Now.ToLongTimeString());
}
sw.Flush();
sw.Close();
return xml;
}
After I've added the attributes to the element do I need to do anything
else to the XML document?
My web service runs sucessfully (I know because it writes to the
logfile at each step above).
I'm consuming the web service by doing this:
SPFileInfo.SPFileInfo fileInfo = new SPFileInfo.SPFileInfo();
fileInfo.Credentials = System.Net.CredentialCache.DefaultCredentials;
fileInfo.Url = strWSURL;
XmlNode node = fileInfo.GetFolder(strSite, guidWebID, strURL);
Am I missing anything obvious here? (This is my first go at a
sharepoint interface and web services for that matter!)
Any help is greatly appreciated!
Cheers,
Fraser