DataPortal calls fail when Logged into Silverlight Application

DataPortal calls fail when Logged into Silverlight Application

Old forum URL: forums.lhotka.net/forums/t/9774.aspx


ksirmons posted on Tuesday, November 16, 2010

Howdy,

We are building a Silverlight 4 application and are using WCF for the dataportal.  It is configured to use SSL with Transport security on a basicHttpBinding endpoint.

After launching the application, the client contacts the server through the DP to pull a list of values to populate a drop down list.  The user selects an item and then provides their username / password to logon.

The credentials are passed through the DP again and validated against the database, passing back a CslaIdentity that is assigned to the CslaPrincipal.  

After this, the Csla.ApplicationContext.User is correct inside Silverlight.

If I then perform another DP fetch, the request fails.

Here is the e.ErrorInfo:

- e.Error {System.MissingMethodException: No parameterless constructor defined for this object.

   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)

   at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache)

   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache)

   at System.Activator.CreateInstance(Type type, Boolean nonPublic)

   at Csla.Serialization.Mobile.MobileFormatter.DeserializeAsDTO(List`1 deserialized)

   at Csla.Serialization.Mobile.MobileFormatter.Deserialize(List`1 data)

   at Csla.Serialization.Mobile.MobileFormatter.Deserialize(XmlReader reader)

   at Csla.Serialization.Mobile.MobileFormatter.Deserialize(Stream serializationStream)

   at Csla.Serialization.Mobile.MobileFormatter.Deserialize(Byte[] data)

   at Csla.Server.Hosts.Silverlight.WcfPortal.Fetch(CriteriaRequest request)

} System.Exception {Csla.DataPortalException}

- [Csla.DataPortalException] {System.MissingMethodException: No parameterless constructor defined for this object.

   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)

   at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache)

   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache)

   at System.Activator.CreateInstance(Type type, Boolean nonPublic)

   at Csla.Serialization.Mobile.MobileFormatter.DeserializeAsDTO(List`1 deserialized)

   at Csla.Serialization.Mobile.MobileFormatter.Deserialize(List`1 data)

   at Csla.Serialization.Mobile.MobileFormatter.Deserialize(XmlReader reader)

   at Csla.Serialization.Mobile.MobileFormatter.Deserialize(Stream serializationStream)

   at Csla.Serialization.Mobile.MobileFormatter.Deserialize(Byte[] data)

   at Csla.Server.Hosts.Silverlight.WcfPortal.Fetch(CriteriaRequest request)

} Csla.DataPortalException

- base {System.MissingMethodException: No parameterless constructor defined for this object.

   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)

   at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache)

   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache)

   at System.Activator.CreateInstance(Type type, Boolean nonPublic)

   at Csla.Serialization.Mobile.MobileFormatter.DeserializeAsDTO(List`1 deserialized)

   at Csla.Serialization.Mobile.MobileFormatter.Deserialize(List`1 data)

   at Csla.Serialization.Mobile.MobileFormatter.Deserialize(XmlReader reader)

   at Csla.Serialization.Mobile.MobileFormatter.Deserialize(Stream serializationStream)

   at Csla.Serialization.Mobile.MobileFormatter.Deserialize(Byte[] data)

   at Csla.Server.Hosts.Silverlight.WcfPortal.Fetch(CriteriaRequest request)

} System.Exception {Csla.DataPortalException}

+ Data {System.Collections.ListDictionaryInternal} System.Collections.IDictionary {System.Collections.ListDictionaryInternal}

+ InnerException null System.Exception

Message "No parameterless constructor defined for this object." string

StackTrace null string

+ Static members

+ Non-Public members

- ErrorInfo {Csla.WcfPortal.WcfErrorInfo} Csla.WcfPortal.WcfErrorInfo

ExceptionTypeName "System.MissingMethodException" string

InnerError null Csla.WcfPortal.WcfErrorInfo

Message "No parameterless constructor defined for this object." string

Source "mscorlib" string

StackTrace "   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)\r\n   at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache)\r\n   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache)\r\n   at System.Activator.CreateInstance(Type type, Boolean nonPublic)\r\n   at Csla.Serialization.Mobile.MobileFormatter.DeserializeAsDTO(List`1 deserialized)\r\n   at Csla.Serialization.Mobile.MobileFormatter.Deserialize(List`1 data)\r\n   at Csla.Serialization.Mobile.MobileFormatter.Deserialize(XmlReader reader)\r\n   at Csla.Serialization.Mobile.MobileFormatter.Deserialize(Stream serializationStream)\r\n   at Csla.Serialization.Mobile.MobileFormatter.Deserialize(Byte[] data)\r\n   at Csla.Server.Hosts.Silverlight.WcfPortal.Fetch(CriteriaRequest request)" string

TargetSiteName "CreateInstance" string

+ Non-Public members

+ Data {System.Collections.ListDictionaryInternal} System.Collections.IDictionary {System.Collections.ListDictionaryInternal}

+ InnerException null System.Exception

Message "No parameterless constructor defined for this object." string

StackTrace null string

+ Static members

+ Non-Public members

 

If I do not login to the Application and stick with Silverlight's default Csla.Security.UnauthenticatedPrincipal, all of the calls work correctly.

My web.config:

 <appSettings>
    <add key="CslaAuthentication" value="Csla" />
  </appSettings>
  <system.serviceModel>
    <protocolMapping>
      <add scheme="https" binding="basicHttpBinding" bindingConfiguration="https" />
    </protocolMapping>
    
    <bindings>
      <basicHttpBinding>
        <binding name="https">
          <security mode="Transport">
            <transport clientCredentialType="None" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
      multipleSiteBindingsEnabled="true" />
    <behaviors>
      <serviceBehaviors>
        <behavior>
            <serviceMetadata httpsGetEnabled="True"/>
            <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

My ServiceReferences.ClientConfig:

 <appSettings>
    <add key="CslaAuthentication" value="Csla" />
  </appSettings>
  <system.serviceModel>
    <client>
      <endpoint address="https://localhost:1406/WcfPortal.svc"
                binding="basicHttpBinding"
                bindingConfiguration="BasicHttpBinding_IWcfPortal"
                contract="WcfPortal.IWcfPortal"
                name="BasicHttpBinding_IWcfPortal"/>
       </client>
    
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IWcfPortal"
                 maxBufferSize="65536"
                 maxReceivedMessageSize="65536"
                 receiveTimeout="10"
                 sendTimeout="10">
          <security mode="Transport">
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
   
  </system.serviceModel>

 

I can see breakpoints are being hit in the Global.asax.cs class as the DataPortal requests are sent to the server, but I do not see the Csla.ApplicationContext.User being changed from System.Security.Principal.GenericPrincipal at either Application_BeginRequest or Application_AuthenticateRequest.

IIS 7 (Windows 7) is configured to require SSL, and the binding for the port is https.

Am I missing something in the security model that is causing the block of my dataportal requests?

 

Thank you,

Keith

 

 

RockfordLhotka replied on Tuesday, November 16, 2010

Keith Sirmons

- e.Error {System.MissingMethodException: No parameterless constructor defined for this object.

This is the key - you have some object flowing through the data portal that doesn't have a public default constructor. Possibilities include

  1. Your criteria object
  2. Your business object
  3. Your principal object
  4. Your identity object
  5. Any object you've put into ApplicationContext.ClientContext or .GlobalContext

Given that your initial request works, my bet is on the principal class.

ksirmons replied on Wednesday, November 17, 2010

Perfect.  

I checked the BOs several times for this requirement, just missed the Principal object.  I had used CSLA at the 2.0 version a few years ago and it was just habit to make all constructors private.

 

Thank you,

Keith

Copyright (c) Marimer LLC