I am having a problem converting enum to my WCF application.
I have a class Accountthat inherits an interface IAccountdefined as follows:
namespace MyNamespace
{
public interface IAccount
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string EmailAddress { get; set; }
public Country Country { get; set; }
}
}
A class Accountthat inherits from IAccountis defined as:
namespace MyNamespace
{
[DataContract]
public Account : IAccount
{
[DataMember]
public string FirstName { get; set; }
[DataMember]
public string LastName { get; set; }
[DataMember]
public string EmailAddress { get; set; }
[DataMember]
public Country Country { get; set; }
}
}
}
The country is Enumas follows:
namespace MyNamespace
{
public enum Country
{
America = 1,
England = 2,
France = 3
}
}
Creating an object Accounton the client side and calling the decorated AddAccount method OperationContractserializes the Account object as:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<AddAccount xmlns="http://tempuri.org/">
<account>
<FirstName xmlns="http://schemas.datacontract.org/2004/07/MyNamespace">MyFirstName</FirstName>
<LastName xmlns="http://schemas.datacontract.org/2004/07/MyNamespace">MyLastName</LastName>
<EmailAddress xmlns="http://schemas.datacontract.org/2004/07/MyNamespace">MyEmail@gmail.com</EmailAddress>
</account>
</AddAccount>
</soap:Body>
</soap:Envelope>
You will notice that the enumeration is Countrynot serializable.
I tried everything: from decorating an enumeration with DataContract and EnumMember and even explicitly setting the namespace in the attribute values for DataContracts to uniformly set the values for EnumMember attributes, but nothing works.
, - - , , .
UPDATE:
, WCF -, , [System.Xml.Serialization.XmlElementAttribute(IsNullable = true)], .