Print Page | Close Window

Implementing ServiceProxyEvents throws "Cannot find ObjectServer or default ServiceKey"

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=3835
Printed Date: 13-May-2026 at 12:56am


Topic: Implementing ServiceProxyEvents throws "Cannot find ObjectServer or default ServiceKey"
Posted By: afrizal.chen
Subject: Implementing ServiceProxyEvents throws "Cannot find ObjectServer or default ServiceKey"
Date Posted: 04-Dec-2012 at 11:36pm
I'm having a 3-tier configuration where i have winform-client that connects to BOS hosted in IIS.
It works fine with my current app.config (client) and web.config(BOS).

Now I have requirement to allow my winform-client to change the BOS address. Thus I'm implementing IdeaBlade.EntityModel.ServiceProxyEvents based on  http://drc.ideablade.com/devforce-2012/bin/view/Documentation/code-sample-custom-client-configuration - http://drc.ideablade.com/devforce-2012/bin/view/Documentation/code-sample-custom-client-configuration .
And now the winfom-client always throws "System.InvalidOperationException: Cannot find ObjectServer or default ServiceKey" when I create a new instance of a DomainModelEntityManager.

Did I miss anything in the implementation? Is there any part of the app.config that I need to modify?
I put a breakpoint at the constructor of my derived class of ServiceProxyEvents, i doest break there, but the two overriden method are never called.

here's the stacktrace:
IdeaBlade DevForce EntityManager error 
---> IdeaBlade.EntityModel.EntityServerException: Cannot find ObjectServer or default ServiceKey 
---> System.InvalidOperationException: Cannot find ObjectServer or default ServiceKey 
at IdeaBlade.Core.Configuration.ObjectServerElement.GetDefaultServiceKey() 
at IdeaBlade.Core.Configuration.ObjectServerElement.GetServiceKey(String name, Boolean throwIfNotFound) 
at IdeaBlade.EntityModel.DefaultClientProxy`1.GetServiceAddress() 
at IdeaBlade.EntityModel.WcfProxy`1.CreateProxyCore() 
at IdeaBlade.EntityModel.WcfProxy`1..ctor(String serviceName, String serviceKey, Boolean delayedCreation) 
at IdeaBlade.EntityModel.WcfProxyFactory.GetProxy[TContract](String serviceName, String serviceKey, String& address) 
at IdeaBlade.EntityModel.RemoteEntityServiceProxyBase`1.Initialize() 
at IdeaBlade.EntityModel.RemoteEntityServerProxyBase.Connect(ConnectAction action) 
at IdeaBlade.EntityModel.EntityManager.Connect() 
--- End of inner exception stack trace --- 
at IdeaBlade.EntityModel.EntityManager.HandleEntityServerException(Exception ex, Boolean tryToHandle, PersistenceOperation operation, Boolean throwOnError) 
at IdeaBlade.EntityModel.EntityManager.Connect() 
at IdeaBlade.EntityModel.EntityManager..ctor(EntityManagerContext context) 
at DomainModel.DomainModelEntityManager..ctor(Boolean shouldConnect, String dataSourceExtension, EntityServiceOption entityServiceOption, String compositionContextName)



Replies:
Posted By: afrizal.chen
Date Posted: 05-Dec-2012 at 1:41am
I've found the cause of the problem. There're duplicate implementation of ServiceProxyEvents.
Too bad the exception thrown is quite misleading. Thanks.


Posted By: kimj
Date Posted: 05-Dec-2012 at 8:38am
Glad you solved the problem, Afrizal.
 
You can change the service address in several ways:  in the app.config with either the ObjectServer or ServiceKey information, or in code by programmatically setting the corresponding IdeaBladeConfig.Instance information.  Implementing a custom ServiceProxyEvents will allow you to change the address too, but it's not as straightforward as the other means.


Posted By: afrizal.chen
Date Posted: 17-Dec-2012 at 1:56am
Hi Kim,
Currently I have a windows login form that allows my user to switch BOS-endpoint-address and Proxy-Address. I'm setting all this via ServiceProxyEvents. This works well.
Except in a scenario where user inputs a wrong endpoint-address at first, afterwards he changes the endpoint and try to login for the second time, it will still fail, because both overriden method of ServiceProxyEvents are not called anymore.
Is there a way to force the "OnEndpointCreated" and "OnFactoryCreated" to be called more than once? Please advise.


Posted By: afrizal.chen
Date Posted: 17-Dec-2012 at 4:52am
I found a workaround that I think it might worth to share.

I cache the "System.ServiceModel.ChannelFactory" into a static variable when OnFactoryCreated() called in the user's first login attempt.
Before the user login for the second time, I call System.ServiceModel.ChannelFactory.Close(), this will force the OnEndpointCreated() to be called again when instantiating EntityManager.


Posted By: kimj
Date Posted: 17-Dec-2012 at 11:46am
I'm a bit surprised that this works, but if it does that's a clever workaround.
 
We generally recommend that you create the EntityManager with a different service key, composition context or data source key to force a new URI to be used from the client.



Print Page | Close Window