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
}

      

+3


source to share


2 answers


These links can help you



+1


source


Enumerations are a pain. You have to decorate the enum for the attribute ContractNamespace

to take effect.

[DataContract]
public enum Gender
{ 
    [EnumMember]
    Male,
    [EnumMember]
    Female,
    [EnumMember]
    Other
}

      



See what your type is showing up in the WSDL namespace you want.

+5


source







All Articles