New Posts New Posts RSS Feed: InvalidOperation Expection at startup
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

InvalidOperation Expection at startup

 Post Reply Post Reply
Author
morahman View Drop Down
Newbie
Newbie
Avatar

Joined: 26-Feb-2012
Location: India
Posts: 3
Post Options Post Options   Quote morahman Quote  Post ReplyReply Direct Link To This Post Topic: InvalidOperation Expection at startup
    Posted: 12-Apr-2013 at 9:22am
I'm using DevForce 2012 with Visual Studio 2012 for a Silverlight 5 enterprise application.

I'm starting to get InvalidOperationException when trying to instantiat EntityManager for Authentication process

_registrationManager = new EntityManager.

The exception has a following message

"Could not find endpoint element with name 'EntityService' and contract 'IdeaBlade.EntityModel.IEntityServiceContract' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this name could be found in the client element."

The  web.config hasn't changed at all. It has remained same for long. This exception is suddenly showing up.

Any clues as to what might be possibly happening.

Thanks
-Obaid

Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 12-Apr-2013 at 10:13am
Do you have a ServiceReferences.ClientConfig file in your Silverlight project? If so, check that it's correct. For the record, you don't need the ClientConfig, but it's one option if you're overriding defaults. See http://drc.ideablade.com/devforce-2012/bin/view/Documentation/code-sample-custom-client-servicemodel for more information on using this file.

If everything looks good and was working until recently, surely something has changed.
Back to Top
morahman View Drop Down
Newbie
Newbie
Avatar

Joined: 26-Feb-2012
Location: India
Posts: 3
Post Options Post Options   Quote morahman Quote  Post ReplyReply Direct Link To This Post Posted: 14-Apr-2013 at 10:27pm
My ServicesReferences.ClientConfig has information of my internal WCF service

<configuration>
  <system.serviceModel>
   <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_ISynchronization"
                 maxBufferSize="2147483647"
                 maxReceivedMessageSize="2147483647">
          <security mode="None" />
        </binding>
      </basicHttpBinding>
      </bindings>
    <client>
      <endpoint address="http://localhost:9867/Services/Synchronization.svc"
                binding="basicHttpBinding"
                bindingConfiguration="BasicHttpBinding_ISynchronization"
                contract="SyncServiceReference.ISynchronization"
                name="BasicHttpBinding_ISynchronization" />
    </client>
  </system.serviceModel>
</configuration>

but when I add EntityService information 

<configuration>
  <system.serviceModel>
   <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_ISynchronization"
                 maxBufferSize="2147483647"
                 maxReceivedMessageSize="2147483647">
          <security mode="None" />
        </binding>
      </basicHttpBinding>
      </bindings>
    <client>
      <endpoint name="EntityService"
                address="http://localhost:8000/EntityService.svc"
                binding="customBinding"
                contract="IdeaBlade.EntityModel.IEntityServiceContract"/>
 
      <endpoint name="EntityServer"
                address="http://localhost:8000/EntityServer.svc"
                binding="customBinding"
                contract="IdeaBlade.EntityModel.IEntityServerContract"/>
      
      <endpoint address="http://localhost:9867/Services/Synchronization.svc"
                binding="basicHttpBinding"
                bindingConfiguration="BasicHttpBinding_ISynchronization"
                contract="SyncServiceReference.ISynchronization"
                name="BasicHttpBinding_ISynchronization" />
    </client>
  </system.serviceModel>
</configuration>
along with following custom code
public class ProxyEvents : IdeaBlade.EntityModel.ServiceProxyEvents
    {
 
        public override void OnEndpointCreated(System.ServiceModel.Description.ServiceEndpoint endpoint)
        {
            base.OnEndpointCreated(endpoint);
 
            // Sample adding Gzip compression programmatically.  
            // Use when using a ServiceReferences.ClientConfig where a gzip binding cannot be added declaratively (this is a 
            // Silverlight limitation since it does not support extensions via config).
 
            if (endpoint.Binding is CustomBinding)
            {
                var binding = endpoint.Binding as CustomBinding;
                var elements = binding.CreateBindingElements();
 
                // Swap out binary/text message encoding for gzip/binary
                var encoding = elements.Find<MessageEncodingBindingElement>();
                if (encoding != null)
                {
                    elements.Remove(encoding);
                }
 
                encoding = new GZipMessageEncodingBindingElement();
                elements.Insert(0, encoding);
                elements.Add(new HttpTransportBindingElement { MaxReceivedMessageSize = 2147483647, MaxBufferSize = 2147483647 });
                endpoint.Binding = new CustomBinding(elements);
            }
            else if (endpoint.Binding == null)
            {
                var customBinding = new CustomBinding();
                var elements = customBinding.CreateBindingElements();
                var encoding = new GZipMessageEncodingBindingElement();
                elements.Insert(0, encoding);
                elements.Add(new HttpTransportBindingElement { MaxReceivedMessageSize = 2147483647, MaxBufferSize = 2147483647 });
 
                endpoint.Binding = new CustomBinding(elements);
            }
        }
    }
things are starting to work as expected. But when I remove client information from ClientConfig, I get the said exception.

Any idea what is possibly happening
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 15-Apr-2013 at 11:11am
If you're keeping this ProxyEvents code when you remove the DevForce client endpoints from the ServiceReferences.ClientConfig, then that's causing the exception.   

Without .ClientConfig information DevForce performs its default initialization, so when your ProxyEvents code is called the CustomBinding is already set up with both the Gzip encoding and HttpTransport. Adding them again is the cause of the failure.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down