Serialization question

Serialization question

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


Mark Sulkowski posted on Wednesday, September 26, 2012

When I call DataPortal.Fetch using WCF, the following ExceptionDetail is caught in WcfProxy.Fetch:

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:request. The InnerException message was 'Error in line 1 position 1349. 'EndElement' '_criteria' from namespace 'http://schemas.datacontract.org/2004/07/Csla.Server.Hosts.WcfChannel' is not expected. Expecting element '_x003C_Guid_x003E_k__BackingField'.'.  Please see InnerException for more details.

I had created and sent my own criteria object:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

[

 

Serializable]

 

 

 

public class SelectCriteria

{

 

 

 

public SelectCriteria(Int32 rowId) {RowId = rowId;}

 

 

 

public SelectCriteria(Guid guid) {Guid = guid;}

 

 

 

public Int32? RowId { get; set; }

 

 

 

 

 

 

public Guid? Guid { get; set; }

}

I'm using .NET 4.0 at the moment.  The App.config of my client assembly is:

<?

 

 

xml version="1.0" encoding="utf-8" ?>

<

 

 

configuration>

<

 

 

system.serviceModel>

<

 

 

client>

<

 

 

endpoint name="WcfDataPortal"

 

 

 

address="http://localhost:58585/WcfPortal.svc"

 

 

 

binding="wsHttpBinding"

 

 

 

contract="Csla.Server.Hosts.IWcfPortal" />

</

 

 

client>

</

 

 

system.serviceModel>

<

 

 

appSettings>

<

 

 

add key="CslaAuthentication" value="Windows"/>

<

 

 

add key="CslaAuthorizationProvider" value="Server.AuthorizeDataPortal, Server"/>

<

 

 

add key="CslaDataPortalProxy" value="Csla.DataPortalClient.WcfProxy, Csla"/>

<

 

 

add key="CslaDataPortalUrl" value="http://localhost:58585/WcfPortal.svc"/>

</

 

 

appSettings>

</

 

 

configuration>

And the Web.config of my WCF service looks like this:

<?

 

 

xml version="1.0"?>

<

 

 

configuration>

<

 

 

appSettings>

<

 

 

add key="CslaAuthentication" value="Windows"/>

</

appSettings>

<!--

 

 

Begin System Service Model -->

<

 

 

system.serviceModel>

<

 

 

serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

<

 

 

services>

<

 

 

service name="Csla.Server.Hosts.WcfPortal"

 

 

 

behaviorConfiguration="MyServiceTypeBehaviors">

<

 

 

endpoint binding="wsHttpBinding"

 

 

 

contract="Csla.Server.Hosts.IWcfPortal"/>

</

 

 

service>

</

 

 

services>

<

 

 

bindings>

<

 

 

wsHttpBinding>

<

 

 

binding name="wsHttpBinding_IWcfPortal"

 

 

 

maxReceivedMessageSize="2147483647">

<

 

 

readerQuotas maxBytesPerRead="2147483647"

 

 

 

maxArrayLength="2147483647"

 

 

 

maxStringContentLength="2147483647"

 

 

 

maxDepth="2147483647"/>

</

 

 

binding>

</

 

 

wsHttpBinding>

</

 

 

bindings>

<

 

 

behaviors>

<

 

 

serviceBehaviors>

<

 

 

behavior name="MyServiceTypeBehaviors">

<!--

 

 

To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->

<

 

 

serviceDebug includeExceptionDetailInFaults="true"/>

</

 

 

behavior>

</

 

 

serviceBehaviors>

</

 

 

behaviors>

</

 

 

system.serviceModel>

<!--

 

 

End System Service Model -->

<

 

 

system.web>

<

 

 

compilation debug="true" targetFramework="4.0" />

<

 

 

httpRuntime maxRequestLength="2147483647"/>

</

 

 

system.web>

<

 

 

system.webServer>

<

 

 

modules runAllManagedModulesForAllRequests="true"/>

</

 

 

system.webServer>

</

 

 

configuration>

There is a Fetch method in the expected that is reached if I remove the [Serializable] attribute from the SelectCriteria class.  (The method is reached, but the values of the properties are nulls, because no serialization is attempted.)

What is going on?  Why isn't serialization happening as it should?

Mark Sulkowski

RockfordLhotka replied on Wednesday, September 26, 2012

This is with CSLA 4.3?

Mark Sulkowski replied on Thursday, September 27, 2012

Yes, it was with CSLA 4.3.

However, the key element that I had missed was to subclass my criteria class from CriteriaBase.  That did the trick.

JonnyBee replied on Wednesday, September 26, 2012

Your criteria class should inherit from CriteriaBase class and implement managed properties.

Copyright (c) Marimer LLC