nkewney
asked on
Returning a custom object in a WCF data contract
Dear Experts,
I was hoping somebody could help me with a problem I'm having with a WCF Service.
I'm trying to return a cusom object (defined elsewhere in my application) via my WCF service.
The object I'm trying to return is "UserExchangeCredentialSet Collection " which contains many "UserExchangeCredentialSet " items.
My Interface, (IExchangeService), has the following:
[OperationBehavior]
public UserExchangeCredentialSetC ollection GetActiveExchangeUserColle ction()
{
return UserExchangeCredentialSetM ethods.Get ActiveUser ExchangeCr edentialSe tCollectio n();
}
My service contract contains:
[OperationContract]
UserExchangeCredentialSetC ollection GetActiveExchangeUserColle ction();
Do I need to define this in my data contract?
If so, could somebody give me an idea of the best way to do this to enable me to use this data in my client application!
Many thanks in advance.
Nick
I was hoping somebody could help me with a problem I'm having with a WCF Service.
I'm trying to return a cusom object (defined elsewhere in my application) via my WCF service.
The object I'm trying to return is "UserExchangeCredentialSet
My Interface, (IExchangeService), has the following:
[OperationBehavior]
public UserExchangeCredentialSetC
{
return UserExchangeCredentialSetM
}
My service contract contains:
[OperationContract]
UserExchangeCredentialSetC
Do I need to define this in my data contract?
If so, could somebody give me an idea of the best way to do this to enable me to use this data in my client application!
Many thanks in advance.
Nick
Current DataContract.cs (for testing only, with no mention of this collection)
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
namespace LayerExchangeServices
{
[DataContract]
public class Request
{
string name;
[DataMember]
public string Name
{
get { return name; }
set { name = value; }
}
}
[DataContract]
public class Response
{
string message;
[DataMember]
public string Message
{
get { return message; }
set { message = value; }
}
}
}
If the UserExchangeCredentialSetC ollection contains other objects then these will also have to have the DataContract and DataMember attributes added.
ASKER
Thanks Guys.
Like this?
Like this?
[DataContract]
public class UserExchangeCredentialSet
{
[DataMember]
public Boolean EXCHG_APPT_SYNC { get; set; }
[DataMember]
public string EXCHG_SVR { get; set; }
[DataMember]
public string EXCHG_EMAIL { get; set; }
[DataMember]
public string EXCHG_DOMAIN { get; set; }
[DataMember]
public string EXCHG_USER { get; set; }
[DataMember]
public string EXCHG_PASSWD { get; set; }
public UserExchangeCredentialSet() { }
[DataContract]
public class UserExchangeCredentialSetCollection : CollectionBase
{
[DataMember]
public UserExchangeCredentialSet this[int index]
{
get
{
return (UserExchangeCredentialSet)base.List[index];
}
set
{
base.List[index] = value;
}
}
Hi,
Some post say that there are problem others say not
Yes, there is a problem with collections...
http://borismod.blogspot.com/2009/04/wcf-collectiondatacontract-and.html
http://just2thepoint.blogspot.com/2008/05/wcf-collectiondatacontract-and.html
No, there is not a problem with collections...
And from another post:http://social.msdn.microsoft.com/forums/en-US/wcf/thread/3749248c-c3b0-40eb-88db-95574205dd9a
You need to ensure that WCF knows how to serialize and deserialize all messages/paramaters used in your operations. This error can be caused by forgetting to apply e.g. [DataContract] to an class used in a message or collection. If you use derived objects you need to use the [ServiceKnownType(typeof(. ..))] attribute to let WCF know about how to de-/serialize objects not directly references in the operation contracts.
Thanks,
Darren
Some post say that there are problem others say not
Yes, there is a problem with collections...
http://borismod.blogspot.com/2009/04/wcf-collectiondatacontract-and.html
http://just2thepoint.blogspot.com/2008/05/wcf-collectiondatacontract-and.html
No, there is not a problem with collections...
And from another post:http://social.msdn.microsoft.com/forums/en-US/wcf/thread/3749248c-c3b0-40eb-88db-95574205dd9a
You need to ensure that WCF knows how to serialize and deserialize all messages/paramaters used in your operations. This error can be caused by forgetting to apply e.g. [DataContract] to an class used in a message or collection. If you use derived objects you need to use the [ServiceKnownType(typeof(.
Thanks,
Darren
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This solved my problem.
I'm not sure that I follow...
You are returning a collection of UserExchangeCredentialSet
If you are returning this then you will have to ad the DataContract and DataMember attributes to UserExchangeCredentialSet
Maybe I've missunderstood....
Cheers,
Darren