Skip to main content
Planview Customer Success Center

WSE call fails with error

Login example in the documentation works, however other API calls such as GetContacts or GetById fails. Sample code used is below:

// Documentation P595/596
var proxyLogin = new CPLogin.WSLogin();
// Token Generation
var loginToken = new UsernameToken("cpadmin", "cpadmin", PasswordOption.SendHashed);
loginToken.Id = "LOGIN";
// Add token to the proxy class
proxyLogin.RequestSoapContext.Security.Tokens.Add(loginToken);
proxyLogin.RequestSoapContext.Security.Elements.Add(new MessageSignature(loginToken));
// Invoke the SOAP request. The Login is set there...
CPLogin.WSUser loginUser = proxyLogin.Login("cpadmin"); // Returns the WSUser object for CPADMIN => Works
// Documentation p598
var mProxy = new CPProject.Project();
// Generate the Token
var textToken = new UsernameToken("cpadmin", "cpadmin", PasswordOption.SendPlainText);
// Add this token to the proxy class
mProxy.RequestSoapContext.Security.Tokens.Add(textToken);
var oRet = mProxy.GetById("{...}");


Error/warning messages:
13:56:31 Level5: Warning for error code:-2003 Login user password is not provided by AccessToken.
13:56:31 Level2: Error: Number= -2001 Message= Login token is not valid, please login. Can not find login user ID.
13:56:31 Level1: Log for this source is end.


Reason:
The error message in the ws log file shows that the login token is not valid, due to the incorrect usage of UsernameToken() method.



Resolution:
Before accessing any of the other Changepoint Web Services API methods, custom application must first login to the Web Services API interface and generate a security token, which will be used for accessing other WS API methods. The correct usage of the UsernameToken() method is below:

CPLogin.WSUser loginUser = proxyLogin.Login("cpadmin");
var mProxy = new CPProject.Project();
var textToken = new UsernameToken(loginUser.value.UserId, loginUser.value.AccessToken, PasswordOption.SendPlainText);
mProxy.RequestSoapContext.Security.Tokens.Add(textToken);
var oRet = mProxy.GetById("{...}");