WCF error deserializing my Response Object

G

galtulsa

{"Type 'System.Object[]' cannot be added to list of known types since another
type 'System.Collections.ArrayList' with the same data contract name
'http://schemas.microsoft.com/2003/10/Serialization/Arrays:ArrayOfanyType' is
already present."}



Error deserializing my Response Object


I am getting an exception when deserializing on the client side.

{"Type 'System.Object[]' cannot be added to list of known types since
another type 'System.Collections.ArrayList' with the same data contract name
'http://schemas.microsoft.com/2003/10/Serialization/Arrays:ArrayOfanyType' is
already present."}


The service method looks like:

public ResponseEntity LoginUser(RequestEntity request)
{
_userFacade = new UserFacade(request.Agency);
return _userFacade.LoginUser((string)request.RequestObjects[0],
(string)request.RequestObjects[1]);
}

Where I am passing username and password as an array parameters on the
RequestEntity object.

The user Facade looks like:

public ResponseEntity LoginUser(string userID, string password)
{
var response = new ResponseEntity(String.Empty, false);
try
{
var userBusinessController = new
UserBusinessController(AgencyName);
User user = userBusinessController.LoginUser(userID,
password);
response.ResponseObject = user;
response.IsSuccess = true;
}

catch (Exception ex)
{
// ExceptionHandler.HandleException(ex,
My.Resources.FacadeResource.generic_policy);
response = ProcessException(ex);
}
return response;
}


The Response Object looks like:

[MessageContract]
public class ResponseEntity
{
#region Private Members
private Boolean _isSuccess;
private object _responseObject;
private string _message;
#endregion

#region Constructors

public ResponseEntity()
{
}
public ResponseEntity(string message, Boolean isSuccess)
{
_message = message;
_isSuccess = isSuccess;
}

#endregion

#region Properties

[MessageBodyMember]
public Boolean IsSuccess
{
get { return _isSuccess; }
set { _isSuccess = value; }
}
[MessageBodyMember]
public string Message
{
get { return _message; }
set { _message = value; }
}
[MessageBodyMember]
public object ResponseObject
{
get { return _responseObject; }
set { _responseObject = value; }
}
#endregion

}


Using the SVCtracerViewer I can see the message created on the server side
and looks like:



<MessageLogTraceRecord>
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"
xmlns:a="http://www.w3.org/2005/08/addressing"
xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<s:Header>
<a:Action
s:mustUnderstand="1">http://www.cprops.com/IUserService/LoginUserResponse</a:Action>
<ActivityId CorrelationId="8696cbf9-9e55-4c2a-a4cc-ae339aff1e00"
xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics">2fe8b8ac-9b53-4876-9139-321d3645ab8f</ActivityId>
<a:RelatesTo>urn:uuid:997a9063-24c4-4b38-87ba-13b5bd79ba48</a:RelatesTo>
<o:Security s:mustUnderstand="1"
xmlns:blush:="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<u:Timestamp u:Id="_0">
<u:Created>2008-03-26T18:29:45.515Z</u:Created>
<u:Expires>2008-03-26T18:34:45.515Z</u:Expires>
</u:Timestamp>
</o:Security>
</s:Header>
<s:Body>
<ResponseEntity xmlns="http://www.cprops.com/">
<IsSuccess>true</IsSuccess>
<Message></Message>
<ResponseObject i:type="b:User"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance"
xmlns:b="http://schemas.datacontract.org/2004/07/CPR.DMS.BusinessEntity">
<_isDirty
xmlns="http://schemas.datacontract.org/2004/07/CPR.DMS.Framework.Business">false</_isDirty>
<_systemID
xmlns="http://schemas.datacontract.org/2004/07/CPR.DMS.Framework.Business">fa61c113-1818-4d6e-9bd5-e983bcd2895b</_systemID>
<_systemParentID i:nil="true"
xmlns="http://schemas.datacontract.org/2004/07/CPR.DMS.Framework.Business"></_systemParentID>
<b:Answer i:nil="true"></b:Answer>
<b:IsLoggedIn>true</b:IsLoggedIn>
<b:LastLogonDateTime>2008-03-26T13:30:29.573</b:LastLogonDateTime>
<b:LogonDateTime>2008-03-26T13:30:29.573</b:LogonDateTime>
<b:pin>32622</b:pin>
<b:Question i:nil="true"></b:Question>
<b:SystemRights>ReadOnly</b:SystemRights>
<b:UserID>10001</b:UserID>
<b:UserType>2</b:UserType>
<b:WebUserType>CounselingClient</b:WebUserType>
</ResponseObject>
</ResponseEntity>
</s:Body>
</s:Envelope>
</MessageLogTraceRecord>



I am not sure why this Message is not serialize correctly. I have set up all
the attributes Dtaacontracts, DataMembers, Etc.

and the web.config looks like:

<system.serviceModel>
<diagnostics>
<messageLogging logEntireMessage="true" logMalformedMessages="true"
logMessagesAtTransportLevel="true" maxMessagesToLog="50000000"
maxSizeOfMessageToLog="50000000" />
</diagnostics>
<bindings>
<wsHttpBinding>
<binding name="TransportSecurity">
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="Windows"
proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows"
negotiateServiceCredential="true" algorithmSuite="Default"
establishSecurityContext="true" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<services>
<service
behaviorConfiguration="CPR.DMS.Server.Service.UserServiceBehavior"
name="CPR.DMS.Server.Service.UserService">
<endpoint address="https://localhost/DMSRemoteAgency/UserService.svc"
binding="wsHttpBinding" bindingConfiguration="TransportSecurity"
contract="CPR.DMS.Server.Service.IUserService" />
<endpoint address="mex" binding="mexHttpsBinding"
contract="IMetadataExchange" />
<host>
<timeouts closeTimeout="00:01:10" openTimeout="00:05:00" />
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="CPR.DMS.Server.Service.UserServiceBehavior">
<serviceMetadata httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>


I generate the Client proxy using Visual Studio 2008 and what I believe
should be causing problems is on the following lines:

[System.Diagnostics.DebuggerStepThroughAttribute()]

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "3.0.0.0")]

[System.Runtime.Serialization.CollectionDataContractAttribute(Name="EntityPropertyCollection",
Namespace="http://schemas.datacontract.org/2004/07/CPR.DMS.Framework.Business", ItemName="anyType")]
[System.SerializableAttribute()]
public class EntityPropertyCollection :
System.Collections.Generic.List<object> {
}

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel",
"3.0.0.0")]

[System.ServiceModel.ServiceContractAttribute(Namespace="http://www.cprops.com/", ConfigurationName="UserService.IUserService")]
public interface IUserService {

// CODEGEN: Generating message contract since the wrapper name
(RequestEntity) of message RequestEntity does not match the default value
(LoginUser)

[System.ServiceModel.OperationContractAttribute(Action="http://www.cprops.com/IUserService/LoginUser",
ReplyAction="http://www.cprops.com/IUserService/LoginUserResponse")]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(object[]))]

[System.ServiceModel.ServiceKnownTypeAttribute(typeof(CPR.DMS.Framework.Business.BusinessEntity))]

[System.ServiceModel.ServiceKnownTypeAttribute(typeof(CPR.DMS.ClientProxy.UserService.EntityPropertyCollection))]

[System.ServiceModel.ServiceKnownTypeAttribute(typeof(CPR.DMS.BusinessEntity.User))]

[System.ServiceModel.ServiceKnownTypeAttribute(typeof(CPR.DMS.BusinessEntity.SystemRights))]

[System.ServiceModel.ServiceKnownTypeAttribute(typeof(CPR.DMS.BusinessEntity.WebUserType))]
CPR.DMS.ClientProxy.UserService.ResponseEntity
LoginUser(CPR.DMS.ClientProxy.UserService.RequestEntity request);
}



The line: public class EntityPropertyCollection :
System.Collections.Generic.List<object> {
and the line
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(object[]))] must be the
reason why I am getting the error:

{"Type 'System.Object[]' cannot be added to list of known types since
another type 'System.Collections.ArrayList' with the same data contract name
'http://schemas.microsoft.com/2003/10/Serialization/Arrays:ArrayOfanyType' is
already present."}


The user Object looks like:

[Serializable]
[KnownType(typeof(WebUserType))]
[DataContract]
public partial class User : CPR.DMS.Framework.Business.BusinessEntity
{

#region "PRIVATE DECLARATIONS"

internal protected EntityProperty<String> _userID =
(EntityProperty<String>)_propertyCollection.Add(new
EntityProperty<String>("UserID", EntityPropertyOptions.IsRequired, new
StringValidator(0, 50)));
internal protected EntityProperty<Int32> _userType =
(EntityProperty<Int32>)_propertyCollection.Add(new
EntityProperty<Int32>("UserType"));
internal protected EntityProperty<String> _pin =
(EntityProperty<String>)_propertyCollection.Add(new
EntityProperty<String>("Pin", new StringValidator(0, 50)));
internal protected EntityProperty<String> _question =
(EntityProperty<String>)_propertyCollection.Add(new
EntityProperty<String>("Question", new StringValidator(0, 50)));
internal protected EntityProperty<String> _answer =
(EntityProperty<String>)_propertyCollection.Add(new
EntityProperty<String>("Answer", new StringValidator(0, 50)));
internal protected EntityProperty<DateTime?> _lastLogonDateTime =
(EntityProperty<DateTime?>)_propertyCollection.Add(new
EntityProperty<DateTime?>("LogonDateTime"));
internal protected EntityProperty<WebUserType> _webUserType =
(EntityProperty<WebUserType>)_propertyCollection.Add(new
EntityProperty<WebUserType>("WebUserType"));

#endregion



#region "PROPERTY DECLARATIONS"
[DataMember]
public String UserID
{
get { return _userID.Value; }
set { _userID.Value = value; }
}
[DataMember]
public Int32 UserType
{
get { return _userType.Value; }
set { _userType.Value = value; }
}
[DataMember]
public String Pin
{
get { return _pin.Value; }
set { _pin.Value = value;}
}
[DataMember]
public String Question
{
get { return _question.Value; }
set { _question.Value = value;}
}
[DataMember]
public String Answer
{
get { return _answer.Value; }
set {_answer.Value = value; }
}
[DataMember]
public DateTime? LastLogonDateTime
{
get { return _lastLogonDateTime.Value; }
set { _lastLogonDateTime.Value = value; }
}
[DataMember]
public WebUserType WebUserType
{
get { return _webUserType.Value; }
set { _webUserType.Value = value; }
}


#endregion


[OnDeserializingAttribute()]
public void Init(StreamingContext context)
{
_userID = (EntityProperty<String>)_propertyCollection.Add(new
EntityProperty<String>("UserID", EntityPropertyOptions.IsRequired, new
StringValidator(0, 50)));
_userType = (EntityProperty<Int32>)_propertyCollection.Add(new
EntityProperty<Int32>("UserType"));
_pin = (EntityProperty<String>)_propertyCollection.Add(new
EntityProperty<String>("Pin", new StringValidator(0, 50)));
_question = (EntityProperty<String>)_propertyCollection.Add(new
EntityProperty<String>("Question", new StringValidator(0, 50)));
_answer = (EntityProperty<String>)_propertyCollection.Add(new
EntityProperty<String>("Answer", new StringValidator(0, 50)));
_lastLogonDateTime =
(EntityProperty<DateTime?>)_propertyCollection.Add(new
EntityProperty<DateTime?>("LogonDateTime"));
_webUserType =
(EntityProperty<WebUserType>)_propertyCollection.Add(new
EntityProperty<WebUserType>("WebUserType"));

}

}



Any Ideas why I might be getting this error?

Thanks
 
G

galtulsa

I found the solution.

I had a custom collection called EntityPropertyCollection that had the
[CollectionDataContract] but also was adding a private member as ArrayList to
store items which was redundant since the base class was storing the items as
a generic list.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top