Using ContractNamespace to enumerate names in WCF
I am trying to create the correct WSDL namespaces for my C # enums using ContractNamespace
attributes instead of decorating each type.
The following code correctly generates the type Person
at http://www.mynamespace.co.za/ "but for some reason Gender
is in a different WSDL Namespace, http://schemas.datacontract.org/2004/07/SomeOtherNamespace ".
What am I missing? Do you need special dressings?
[assembly: ContractNamespace("http://www.mynamespace.co.za/", ClrNamespace = "SomeOtherNamespace")]
namespace SomeOtherNamespace
{
public class Person
{
public int Age { get; set; }
public Gender Gender { get; set; }
}
public enum Gender
{
Male,
Female,
Other
}
}
In my actual code, the types live in an external, generated assembly. Types cannot be easily decorated with custom attributes. ContractNamespace
would be perfect if it could work for enums too ...
In other words, the following works, but it would be very painful to get into the code generation process.
[DataContract(Namespace = "http://www.mynamespace.co.za/")]
public enum Gender
{
[EnumMember]
Male,
[EnumMember]
Female,
[EnumMember]
Other
}
source to share