The essential of impersonation with Project Server 2007 is the following:
Instead of issuing a web service call using your cached credentials to a
service provider like
http://projectserver/instance/_vti_bin/psi/resource.asmx, you send the
request directly to the Shared Service Provider (SSP), that hosts the
project server.
"/instance/" is replaced with ":56737/SSP", like
http://projectserver:56737/ShareServices1/_vti_bin/psi/resource.asmx.
This call must use the credentials of the Application Pool Identity of the
Application Pool that contains the SSP.
The webrequest you send to the SSP contains two additional headers:
· "PjAuth" with the serialized contextinfo of the user to be
impersonated (isWindowsUser, userAccount, userGuid, trackingGuid, siteId,
lcid)
· "ForwardedFrom" with the relative URL like
"/_vti_bin/psi/resource.asmx"
Your code must override the default webrequest method for SSP related web
service calls
protected override WebRequest GetWebRequest(Uri uri)
{
WebRequest webRequest = base.GetWebRequest(uri);
if (contextString != String.Empty)
{
webRequest.UseDefaultCredentials = true;
bool isImpersonating =
(System.Security.Principal.WindowsIdentity.GetCurrent(true)
!= null);
webRequest.Credentials = new
NetworkCredential("administrator", "2007", "");
webRequest.Headers.Add("PjAuth", contextString);
webRequest.Headers.Add("ForwardedFrom",
"/_vti_bin/psi/resource.asmx");
webRequest.PreAuthenticate = true;
}
return webRequest;
}
You cannot use your default credentials:
Instead of
resProxyBySSP = new ResourceDerived();
resProxyBySSP.Url = PSI_RESOURCE_SSP;
resProxyBySSP.Credentials = CredentialCache.DefaultCredentials;
you need something like this
ICredentials SSPcred = new
NetworkCredential("administrator","2007","");
resProxyBySSP = new ResourceDerived();
resProxyBySSP.Url = PSI_RESOURCE_SSP;
resProxyBySSP.Credentials = SSPcred;
Hope this helps,
Berend