Enumerations and Wcf - The underlying connection was closed: The connection was closed unexpectedly.

Enumerations and Wcf - The underlying connection was closed: The connection was closed unexpectedly.

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


rfcdejong posted on Thursday, March 18, 2010

Using the local dataportal configuration my application is working perfectly, but when i want to use the WcfPortal configuration i bumped into the exception. "The underlying connection was closed: The connection was closed unexpectedly." After trying out several types of wpf binding, bindingConfigurations, behaviours, security, servicehostfactory, etc.. i learned alot about wcf configurations, but i couldn't solve the error without getting other errors like bad request (400) or invalid codebase..

Just changing the dataportal configuration from local to wcf won't work if u have the following.

Having an repository with id's 0, 1, 2, 3
And having an enumeration

public enum Pets
{       
       Dog = 0,
       Cat = 1
}

When trying to load the property with LoadProperty(myBO, MyBO.Pet, 3) it will just succeed and resulting into an value which is not a member of the enumeration Pets

In the local dataportal configuration this work fine
In the wcf dataportal configuration this throws "The underlying connection was closed: The connection was closed unexpectedly."

Did u guys know this won't even throw an exception?
Pets pet = (Pets)3;

The bottomline is that an enum value should be checked if it's defined.

 something like this is for now my solution

 

protected void LoadProperty(object obj, IPropertyInfo propertyInfo, object newValue)
{
    Type enumType = propertyInfo.Type;
   
if (enumType.IsEnum)
    {
       
if (!Enum.IsDefined(enumType, newValue))
        {
             
throw new InvalidCastException(newValue.ToString() + " is not a member of enum " + enumType.ToString());
        }
   
}
....

better would be an exception in the csla framework under the non-generic LoadProperty,  LoadFieldData or Utilities.CoerceValue where the enum is being checked if it's defined.

chachek replied on Thursday, March 18, 2010

Didi you try marking the enum as Serializable?

rfcdejong replied on Friday, March 19, 2010

I did as i did alot of other things, the only solution is to 100% match the datacontract definition generated by csla. Using not defined enum's will result in the common exception above "closed unexpectedly". I found something else that might work using Flags for bitwise enum usage http://geekswithblogs.net/claeyskurt/archive/2006/07/19/85667.aspx

Copyright (c) Marimer LLC