I am trying to write a console app that connects to an instance of
Reporting Services' ReportServer service. I'm using custom
authentication (based on FormsAuthentication) rather than Windows
authentication. The usual incantation for connecting to the service is
via code like this:
ReportingService reportingService = new ReportingService();
reportingService.Credentials = CredentialCache.DefaultCredentials;
This will not work because my default credentials will be my Windows
identity, and I need to instead authenticate as a user in our database's
list of users. I expected to be able to do this using NetworkCredential:
reportingService.Credentials = new NetworkCredential(...);
But every time instead I get back is the 302 redirect response
(redirecting to the LogInForm.aspx page). The response isn't even in
the form of a Soap error response.
I have the same problem with the plain-HTTP approach; I have even tried
the following longer variation on the above:
Uri uri = new Uri(servUri, "?%2F&rs:Command=ListChildren");
HttpWebRequest req = (HttpWebRequest) WebRequest.Create(uri);
NetworkCredential cred = new NetworkCredential(...);
CredentialCache cache = new CredentialCache();
cache.Add(servUri, "Basic", cred);
cache.Add(servUri, "NTLM", cred);
cache.Add(servUri, "Digest", cred);
cache.Add(servUri, "Kerberos", cred);
req.Credentials = cache;
I still get the redirect to the log-in page. In this case I think I can
work around this little difficulty, by doing two requests, one to the
log-in page to collect a cookie, and the second to the page I want,
using that cookie. But even if that works, it will not help with the
Soap version (unless I decide I want to do all the Soap requests 'by
hand' via HttpWebRequest).
I have a feeling the problem is that the Credentials thingummy is only
good for kosher HTTP authentication, and that since Forms Authentication
uses cookies, it does not count. Maybe I could switch to using Digest
authentication?