I am trying to call PSI functions in Project Server from web part but user credentials are not passed to PSI services
exception is:
1. anonymus access is enabled and web application uses Claims based authentication
2. My code
private SvcProject.ProjectClient SetProjectClientEndpoint()
{
const int MAXSIZE = 500000000;
const string ROUTER_SERVICE = "http://test01/pwa/_vti_bin/PSI/ProjectServer.svc";
BasicHttpBinding binding = null;
binding.Name = "basicHttpConf";
binding.AllowCookies = true;
binding.MessageEncoding = WSMessageEncoding.Text;
binding.OpenTimeout = TimeSpan.FromHours(1);
binding.ReceiveTimeout = TimeSpan.FromHours(1);
binding.SendTimeout = TimeSpan.FromHours(1);
// If the TransferMode is buffered, the MaxBufferSize and
// MaxReceived MessageSize must be the same value.
binding.TransferMode = TransferMode.Buffered;
binding.MaxBufferSize = MAXSIZE;
binding.MaxReceivedMessageSize = MAXSIZE;
binding.ReaderQuotas.MaxArrayLength = MAXSIZE;
binding.ReaderQuotas.MaxNameTableCharCount = MAXSIZE;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm;
binding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.Ntlm;
binding.Security.Transport.Realm = "";
// The endpoint address is the ProjectServer.svc router for all public PSI calls.
EndpointAddress address = new EndpointAddress(ROUTER_SERVICE);
SvcProject.ProjectClient projectClient = new SvcProject.ProjectClient(binding, address);
projectClient.ChannelFactory.Credentials.Windows.AllowedImpersonationLevel
= TokenImpersonationLevel.Impersonation;
projectClient.ChannelFactory.Credentials.Windows.AllowNtlm = true;
return projectClient;
}
3. Function call:
SvcProject.ProjectClient projectClient = SetProjectClientEndpoint();
projectClient.ReadProject(this.ProjectGuid, SvcProject.DataStoreEnum.WorkingStore);
4. Exception happens on ReadProject function:
"The HTTP request is unauthorized with client authentication scheme 'Negotiate'. The authentication header received from the server was 'Negotiate,NTLM'"
If I change my code and hardcode user like this:
projectClient.ChannelFactory.Credentials.Windows.ClientCredential.UserName = "myuser";
projectClient.ChannelFactory.Credentials.Windows.ClientCredential.Password = "mypass";
projectClient.ChannelFactory.Credentials.Windows.ClientCredential.Domain = "mydomain";
I don't get the error, but I don't want that because some other part of my code then don't work, I need to call PSI with current user. How?