Try our conversational search powered by Generative AI!

ODP setup and EpiServer.OpenIDConnect on .NET Framework

Vote:
 

Hello,

I am attempting to install and configure ODP on our CMS 11 and Commerce 13 site. Since our site is on .NET Framework 4.7.1, the only compatible version of EPiServer.ServiceApi and EpiServer.ServiceApi.Commerce is 5.6.1. This also means there is no compatible version, past or present, of EpiServer.OpenIDConnect is referenced in all the documentation located here:

https://docs.developers.optimizely.com/customized-commerce/v1.3.0-service-api-developer-guide/docs/installation-and-configuration

I am not finding the resources or documentation I need for the versions of what we have. All the documentation references ServiceApi 6+ and 7+. Can anyone help with this?

#320622
Apr 17, 2024 14:09
Vote:
 

Hi Mike

I could not find much details of Service API for Commerce 13 in our new doc, I've managed to find one from our old doc system, and I hope this helps.

https://world.optimizely.com/documentation/developer-guides/archive/service-api/installation-and-configuration/5/

#320670
Apr 18, 2024 5:23
Vote:
 

The beginning of the documentation references using .NET Framework 4.6+, which is a good start. But when we get to the Owin setup, which is required, all those docs only show a Startup.cs configuration and reference .NET core. Obviously .NET Framework doesn't have a Startup.cs, so not sure how to complete that section.

#320675
Apr 18, 2024 13:19
Vote:
 

Hi Mike

Startup.cs has already existed in .NET Framework if you're familiar with "Owin" (see attached link below) . The Service API documentation I shared above has correct information that you need to set up for  Commerce 13. 

OWIN Startup Class Detection | Microsoft Learn

#320724
Apr 19, 2024 3:25
Vote:
 

Hi Vincent,

I appreciate your help on this. You are correct, I wasn't aware of an Owin startup class. I followed that guide, have all the necessary things installed and configured to the best of that and any documentation I can find. I'm not getting the same error as before, but still having issues just getting the site running. Haven't found anything helpful on this issue, though I've tried several things that are commented out

Error I'm getting now:


Stack Tr

Stack Trace:


[NullReferenceException: Object reference not set to an instance of an object.]
   EPiServer.ServiceApi.<>c.<Initialize>b__2_0(HttpConfiguration config) +312
   System.Web.Http.GlobalConfiguration.Configure(Action`1 configurationCallback) +125
   EPiServer.ServiceApi.IntegrationInitialization.Initialize(InitializationEngine context) +262
   EPiServer.Framework.Initialization.Internal.<>c__DisplayClass2_0.<Initialize>b__0() +56
   EPiServer.Framework.Initialization.Internal.ModuleNode.Execute(Action a, String key) +80
   EPiServer.Framework.Initialization.Internal.ModuleNode.Initialize(InitializationEngine context) +141
   EPiServer.Framework.Initialization.InitializationEngine.InitializeModules() +254

[InitializationException: Initialize action failed for Initialize on class EPiServer.ServiceApi.IntegrationInitialization, EPiServer.ServiceApi, Version=5.6.1.0, Culture=neutral, PublicKeyToken=8fe83dea738b45b7]
   EPiServer.Framework.Initialization.InitializationEngine.InitializeModules() +645
   EPiServer.Framework.Initialization.InitializationEngine.ExecuteTransition(Boolean continueTransitions) +262
   EPiServer.Framework.Initialization.InitializationEngine.Initialize() +70
   EPiServer.Framework.Initialization.<>c.<FrameworkInitialization>b__7_0(InitializationEngine e) +36
   EPiServer.Framework.Initialization.InitializationModule.EngineExecute(HostType hostType, Action`1 engineAction) +851
   EPiServer.Framework.Initialization.InitializationModule.FrameworkInitialization(HostType hostType) +216
   EPiServer.Global..ctor() +65
   CMS.Ellsworth.EPiServerApplication..ctor() +42
   ASP.global_asax..ctor() in c:\Users\agunn\AppData\Local\Temp\Temporary ASP.NET Files\root\0ca93a91\5fdf9290\App_global.asax.0.cs:0

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
   System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0
   System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +122
   System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +239
   System.Activator.CreateInstance(Type type, Boolean nonPublic) +85
   System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, StackCrawlMark& stackMark) +1173
   System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) +130
   System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture) +21
   System.Web.HttpRuntime.CreateNonPublicInstance(Type type, Object[] args) +81
   System.Web.HttpRuntime.CreateNonPublicInstance(Type type) +52
   System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +131
   System.Web.HttpApplicationFactory.GetPipelineApplicationInstance(IntPtr appContext, HttpContext context) +102
   System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +265

[HttpException (0x80004005): Exception has been thrown by the target of an invocation.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +752
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +144
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +246
using System;
using System.IO;
using EPiServer.ServiceApi.Owin;
using EPiServer.ServiceLocation;
using Microsoft.Owin;
using Owin;
using StructureMap;

[assembly: OwinStartup(typeof(CMS.Ellsworth.Startup))]

namespace CMS.Ellsworth
{
    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            var container = new Container();
            container.Configure(config =>
            {
                config.For<IAppBuilder>().Use(app); // Make sure IAppBuilder is registered
                // Add other necessary services
            });

            ServiceLocator.SetLocator(new StructureMapServiceLocator(container));

            // ServiceLocator.SetLocator(
            //     new StructureMapServiceLocator(new Container(x => x.For<IAppBuilder>().Use(app))));
            //
            //

            app.UseServiceApiMembershipTokenAuthorization();
            app.Run(context =>
            {
                string t = DateTime.Now.Millisecond.ToString();
                Console.WriteLine("Production OWIN App");
                return context.Response.WriteAsync(t + " Production OWIN App");
            });

            app.Use((context, next) =>
            {
                TextWriter output = context.Get<TextWriter>("host.TraceOutput");
                return next().ContinueWith(result =>
                {
                    output.WriteLine("Scheme {0} : Method {1} : Path {2} : MS {3}",
                        context.Request.Scheme, context.Request.Method, context.Request.Path, DateTime.Now.TimeOfDay);
                });
            });
        }
    }
}
using System;
using System.IO;
using EPiServer.Framework;
using EPiServer.Framework.Initialization;
using EPiServer.ServiceApi.Owin;
using EPiServer.ServiceLocation;
using Owin;
using StructureMap;

namespace CMS.Ellsworth.Infrastructure
{
    [InitializableModule]
    [ModuleDependency(typeof(EPiServer.Web.InitializationModule))]
    public class OwinInitialization : IInitializableModule
    {
        public void Initialize(InitializationEngine context)
        {

            // context.Initialize();
            // app.UseServiceApiMembershipTokenAuthorization();
            // app.Run(ctx =>
            // {
            //     string t = DateTime.Now.Millisecond.ToString();
            //     Console.WriteLine("Production OWIN App");
            //     return ctx.Response.WriteAsync(t + " Production OWIN App");
            // });
            //
            // app.Use((ctx, next) =>
            // {
            //     TextWriter output = ctx.Get<TextWriter>("host.TraceOutput");
            //     return next().ContinueWith(result =>
            //     {
            //         output.WriteLine("Scheme {0} : Method {1} : Path {2} : MS {3}",
            //             ctx.Request.Scheme, ctx.Request.Method, ctx.Request.Path, getTime());
            //     });
            // });
            //
            // app.Run(async ctx => { await ctx.Response.WriteAsync(getTime() + " My First OWIN App"); });
        }

        public void Uninitialize(InitializationEngine context)
        {
            //Add uninitialization logic
        }
    }
}

<add key="owin:appStartup" value="CMS.Ellsworth.Startup, CMS.Ellsworth" />
        <add key="owin:AutomaticAppStartup" value="false" />
#320733
Apr 19, 2024 16:55
Vote:
 

Hi Mike

Just let you know, Opti doc team has updated the Service API doc for previous version Install version 5 (optimizely.com) . Thanks for the feedback. 

Regarding to above error, I don't know the intent. However, the following code seems incorrect. In order to access services in startup, you can just use ServiceLocator.Current.GetInstance<xxxx>

 var container = new Container();
 container. Configure(config =>
 {
       config.For<IAppBuilder>().Use(app); // Make sure IAppBuilder is registered
        // Add other necessary services
 });

ServiceLocator.SetLocator(new StructureMapServiceLocator(container));
#320858
Apr 22, 2024 5:43
Vote:
 

Hi Vincent,

Thank you for your help during this. I followed the directions on that link but still reach the same error I got before. Initially I got an error about Owin.Security packages needing to be version 3.0.0, which fixed that error. But I get the failed initialization error and a NullPointer after that. It doesn't say anything about Initialization or a module in the docs, so I'm confused as to what I'm missing to initialize it.

EPiServer.Framework.Initialization.InitializationException: Initialize action failed for Initialize on class EPiServer.ServiceApi.IntegrationInitialization, EPiServer.ServiceApi, Version=5.6.1.0, Culture=neutral, PublicKeyToken=8fe83dea738b45b7 ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at EPiServer.ServiceApi.IntegrationInitialization.<>c.<Initialize>b__2_0(HttpConfiguration config)
   at System.Web.Http.GlobalConfiguration.Configure(Action`1 configurationCallback)
   at EPiServer.ServiceApi.IntegrationInitialization.Initialize(InitializationEngine context)
   at EPiServer.Framework.Initialization.Internal.ModuleNode.<>c__DisplayClass2_0.<Initialize>b__0()
   at EPiServer.Framework.Initialization.Internal.ModuleNode.Execute(Action a, String key)
   at EPiServer.Framework.Initialization.Internal.ModuleNode.Initialize(InitializationEngine context)
   at EPiServer.Framework.Initialization.InitializationEngine.InitializeModules()
[NullReferenceException: Object reference not set to an instance of an object.]
   EPiServer.ServiceApi.<>c.<Initialize>b__2_0(HttpConfiguration config) +312
   System.Web.Http.GlobalConfiguration.Configure(Action`1 configurationCallback) +125
   EPiServer.ServiceApi.IntegrationInitialization.Initialize(InitializationEngine context) +262
   EPiServer.Framework.Initialization.Internal.<>c__DisplayClass2_0.<Initialize>b__0() +56
   EPiServer.Framework.Initialization.Internal.ModuleNode.Execute(Action a, String key) +80
   EPiServer.Framework.Initialization.Internal.ModuleNode.Initialize(InitializationEngine co
using EPiServer.ServiceApi.Owin;
using EPiServer.ServiceLocation;
using Microsoft.Owin;
using Owin;
using StructureMap;

[assembly: OwinStartup(typeof(CMS.Ellsworth.Startup))]

namespace CMS.Ellsworth
{
    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            // Enable bearer token authentication using Membership for Service Api
            app.UseServiceApiMembershipTokenAuthorization();

            var container = new Container();
            container.Configure(config =>
            {
                config.For<IAppBuilder>().Use(app); // Make sure IAppBuilder is registered
                // Add other necessary services
            });

            ServiceLocator.SetLocator(new StructureMapServiceLocator(container));
        }
    }
}
#321131
Apr 27, 2024 20:21
Vote:
 

I can confirm that the Initialization error happens regardless whether the Owin Startup class is there or not, as it never hits any breakpoint in the owin Startup class. The documentation doesn't say anything about an Initialization module needing to be created, but that is what it's looking for.

#321167
Apr 28, 2024 18:01
Vote:
 

Hi Mike

The initialization modudle error above is from Service API itself, it could indicates something was not configured properly in the solution which caused the Initialization moudle fail to initialize the other stuffs. 

You Startup class doesn't look identical to the dev doc page.  I don't know the reason for the following code in your startup, it would potentially cause many issues if you try to reset container instance. can you remove them and give a try?

 var container = new Container();
 container. Configure(config =>
 {
        config.For<IAppBuilder>().Use(app); 
       // Make sure IAppBuilder is registered
 });

  ServiceLocator.SetLocator(new StructureMapServiceLocator(container));
#321204
Edited, Apr 29, 2024 3:09
Vote:
 

This is what my startup class looks like, same exact error message

using CMS.Ellsworth;
using EPiServer.ServiceApi.Owin;
using Microsoft.Owin;
using Owin;

[assembly: OwinStartup(typeof(Startup))]

namespace CMS.Ellsworth
{
    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            app.UseServiceApiMembershipTokenAuthorization();
        }
    }
}
#321222
Apr 29, 2024 13:36
Vote:
 

Hi Mike

Which project did you install the Service Api package? I used to have a few issues while installing into the Commerce Manager project.

#321267
Apr 30, 2024 0:48
Vote:
 

Hi Mike

Is your application using Membership or AspNetIdentity? The configuration will be different in Startup. 

I just install EPiServer.ServiceApi.Commerce 5.6.1 on my favourite optimizely demo ecommerce site - Quicksilver and it worked like a charm (see screenshow attached).  Note: Quicksilver is using AspNetIdentity.

#321269
Apr 30, 2024 2:31
Vote:
 

I did install in our main project that our codebase is in, and not in Commerce Manager. I believe we are using Membership (screenshot below), and I did run the update-epidatabase and the tblUserPermissions has given the db admin account all permissions. 

I install the packages, version 5.6.1 and create the Startup class for Membership but upon setting a breakpoint in the startup class, it never hits it. That initialization error happens regardless of configuration or things I follow in that demo.

I have also tried every past version of ServiceApi package to see if those worked, but none did.

<membership defaultProvider="CMSMembershipProvider" userIsOnlineTimeWindow="10" hashAlgorithmType="HMACSHA512">
      <providers>
        <clear />
        <add name="MultiplexingMembershipProvider" type="EPiServer.Security.MultiplexingMembershipProvider, EPiServer.Framework.AspNet" provider1="SqlServerMembershipProvider" provider2="WindowsMembershipProvider" />
        <add name="WindowsMembershipProvider" type="EPiServer.Security.WindowsMembershipProvider, EPiServer.Cms.AspNet" deletePrefix="BUILTIN\" searchByEmail="true" />
        <add name="SqlServerMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="EPiServerDB" requiresQuestionAndAnswer="false" applicationName="EPiServerSample" requiresUniqueEmail="true" passwordFormat="Hashed" maxInvalidPasswordAttempts="10" minRequiredPasswordLength="7" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" passwordStrengthRegularExpression="" />
        <!-- ECF Start -->
        <add connectionStringName="EcfSqlConnection" applicationName="EPiServer_CommerceManager_Ellsworth" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="true" passwordFormat="Hashed" passwordStrengthRegularExpression="" minRequiredPasswordLength="4" minRequiredNonalphanumericCharacters="0" name="CMSMembershipProvider" type="Mediachase.Commerce.Customers.Profile.Providers.CustomerSqlMembershipProvider, Mediachase.Commerce" />
        <!-- ECF End -->
      </providers>
    </membership>
#321285
Apr 30, 2024 14:27
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.