How to return a DataSet from an Epicor Function?

You can use the EpiRest Library you just have to deploy it with the client.

using EpicorRestAPI;
SetupEpicorRest("APIKey")
var response = EpicorRest.EfxPost("CustomerPortal", "GenerateNewPassword", new { });
GeneratePwdResponse pwdResp = Newtonsoft.Json.JsonConvert.DeserializeObject<DataSet>(response.ResponseBody);
if(!response.IsErrorResponse)
{
// do something with response.Properties
}
//......


public bool SetupEpicorRest(string apiKey)
    {
        try
        {
            string appUri =AppSettingsHandler.GetValue(AppSettingsSections.Application, "AppServerURL", null);
            var uri = new Uri(appUri);
            EpicorRestAPI.EpicorRest.AppPoolHost=uri.Host;
            EpicorRest.AppPoolInstance = uri.LocalPath.Replace("/","");
            EpicorRest.APIKey = apiKey;
            var session = oTrans.Session as Ice.Core.Session;
			EpicorRest.Company = session.CompanyID;

			Assembly sm = Assembly.LoadFrom("Epicor.ServiceModel.dll");  // Kinetic Uplift
			object authClass = sm.CreateInstance("Epicor.ServiceModel.Wcf.Security.AuthenticationWcf");  // Kinetic Uplift
			Type smType = authClass.GetType();  // Kinetic Uplift
			BindingFlags bf = BindingFlags.Instance|BindingFlags.NonPublic|BindingFlags.Public;  // Kinetic Uplift
			MethodInfo mi = smType.GetMethod("IsWindows", bf);  // Kinetic Uplift
			object[] invParams = new object[1]{AppSettingsHandler.AuthenticationMode};  // Kinetic Uplift
			bool isWindows = (bool)mi.Invoke(authClass,invParams);  // Kinetic Uplift
			

            var accessTokenFunc = typeof(Ice.Core.Session).GetProperty("GetAccessTokenFunc", BindingFlags.Instance|BindingFlags.NonPublic|BindingFlags.Public).GetValue(session) as Func<bool,string>;
            if(accessTokenFunc !=null)
            {
                EpicorRest.BearerToken = accessTokenFunc(false);
            }
			else if(isWindows) // Kinetic Uplift
            {
                EpicorRest.UserName = Environment.UserName;
                EpicorRest.Password = "";
            }
            else
            {
                object clientCreds = typeof(Ice.Core.Session).GetProperty("ClientCredentials", BindingFlags.Instance|BindingFlags.NonPublic|BindingFlags.Public).GetValue(session);
                if(clientCreds!=null)
                {
                    object clientCredsUname = clientCreds.GetType().GetProperty("UserName").GetValue(clientCreds);
                    EpicorRest.UserName =clientCredsUname.GetType().GetProperty("UserName").GetValue(clientCredsUname) as String;
                    EpicorRest.Password =clientCredsUname.GetType().GetProperty("Password").GetValue(clientCredsUname) as String;
                }
            }
            return true;
        }
        catch(Exception ex)
        {
            return false;
        }
    }
1 Like