Search code examples
.netwcfauto-generate

How can I force WCF to put a type into the Client Proxy if it is not Used in the Service Contract?


I have declared an enum in my server code, and would like my client code to be able to use it. Unfortunately, it's not being auto-generated for some reson. My enum is declared similar to the following example:

[DataContract]
public enum MyEnum {
    [EnumMember]
    First = 1,
    [EnumMember]
    Second = 2
}

It's not declared inside a class, but alongside several classes that are auto-generated as well (all in the same namespace). I have no problem using these classes in my client code, but this enum isn't being generated, and therefore is not usable. Help!

Thanks!!

EDIT:

As of now, the service neither takes a "MyEnum" as a parameter anywhere, or returns it from a function. That's my problem. It's used several places in my server code, and I'd like to use it in a few places in my client code as well (without having to copy/paste an existing construct).


Solution

  • The easiest solution I came up for this problem was to create a simple WCF function that takes a MyEnum parameter and returns it. As a result, "MyEnum" will be exposed to my client.

    //Declaration
    [DataContract]
    MyEnum GetMyEnum(MyEnum value);
    
    //Definition
    public MyEnum GetMyEnum(MyEnum value){
        return value;
    }
    

    Any alternatives that don't require this and/or are more graceful would be appreciated!