Hi Sush
Below is a sample console application that tries to execute a SmartObject using the current user's credentials.
If the credentials aren't cached it will raise an AuthenticationException and will prompt for new credentials (in your case the SAP credentials)
hth
using System;
using System.Collections.Generic;
using System.Text;
namespace TestAuthentication
{
class Program
{
static void Main(stringc] args)
{
try
{
ExecuteListSmartObject("Account", "GetList");
}
catch (Exception ex)
{
Console.WriteLine("ERROR: {0}", ex.Message);
}
finally
{
Console.WriteLine("Press any key to continue ...");
Console.ReadKey();
}
}
static void ExecuteListSmartObject(string smartObjectName, string methodToExecute)
{
SourceCode.Hosting.Client.BaseAPI.SCConnectionStringBuilder scConnectionStringBuilder =
new SourceCode.Hosting.Client.BaseAPI.SCConnectionStringBuilder();
scConnectionStringBuilder.Host = "localhost";
scConnectionStringBuilder.Port = 5555;
scConnectionStringBuilder.IsPrimaryLogin = true;
scConnectionStringBuilder.Integrated = true;
SourceCode.SmartObjects.Client.SmartObjectClientServer clientServer =
new SourceCode.SmartObjects.Client.SmartObjectClientServer();
clientServer.CreateConnection();
clientServer.Connection.Open(scConnectionStringBuilder.ConnectionString);
SourceCode.SmartObjects.Client.SmartObject smartObject = clientServer.GetSmartObject(smartObjectName);
smartObject.MethodToExecute = methodToExecute;
bool tryAgain = true;
while (tryAgain)
{
tryAgain = false;
try
{
SourceCode.SmartObjects.Client.SmartObjectList listResult = clientServer.ExecuteList(smartObject);
Console.WriteLine("Successful");
tryAgain = false;
}
catch (SourceCode.Hosting.Exceptions.AuthenticationException authEx)
{
// User to supply Authentication details
if (AddProvideAuthentication(authEx, clientServer))
{
tryAgain = true;
}
}
}
}
static bool AddProvideAuthentication(SourceCode.Hosting.Exceptions.AuthenticationException authEx,
SourceCode.SmartObjects.Client.SmartObjectClientServer clientServer)
{
// Get UserName
Console.WriteLine(string.Format("Provide UserName for {0}", authEx.ProviderFriendlyName));
string userName = Console.ReadLine();
if (string.IsNullOrEmpty(userName))
{
return false;
}
// Get Password
Console.WriteLine(string.Format("Provide Password for {0}", authEx.ProviderFriendlyName));
string password = Console.ReadLine();
if (string.IsNullOrEmpty(password))
{
return false;
}
// Apply Authentication to current SmartObjectClientServer
SourceCode.Hosting.Client.BaseAPI.SCConnectionStringBuilder conn =
new SourceCode.Hosting.Client.BaseAPI.SCConnectionStringBuilder(clientServer.Connection.ToString());
conn.IsPrimaryLogin = false;
conn.Integrated = false;
conn.SecurityLabelName = authEx.ProviderFriendlyName;
conn.UserID = userName;
conn.Password = password;
conn.AuthData = authEx.ProviderFriendlyName;
clientServer.Connection.Authenticate(conn.ConnectionString);
return true;
}
}
}
Thanks Schalk for ur reply..
I will try this solution..
Hi Schalk,
I have the same problem, after creating your consol appication still give me the same error 'no credentials cached for this label'
i think the provided credentials (username|password) is the problem, but i am using this credentials when i connect to SAP Destination "by checking predefined credentials checkbox". i am confused :S:S how i can ensure that the credentials is correct