I am struggling to generate correct WSDL namespaces for my C# enums using ContractNamespace
instead of decorating each type with attributes.
The following code correctly generates the Person
type in "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 enums require special treatment?
[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. The types cannot easily be decorated with custom attributes. ContractNamespace
would be perfect if it can work for enums too...
In other words, the following works, but would be extremely painful to get into the code generation process.
[DataContract(Namespace = "http://www.mynamespace.co.za/")]
public enum Gender
{
[EnumMember]
Male,
[EnumMember]
Female,
[EnumMember]
Other
}
Enums are a pain. You must decorate the enum for the ContractNamespace
attribute to take effect.
[DataContract]
public enum Gender
{
[EnumMember]
Male,
[EnumMember]
Female,
[EnumMember]
Other
}
Should see that your type appears in the WSDL namespace you want.
These links may help you
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With