Reputation: 804
I have the following ServiceContract:
[ServiceContract(Namespace = "http://WebAdmin.Services.AdministrativeService", Name = "AdministrativeService")]
public interface IAdministrativeService
{
/// <summary>
/// Add the group based on the provided criteria
/// </summary>
/// <example>
/// <code>
/// service.AddWebGroup
/// (new User {
/// SequenceNumber = 1,
/// },
/// new Group
/// {
/// GroupName = "Example Group"
/// },
/// new Application
/// {
/// ApplicationCode = "DS"
/// }
/// );
/// </code>
/// </example>
/// <param name="webUser"><see cref="WebUser"/>The user a</param>
/// <param name="group"><see cref="Group"/></param>
/// <param name="application"><see cref="Application"/></param>
/// <returns><see cref="Group"/></returns>
[OperationContract]
[TransactionFlow(TransactionFlowOption.Mandatory)]
[FaultContract(typeof(ErrorFault))]
[PrincipalPermission(SecurityAction.Demand, Role = "WEB_ADMIN_SVC")]
Group AddWebGroup(WebUser webUser, Group group, Application application);
}
With the following DataContracts:
[DataContract]
public class WebUser
{
[DataMember]
public long? SequenceNumber { get; set; }
[DataMember]
public List<UserRole> Roles { get; set; }
}
[DataContract]
public class UserRole
{
[DataMember]
public long? RoleID { get; set; }
[DataMember]
public string Name { get; set; }
[DataMember]
public Application Application { get; set; }
[DataMember]
public Group Group { get; set; }
}
{
[DataContract]
public class Application
{
[DataMember]
public string ApplicationCode { get; set; }
[DataMember]
public string ApplicationName { get; set; }
[DataMember]
public string ContactEmailAddress { get; set; }
[DataMember]
public string DivisionCode { get; set; }
}
[DataContract]
public class Group
{
[DataMember]
public long? GroupID { get; set; }
[DataMember]
public string GroupName { get; set; }
}
With the following implementation:
[ServiceBehavior(
ConcurrencyMode = ConcurrencyMode.Single,
InstanceContextMode = InstanceContextMode.PerSession,
ReleaseServiceInstanceOnTransactionComplete = false,
TransactionIsolationLevel = System.Transactions.IsolationLevel.Serializable
)]
public class AdministrativeService : ServiceBase, IAdministrativeService
{
#region Implementation of IAdministrativeService
/// <summary>
/// Add the group based on the provided criteria
/// </summary>
/// <example>
/// <code>
/// service.AddWebGroup
/// (new User {
/// SequenceNumber = 1,
/// },
/// new Group
/// {
/// GroupName = "Example Group"
/// },
/// new Application
/// {
/// ApplicationCode = "DS"
/// }
/// );
/// </code>
/// </example>
/// <param name="webUser"><see cref="WebUser"/>The user adding the group</param>
/// <param name="group"><see cref="Group"/>The Group being added</param>
/// <param name="application"><see cref="Application"/>The associated application</param>
/// <returns><see cref="Group"/> With the ID set</returns>
[OperationBehavior(TransactionAutoComplete = true, TransactionScopeRequired = true)]
public Group AddWebGroup(WebUser webUser, Group group, Application application)
{
if (webUser == null)
throw new ArgumentException("user");
if (webUser.SequenceNumber == long.MinValue)
throw new ArgumentException("user sequence number");
if (group == null || string.IsNullOrWhiteSpace(group.GroupName))
throw new ArgumentNullException("group");
if (application == null || string.IsNullOrWhiteSpace(application.ApplicationCode))
throw new ArgumentException("application");
var service = Resolve<IWebGroupService>();
var criteria = new GroupCriteriaEntity
{
ApplicationCode = application.ApplicationCode,
Group = new GroupEntity{GroupName = group.GroupName,},
User = new UserEntity{SequenceNumber = webUser.SequenceNumber,}
};
GroupEntity result = null;
try
{
result = service.InsertWebGroup(criteria);
}
catch (Exception ex)
{
ex.Data.Add("result",criteria);
ExceptionPolicy.HandleException(ex, "Service Policy");
}
var groupResult = new Group
{
GroupID = result.SequenceNumber
};
return groupResult;
}
The service model binding is using wsHttpBinding with TransportMessageCredential...
All of this excellent stuff works in a dev environment. Transactions commit and roll back as expected. The user credentials allow and prevent the user from executing the codes and all in all everyone is happy happy happy.
The test environment is supposed to be an identical setup as the dev environment. However, when the proxy client invokes the service I get the following exception:
HandlingInstanceID: 44a7c5ae-17fc-4d14-b55e-1aa53bb156e0
An exception of type 'System.ArgumentException' occurred and was caught.
06/13/2012 15:39:11 Type : System.ArgumentException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 Message : Argument passed in is not serializable. Parameter name: value Source : mscorlib Help link : ParamName : value Data : System.Collections.ListDictionaryInternal TargetSite : Void Add(System.Object, System.Object) Stack Trace : at System.Collections.ListDictionaryInternal.Add(Object key, Object value) at Administrative.Service.AdministrativeService.AddWebGroup(WebUser webUser, Group group, Application application) at SyncInvokeAddWebGroup(Object , Object[] , Object[] ) at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs) at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc) at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)
Any ideas on why this would occur on one machine but not another? Why would I be getting an error that I am passing a non-serializable object when all objects are being passed are objects gnerated in the proxy client and are tagged with DataContract?
Upvotes: 0
Views: 710
Reputation: 19842
It looks like the exception is happening at the exception handler where you do: ex.Data.Add("result",criteria);
, but I don't see in your data contracts (the ones you showed) where GroupCriteriaEntity is defined, is that one also serializable?
Upvotes: 2