I am calling the SQL Server Reporting Services Webservice from inside an asp.net application. I need to fire off all the subscriptions for a given report. But I don't want the user to have to wait around for it to all happen, so I want to have all the webservice calls inside a separate thread, and return to the user straight away.
I am using code that looks something like this:
public static void FireAllAsync(string ReportPath)
{
Hashtable paramValues = new Hashtable();
ThreadPool.QueueUserWorkItem(new WaitCallback(FireAll), ReportPath);
}
public static void FireAll(object ReportPath)
{
ReportingService rs = new ReportingService();
rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
Subscription[] SubList = rs.ListSubscriptions((string)ReportPath, null);
foreach (Subscription CurSub in SubList) {
rs.FireEvent(CurSub.EventType, CurSub.SubscriptionID);
}
}
Calling FireAll
works fine, but trying to call FireAllAsync
to use the Thread fails with a 401 error. I believe the problem with the credentials not getting passed through properly. ie this line of code here:
rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
I do not have a good understanding of how the credentials cache works, so I can't figure out why it doesn't like being in a separate thread.
I have tried grabbing the credentials in the outer function, and passing them through as an argument, but the same error occurs.
Does anyone have any ideas what may be happening?