WCF formatter errors when using WCF data portal.

WCF formatter errors when using WCF data portal.

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


HelioD posted on Friday, October 21, 2011

  1. I am using CSLA version 4.1.0.
  2.   When I run the test code with the data portal proxy set to 'local' in app.config the entiire code runs fine. However when using WCF portal hosted in IIS the following error message comes up when attempting to save my business object:

    The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://ws.lhotka.net/WcfDataPortal:UpdateResult. The InnerException message was 'Error in line 1 position 2626. 'Element' '_raiseListChangedEvents' from namespace 'http://schemas.datacontract.org/2004/07/Csla.Rules' is not expected. Expecting element 'AddedNew'.'.  Please see InnerException for more details.System.Runtime.Serialization.SerializationException: Error in line 1 position 2626. 'Element' '_raiseListChangedEvents' from namespace 'http://schemas.datacontract.org/2004/07/Csla.Rules' is not expected. Expecting element 'AddedNew'.
       at System.Runtime.Serialization.XmlObjectSerializerReadContext.ThrowRequiredMemberMissingException(XmlReaderDelegator xmlReader, Int32 memberIndex, Int32 requiredIndex, XmlDictionaryString[] memberNames)
       at System.Runtime.Serialization.XmlObjectSerializerReadContext.GetMemberIndexWithRequiredMembers(XmlReaderDelegator xmlReader, XmlDictionaryString[] memberNames, XmlDictionaryString[] memberNamespaces, Int32 memberIndex, Int32 requiredIndex, ExtensionDataObject extensionData)
       at ReadArrayOfBrokenRuleFromXml(XmlReaderDelegator , XmlObjectSerializerReadContext , XmlDictionaryString[] , XmlDictionaryString[] )
       at System.Runtime.Serialization.ClassDataContract.ReadXmlValue(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context)
       at System.Runtime.Serialization.XmlObjectSerializerReadContext.ReadDataContractValue(DataContract dataContract, XmlReaderDelegator reader)
       at System.Runtime.Serialization.XmlObjectSerializerReadContextComplex.InternalDeserializeInSharedTypeMode(XmlReaderDelegator xmlReader, Int32 declaredTypeID, Type declaredType, String name, String ns)
       at System.Runtime.Serialization.XmlObjectSerializerReadContextComplex.InternalDeserialize(XmlReaderDelegator xmlReader, Int32 declaredTypeID, RuntimeTypeHandle declaredTypeHandle, String name, String ns)
       at ReadBusinessRulesFromXml(XmlReaderDelegator , XmlObjectSerializerReadContext , XmlDictionaryString[] , XmlDictionaryString[] )
       at System.Runtime.Serialization.ClassDataContract.ReadXmlValue(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context)
       at System.Runtime.Serialization.XmlObjectSerializerReadContext.ReadDataContractValue(DataContract dataContract, XmlReaderDelegator reader)
       at System.Runtime.Serialization.XmlObjectSerializerReadContextComplex.InternalDeserializeInSharedTypeMode(XmlReaderDelegator xmlReader, Int32 declaredTypeID, Type declaredType, String name, String ns)
       at System.Runtime.Serialization.XmlObjectSerializerReadContextComplex.InternalDeserialize(XmlReaderDelegator xmlReader, Int32 declaredTypeID, RuntimeTypeHandle declaredTypeHandle, String name, String ns)
       at ReadContractEditFromXml(XmlReaderDelegator , XmlObjectSerializerReadContext , XmlDictionaryString[] , XmlDictionaryString[] )
       at System.Runtime.Serialization.ClassDataContract.ReadXmlValue(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context)
       at System.Runtime.Serialization.XmlObjectSerializerReadContext.ReadDataContractValue(DataContract dataContract, XmlReaderDelegator reader)
       at System.Runtime.Serialization.XmlObjectSerializerReadContextComplex.InternalDeserializeInSharedTypeMode(XmlReaderDelegator xmlReader, Int32 declaredTypeID, Type declaredType, String name, String ns)
       at System.Runtime.Serialization.XmlObjectSerializerReadContextComplex.InternalDeserialize(XmlReaderDelegator xmlReader, Int32 declaredTypeID, RuntimeTypeHandle declaredTypeHandle, String name, String ns)
       at ReadDataPortalResultFromXml(XmlReaderDelegator , XmlObjectSerializerReadContext , XmlDictionaryString[] , XmlDictionaryString[] )
       at System.Runtime.Serialization.ClassDataContract.ReadXmlValue(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context)
       at System.Runtime.Serialization.XmlObjectSerializerReadContext.ReadDataContractValue(DataContract dataContract, XmlReaderDelegator reader)
       at System.Runtime.Serialization.XmlObjectSerializerReadContextComplex.InternalDeserializeInSharedTypeMode(XmlReaderDelegator xmlReader, Int32 declaredTypeID, Type declaredType, String name, String ns)
       at System.Runtime.Serialization.XmlObjectSerializerReadContextComplex.InternalDeserialize(XmlReaderDelegator xmlReader, Int32 declaredTypeID, RuntimeTypeHandle declaredTypeHandle, String name, String ns)
       at ReadWcfResponseFromXml(XmlReaderDelegator , XmlObjectSerializerReadContext , XmlDictionaryString[] , XmlDictionaryString[] )
       at System.Runtime.Serialization.ClassDataContract.ReadXmlValue(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context)
       at System.Runtime.Serialization.XmlObjectSerializerReadContext.ReadDataContractValue(DataContract dataContract, XmlReaderDelegator reader)
       at System.Runtime.Serialization.XmlObjectSerializerReadContextComplex.InternalDeserializeInSharedTypeMode(XmlReaderDelegator xmlReader, Int32 declaredTypeID, Type declaredType, String name, String ns)
       at System.Runtime.Serialization.XmlObjectSerializerReadContextComplex.InternalDeserialize(XmlReaderDelegator xmlReader, Type declaredType, String name, String ns)
       at System.Runtime.Serialization.NetDataContractSerializer.InternalReadObject(XmlReaderDelegator xmlReader, Boolean verifyObjectName)
       at System.Runtime.Serialization.XmlObjectSerializer.InternalReadObject(XmlReaderDelegator reader, Boolean verifyObjectName, DataContractResolver dataContractResolver)
       at

 My app.config:

<?xml version="1.0"?>
<configuration>
  <appSettings>
    <add key="DalManagerType" value="MyDb.DalEf.DalManager,MyDb.DalEf"/>
    <add key="CslaDataPortalProxy" value="Csla.DataPortalClient.WcfProxy, Csla"/>
    <add key="CslaDataPortalUrl" value="http://localhost:52348/WcfPortal.svc"/>
    <!--<add key="CslaDataPortalProxy" value="Local" />-->
    <!--<add key="CslaAuthentication" value="Windows"/>-->
  </appSettings>
  <connectionStrings>
    <add name="CharisCTKEntities" connectionString="metadata=res://*/MyDb.csdl|res://*/MyDb.ssdl|res://*/MyDb.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=MyComputer;Initial Catalog=MyDb;Integrated Security=True;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient"/>
  </connectionStrings>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
 

 Test code excerpt:

   {
            var principal = new System.Security.Principal.GenericPrincipal(
                  new System.Security.Principal.GenericIdentity("Test"),
                  new string[] { "ContractManager" });
            Csla.ApplicationContext.User = principal;

            CC.CharisCTK.Library.Security.CTPrincipal.Login("john", "john");

            var obj = ContractEdit.NewContract();
            obj.CompanyName = "My Company";
            obj.StartDate = Convert.ToDateTime("6/1/2011");

               obj = obj.Save(); //error happens here
                ContractEdit.DeleteContract(obj.Id);
           }

 Any help on how to troubleshoot this problem would be greatly appreciated.

Thank you

JonnyBee replied on Friday, October 21, 2011

You must use a serializable principal and we recommend that you use CslaPrincipal/CslaIdentity rather than GenericPrincipal/GenericIdentity.

When you use remote proxy the user principal is also serialized and sent to the server.

HelioD replied on Friday, October 21, 2011

Hi Jonny,

Thank you very much for your reply. I'll make the changes you recommended and see how it goes.

Helio

HelioD replied on Tuesday, October 25, 2011

Hi Jonny,

I changed my code to use CslaPrincipal/CslaIndenty but I still cannot get the remote proxy to work.

I have a bit more info:

(1) The code actually inserts the record to the database but fails to deserialize the object to the client.

(2) This is the information from the WCF trace:

><Message>The specified domain either does not exist or could not be contacted</Message><StackTrace>   at System.ServiceModel.UpnEndpointIdentity.GetUpnFromDownlevelName(String downlevelName)

The service '/WcfPortal.svc' cannot be activated due to an exception during compilation.  The exception message is: The configuration section cannot contain a CDATA or text element. (D:\Development\MyDb.Wcf\web.config line 41). ---&amp;gt; System.Configuration.ConfigurationErrorsException: The configuration section cannot contain a CDATA or text element. (D:\Development\MyDb.Wcf\web.config line 41)

I've already checked the Web.config file and removed all comments that could possibly cause CDATA errors but it still doesn't work. Any help to direct me to the solution would be great for I am very keen to have the remote proxy approach working.

(3) Here's a copy of the D:\Development\MyDb.Wcf\web.config :

<?xml version="1.0"?>
<configuration>
  <appSettings>
    <add key="DalManagerType" value="MyDb.DalEf.DalManager,MyDb.DalEf"/>
    <add key="CslaDataPortalUrl" value="http://localhost:52348/WcfPortal.svc"/>
  </appSettings>
  <connectionStrings>
    <add name="MyDbEntities" connectionString="metadata=res://*/MyDb.csdl|res://*/MyDb.ssdl|res://*/MyDb.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=Machine01;Initial Catalog=MyDb;Integrated Security=True;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient"/>
  </connectionStrings>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
    <httpRuntime maxRequestLength="2147483647"/>
  </system.web>

  <system.diagnostics>
    <sources>
      <source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true">
        <listeners>
          <add name="traceListener" type="System.Diagnostics.XmlWriterTraceListener" initializeData="c:\temp\WcfTrace.xml" />
        </listeners>
      </source>
    </sources>
    <trace autoflush="true" />
  </system.diagnostics>
  <system.serviceModel>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    <services>
      <service name="Csla.Server.Hosts.WcfPortal"
               behaviorConfiguration="returnFaults">
        <endpoint binding="wsHttpBinding" bindingConfiguration="wsHttpBinding_IWcfPortal"
                  contract="Csla.Server.Hosts.IWcfPortal"/>
      </service>
      <service name="Csla.Server.Hosts.Silverlight.WcfPortal"
               behaviorConfiguration="returnFaults" >
        <endpoint binding="basicHttpBinding" bindingConfiguration="basicHttpBinding_IWcfPortal"
                  contract="Csla.Server.Hosts.Silverlight.IWcfPortal"/>
      </service>
    </services>
    <bindings>
      <basicHttpBinding>
        <binding name="basicHttpBinding_IWcfPortal"
                 maxReceivedMessageSize="2147483647"
                 maxBufferPoolSize="2147483647"
                 maxBufferSize="2147483647" receiveTimeout="00:10:00" sendTimeout="00:10:00">
          <readerQuotas maxBytesPerRead="2147483647"
                        maxArrayLength="2147483647"
                        maxStringContentLength="2147483647"
                        maxNameTableCharCount="2147483647"
                        maxDepth="2147483647"/>
        </binding>
      </basicHttpBinding>
      <wsHttpBinding>
        <binding name="wsHttpBinding_IWcfPortal"
                 maxReceivedMessageSize="2147483647" receiveTimeout="00:10:00" sendTimeout="00:10:00">
          <readerQuotas maxBytesPerRead="2147483647"
                        maxArrayLength="2147483647"
                        maxStringContentLength="2147483647"
                        maxNameTableCharCount="2147483647"
                        maxDepth="2147483647"/>
        </binding>
       
      </wsHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="returnFaults">
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

 

 

RockfordLhotka replied on Tuesday, October 25, 2011

Are you following the setup for server and client config as described in Using CSLA 4: Data Portal Configuration?

Are you absolutely sure that you are using the .NET Csla.dll on the server, and the appropiately targeted Csla.dll for your client (.NET/SL/WP)?

HelioD replied on Tuesday, November 08, 2011

The problem was with the client configuration. All's well now.

Thank you for your help.

 

 

Copyright (c) Marimer LLC