Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom endpoint behavior not working after upgrade to 5.0 #267

Closed
KumG opened this issue Feb 9, 2021 · 2 comments
Closed

Custom endpoint behavior not working after upgrade to 5.0 #267

KumG opened this issue Feb 9, 2021 · 2 comments

Comments

@KumG
Copy link

KumG commented Feb 9, 2021

Describe the bug
I don't know if this is a bug, but with a previous version of OpenRiaServices and Silverlight, I had a custom Endpoint Behavior for my DomainServices, adding a custom header.

Now, with my WPF application, it doesn't work anymore.

Any idea ?

To Reproduce

    public partial class MyDomainContext
     {
         partial void OnCreated()
         {
             if (DomainClient is WebDomainClient<IMyDomainServiceContract> domainClient)
             {
                 if (domainClient.ChannelFactory.Endpoint.Behaviors.All(b => b.GetType() != typeof(InjectCultureNameBehavior)))
                 {
                     domainClient.ChannelFactory.Endpoint.Behaviors.Add(InjectCultureNameBehavior);
                 }
             }
        }

        private static readonly InjectCultureNameBehavior InjectCultureNameBehavior = new InjectCultureNameBehavior();
     }
    internal class InjectCultureNameBehavior : WebHttpBehavior
    {
        public override void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
        {
            clientRuntime.MessageInspectors.Add(_inspector);
        }
    }
    internal class InjectCultureMessageInspector : IClientMessageInspector
    {
        public object BeforeSendRequest(ref Message request, IClientChannel channel)
        {
            var property = request.Properties[HttpRequestMessageProperty.Name] as HttpRequestMessageProperty;
            if (property != null && property.Method == "POST")
            {
                property.Headers["CultureName"] = Thread.CurrentThread.CurrentUICulture.Name;
            }

            return null;
        }

        public void AfterReceiveReply(ref Message reply, object correlationState)
        {
            
        }
    }

Server side:

        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {
            if (System.Web.HttpContext.Current.Request.Headers.AllKeys.Any(k => k == "CultureName"))
                Thread.CurrentThread.CurrentUICulture = new CultureInfo(System.Web.HttpContext.Current.Request.Headers["CultureName"]);
        }

Details

  • Nuget package and version : 5.0.0-preview0003
  • net471
@KumG KumG added the bug label Feb 9, 2021
@Daniel-Svensson
Copy link
Member

To add SCF behaviours to your channelfactory in v5 you need to implement a custom DomainClientFactory.
Derive from the factory you use now (WebDomainClientFacctory ?) and override a suitable extension method.

There is a sample of a fully custom endpoint over at https://github.com/OpenRIAServices/Samples/blob/1e6710833252db4a7d337bd859ae7904563a4cca/CustomEndpoint/CustomEndpoint.Client/BinaryDomainClientFactory.cs#L33 which should help you in the right direction.

The background to the change is that the endpoints are now cached for better performance so they are "locked" at a earlier stage than previously

@Daniel-Svensson Daniel-Svensson changed the title Custom endpoint behavior not working Custom endpoint behavior not working after upgrade to 5.0 Feb 15, 2021
@KumG
Copy link
Author

KumG commented Feb 16, 2021

Thank you, it is working fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants