I have several SmartObjects that access SharePoint lists. The MOSS and K2 instances are on different servers and the access time for retrieving 50 records is around 30 seconds. The K2 server makes hundreds of web service calls to retrieve the data from the list, which is causing the very long access times. I was wondering if there is something that I'm missing in my code that would batch the calls to make the access time quicker. Below is the code that I'm using:
public static List<Entity.EmployeePto> GetListByYear(String year)
{
// Set the filter date values
DateTime dateStart = DateTime.Parse(String.Format("01/01/{0} 12:00:00 AM", year)).AddDays(-1);
DateTime dateEnd = DateTime.Parse(String.Format("01/01/{0} 11:59:59 PM", int.Parse(year) + 1));
// Create the List<> to return
List<Entity.EmployeePto> ptoList = new List<Entity.EmployeePto>();
SmartObjectClientServer server = new SmartObjectClientServer();
try
{
SCConnectionStringBuilder builder = new SCConnectionStringBuilder();
builder.Host = K2ServerName;
builder.Port = K2MGTPort;
builder.Integrated = true;
builder.IsPrimaryLogin = true;
server.CreateConnection();
server.Connection.Open(builder.ToString());
// Get SmartObject Definition
SmartObject employeePTO = server.GetSmartObject("PtoExemptData");
// Get the list method
SmartListMethod getList = employeePTO.ListMethodst"GetList"];
employeePTO.MethodToExecute = getList.Name;
// Set the date filters
GreaterThan dateGreater = new GreaterThan();
dateGreater.Left = new PropertyExpression("PtoDate", PropertyType.DateTime);
dateGreater.Right = new ValueExpression(dateStart, PropertyType.DateTime);
LessThan dateLessThan = new LessThan();
dateLessThan.Left = new PropertyExpression("PtoDate", PropertyType.DateTime);
dateLessThan.Right = new ValueExpression(dateEnd, PropertyType.DateTime);
And and1 = new And();
and1.Left = dateGreater;
and1.Right = dateLessThan;
// Apply the filter
getList.Filter = and1;
// Get the list
SmartObjectList listPTO = server.ExecuteList(employeePTO);
// Add properties to the List<>
foreach (SmartObject smartObject in listPTO.SmartObjectsList)
{
Entity.EmployeePto item = new Entity.EmployeePto();
foreach (SmartProperty var in smartObject.Properties)
{
switch (var.Name)
{
case "ID":
{
if (String.IsNullOrEmpty(var.Value) == false)
{
item.ID = var.Value;
}
break;
}
case "PtoDate":
{
if (String.IsNullOrEmpty(var.Value) == false)
{
item.PtoDate = DateTime.Parse(var.Value);
}
break;
}
case "PtoHours":
{
if (String.IsNullOrEmpty(var.Value) == false)
{
item.PtoHours = int.Parse(var.Value);
}
break;
}
case "PtoComment":
{
if (String.IsNullOrEmpty(var.Value) == false)
{
item.PtoComment = var.Value;
}
break;
}
case "ProcessID":
{
if (String.IsNullOrEmpty(var.Value) == false)
{
item.ProcessID = var.Value;
}
break;
}
}
}
// Add the item to the list
ptoList.Add(item);
}
// Sort the list by the employee name
ptoList.Sort(delegate(Entity.EmployeePto x, Entity.EmployeePto y) { return String.Compare(x.EmployeeName, y.EmployeeName); });
}
catch (SmartObjectException soe)
{
StringBuilder errorMessage = new StringBuilder();
foreach (SmartObjectExceptionData data in soe.BrokerData)
{
String message = data.Message;
String service = data.ServiceName;
String serviceGuid = data.ServiceGuid;
String severity = data.Severity.ToString();
String innerMessage = data.InnerExceptionMessage;
errorMessage.AppendLine("Service: " + service);
errorMessage.AppendLine("Service Guid: " + serviceGuid);
errorMessage.AppendLine("Severity: " + severity);
errorMessage.AppendLine("Error Message: " + message);
errorMessage.AppendLine("Inner Exception: " + innerMessage);
}
throw new Exception(errorMessage.ToString());
}
catch (Exception ex)
{
throw (ex);
}
finally
{
server.Connection.Close();
}
return ptoList;
}
Any help would be greatly appreciated.
Thanks!