Hello,
I've been searching and trying different things for weeks now and at least now my application is working - some of the time. Basically I created a DataView based front end to some lists on Sharepoint for finicky users. It works sometimes. I get the The request failed with HTTP status 401: Unauthorized. error every so often and it seems to happen for a while, then be non-existent for a while, but always comes back. I thought it had to do with my publishing over the WAN, maybe something was getting corrupted or old code cached on the server, but I've completely cleaned everything on the ASP.NET server's cache. So its really random, almost like a timeout, but why the Unauthorized error?
The architecture goes as follows. My asp.net app server is standalone calling another sharepoint server's load balancing server (This is a MS Project enterprise 2007 sharepoint server if it makes and difference). I am not using defaultcredentials due to the multi-hopping issues, therefore I am using a domain account with admin access on all of the servers/services which are involved here. All the app servers are from my knowledge on the same LAN, I'm just developing from the other side of the Atlantic, so my publish jobs are the only things subject to WAN.
I have built 5 seperate ascx controls, each of which call the lists.asmx seperately for different list data, all of these ascx controls are then consolidated into a single aspx page. It's a mashup/dashboard. I am using an objectdatasource/custom classes for the lists.asmx interaction with the ascx. On any given page view, some of the lists.amsx calls work, while others return with the 401 error. Sometimes none work, sometimes they all work. It's really driving me mad!
My code sample from one of my controls which I notice most often failing is:
try
{
//Get List information
System.Data.SqlClient.
SqlConnection sConn = new System.Data.SqlClient.SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["eReportingDBConnectionString"].ConnectionString);
SqlDataAdapter daListInfo = new SqlDataAdapter("SELECT * FROM AllLists WHERE (SAP_GLOBAL_PS_NR = '" + pid + "') AND (tp_Title = 'Project Action Item List (PAIL)')", sConn);
DataTable dtListInfo = new DataTable("AllLists");
daListInfo.Fill(dtListInfo);
/*Declare and initialize a variable for the Lists Web service.*/
com.contiwan.cw01.rbgs795a.
Lists listService = new com.contiwan.cw01.rbgs795a.Lists();
/*Authenticate the current user by passing their default
credentials to the Web service from the system credential cache.*/
url = dtListInfo.Rows[0][4].ToString();
//Temporarily using a default admin user for all web service interactions due to issues with Delegation of impersonated user. To resolve later.
//listService.Credentials = System.Net.CredentialCache.DefaultCredentials;
listService.Credentials =
new System.Net.NetworkCredential(ConfigurationSettings.AppSettings["WSS_ACCESS_UID"], ConfigurationSettings.AppSettings["WSS_ACCESS_PWD"], ConfigurationSettings.AppSettings["WSS_ACCESS_DOMAIN"]);
listService.PreAuthenticate =
true;
/*Set the Url property of the service for the path to a subsite.*/
listService.Url =
"https://" + ConfigurationSettings.AppSettings["MSPE_WSS_Hostname"] + "/" + dtListInfo.Rows[0][4].ToString() + "/_vti_bin/Lists.asmx";
// 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. For listName, using the list display name will also work, but using the list GUID is recommended. For viewName, only the view GUID can be used. Using an empty string for viewName causes the default view
to be used.*/
string listName = "{" + dtListInfo.Rows[0][1].ToString() + "}";
string viewName = "";
string rowLimit = "";
/*Use the CreateElement method of the document object to create elements for the parameters that use XML.*/
System.Xml.
XmlElement query = xmlDoc.CreateElement("Query");
System.Xml.
XmlElement viewFields =
xmlDoc.CreateElement(
"ViewFields");
System.Xml.
XmlElement queryOptions =
xmlDoc.CreateElement(
"QueryOptions");
/*To specify values for the parameter elements (optional), assign CAML fragments to the InnerXml property of each element.*/
query.InnerXml =
"<Where><And><Neq><FieldRef Name='Identifier' /><Value Type='Text'>D</Value></Neq><Eq><FieldRef Name='Mgt_x002e__x0020_Attention' /><Value Type='Text'>Yes</Value></Eq></And></Where>";
viewFields.InnerXml =
"<FieldRef Name=\"ID\" /><FieldRef Name=\"Identifier\" /><FieldRef Name=\"Mgt_x002e__x0020_Attention\" />";
queryOptions.InnerXml =
"";
/* Declare an XmlNode object and initialize it with the XML response from the GetListItems method. The last parameter specifies the GUID of the Web site containing the list. Setting it to null causes the Web site specified by the Url property to be used.*/
///* For list items */
System.Xml.
XmlNode retNode = listService.GetListItems(listName, viewName, query, viewFields, rowLimit, queryOptions, null);
/*Loop through each node in the XML response and display each item.*/
XmlNamespaceManager oNamespaceManager = new XmlNamespaceManager(retNode.OwnerDocument.NameTable);
oNamespaceManager.AddNamespace(
"rs", "urn:schemas-microsoft-com:rowset");
oNamespaceManager.AddNamespace(
"z", "#RowsetSchema");
//XmlNode oRes = retNode.SelectSingleNode("//z:row", oNamespaceManager);;
int count = retNode.SelectNodes("//z:row", oNamespaceManager).Count;
foreach (XmlNode node in retNode.SelectNodes("//z:row", oNamespaceManager))
{
//Create new row in datatable
DataRow dr = dtPail.NewRow();
foreach (XmlAttribute att in node.Attributes)
{
//Create column entries in that new row here
switch (att.Name)
{
case "ows_ID":
dr[
"ID"] = att.InnerText;
break;
case "ows_Identifier":
dr[
"Identifier"] = att.InnerText;
break;
case "ows_AssignedTo":
dr[
"Responsible"] = att.InnerText.Substring(0, att.InnerText.IndexOf(";"));
dr[
"Responsiblename"] = att.InnerText.Remove(0, att.InnerText.IndexOf(";") + 2);
break;
case "ows_Title":
dr[
"Item"] = att.InnerText;
break;
case "ows_DueDate":
dr[
"DueDate"] = Convert.ToDateTime(att.InnerText).ToShortDateString();
dr[
"DueDateWSS"] = Convert.ToDateTime(att.InnerText);
break;
case "ows_Mgt_x002e__x0020_Attention":
dr[
"MgmtAttention"] = att.InnerText;
break;
case "ows_Created":
dr[
"CreateDate"] = att.InnerText;
break;
case "ows_Action":
dr[
"Action"] = att.InnerText;
break;
case "ows_Status":
dr[
"Discipline"] = att.InnerText;
break;
case "ows_Original_x0020_Due_x0020_Date":
dr[
"OriginalDueDate"] = att.InnerText;
break;
default:
break;
}
dr[
"WPROJ_STS_SUBWEB_NAME"] = dtListInfo.Rows[0][4].ToString();
//Response.Write(att.Name + ": " + att.InnerText);
//Response.Write("<br>");
}
dtPail.Rows.Add(dr);
//Response.Write("<br><br>");
}
}
catch (System.Web.Services.Protocols.SoapException ex)
{
//Response.Write(ex.Detail.InnerText);
DataRow dr = dtPail.NewRow();
dr[
"ID"] = "ERROR SOAPEXCEPTION";
dr[
"Action"] = ex.Detail.InnerText;
dtPail.Rows.Add(dr);
}