Enum?

Hi,

Can I have Enum as a DataContract with DataMembers For example:

<DataContract([Namespace]:="http://MyServices")> _

Public Enum EventType As Integer

<DataMember()> _

LOGIN_FAILED

<DataMember()> _

LOGIN_SUCCEEDED

End Enum

When I generate the above (svcutil) I get an empty Enum.

Thanks!

Scott



Answer this question

Enum?

  • Kaloyan Georgiev

    The problem seems to have resolved itself now... I cleared the solution and re-got everything from source control, and I'm no longer getting the same problem. I guess it was a dirty build issue somewhere, though I'm still not sure what caused it.

    Cheers for the help!


  • Denham

    //If one of the service contract has reference to Enum types(Parameters or return value),svcutil will import enum types to client side proxy

    //Simple Enum decalaration should be enough

    Public Enum Seasons As Integer

    Summer = 1

    Winter = 2

    Spring = 3

    Autumn = 4

    End Enum

    <OperationContract()> _

    Sub GetEnum(ByVal enm As Seasons)



  • Swanand

    A related/extended question on the above.. I have a similar situation where my Enum has no values in the generated proxy code. However, my enum is not directly referenced by any of the OperationContract methods: it is a nested member of the DataContract class. For example:

    public enum MyEnum : int
    {
    SomeValue,
    SomeOtherValue
    }

    [DataContract]
    public class MyData
    {
    [DataMember]
    public MyEnum value
    { get { ...} set { ... } }
    }

    [ServiceContract]
    public class ServiceClass
    {
    [OperationContract]
    public MyData GetData()
    { ... }

    }

    As you can see, the ServiceClass doesn't directly reference the enum class, but the serialisation of the class is required in order to complete the call. I've tried this with various combinations of DataContract, DataMember, and EnumMember attributes to no avail. How should this enum be marked up so that it will be correctly generated in the proxy code


  • russ_mac

    //i used following code and config file and I am not able to repro this problem with FEB CTP build

    Are you using FEB CTP

    //CODE

    using System;

    using System.Collections.Generic;

    using System.Text;

    using System.Runtime.Serialization;

    using System.ServiceModel;

    namespace WCFSAMPLES

    {

    public enum MyEnum : int

    {

    SomeValue,

    SomeOtherValue

    }

    [DataContract]

    public class MyData

    {

    private MyEnum m_data;

    [DataMember]

    public MyEnum value

    {

    get

    {

    return m_data;

    }

    set

    {

    m_data=value;

    }

    }

    }

    [ServiceContract]

    public class TESTSVC

    {

    [OperationContract]

    public MyData GetData()

    {

    MyData data = new MyData();

    return data;

    }

    public static void Main()

    {

    Uri baseAddress = new Uri("http://localhost:8000/testsvc");

    ServiceHost sh = new ServiceHost(typeof(TESTSVC), baseAddress);

    sh.Open();

    Console.WriteLine("Service is ready to take calls");

    Console.ReadLine();

    }

    }

    }

    //CONFIG

    < xml version="1.0" encoding="utf-8" >

    <configuration>

    <system.serviceModel>

    <services>

    <service

    name="WCFSAMPLES.TESTSVC">

    <endpoint address=" "

    binding="wsHttpBinding"

    bindingConfiguration="DefaultBinding"

    contract=

    "WCFSAMPLES.TESTSVC" />

    </service>

    </services>

    <bindings>

    <wsHttpBinding>

    <binding name="DefaultBinding" />

    </wsHttpBinding>

    </bindings>

    </system.serviceModel>

    </configuration>

    //My proxy code looks like

    //------------------------------------------------------------------------------
    // <auto-generated>
    // This code was generated by a tool.
    // Runtime Version:2.0.50727.42
    //
    // Changes to this file may cause incorrect behavior and will be lost if
    // the code is regenerated.
    // </auto-generated>
    //------------------------------------------------------------------------------

    namespace WCFSAMPLES
    {
    using System.Runtime.Serialization;


    [System.Runtime.Serialization.DataContractAttribute()]
    public partial class MyData : object, System.Runtime.Serialization.IExtensibleDataObject
    {

    private System.Runtime.Serialization.ExtensionDataObject extensionDataField;

    private WCFSAMPLES.MyEnum valueField;

    public System.Runtime.Serialization.ExtensionDataObject ExtensionData
    {
    get
    {
    return this.extensionDataField;
    }
    set
    {
    this.extensionDataField = value;
    }
    }

    [System.Runtime.Serialization.DataMemberAttribute()]
    public WCFSAMPLES.MyEnum value
    {
    get
    {
    return this.valueField;
    }
    set
    {
    this.valueField = value;
    }
    }
    }

    public enum MyEnum : int
    {

    SomeValue = 0,

    SomeOtherValue = 1,
    }

    }


    [System.ServiceModel.MessageContractAttribute()]
    public class GetDataRequest
    {

    [System.ServiceModel.MessageBodyAttribute(Name="GetData", Namespace="http://tempuri.org/", Order=0)]
    public GetDataRequestBody Body;

    public GetDataRequest()
    {
    }

    public GetDataRequest(GetDataRequestBody Body)
    {
    this.Body = Body;
    }
    }

    [System.Runtime.Serialization.DataContractAttribute()]
    public class GetDataRequestBody
    {

    public GetDataRequestBody()
    {
    }
    }

    [System.ServiceModel.MessageContractAttribute()]
    public class GetDataResponse
    {

    [System.ServiceModel.MessageBodyAttribute(Name="GetDataResponse", Namespace="http://tempuri.org/", ProtectionLevel=System.Net.Security.ProtectionLevel.EncryptAndSign, Order=0)]
    public GetDataResponseBody Body;

    public GetDataResponse()
    {
    }

    public GetDataResponse(GetDataResponseBody Body)
    {
    this.Body = Body;
    }
    }

    [System.Runtime.Serialization.DataContractAttribute(Namespace="http://tempuri.org/")]
    public class GetDataResponseBody
    {

    [System.Runtime.Serialization.DataMemberAttribute(Order=0)]
    public WCFSAMPLES.MyData GetDataResult;

    public GetDataResponseBody()
    {
    }

    public GetDataResponseBody(WCFSAMPLES.MyData GetDataResult)
    {
    this.GetDataResult = GetDataResult;
    }
    }

    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
    [System.ServiceModel.ServiceContractAttribute()]
    public interface TESTSVC
    {

    // CODEGEN: Generating message contract since message part GetDataResult requires protection.
    [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/TESTSVC/GetData", ReplyAction="http://tempuri.org/TESTSVC/GetDataResponse")]
    GetDataResponse GetData(GetDataRequest request);
    }

    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
    public interface TESTSVCChannel : TESTSVC, System.ServiceModel.IClientChannel
    {
    }

    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
    public partial class TESTSVCProxy : System.ServiceModel.ClientBase<TESTSVC>, TESTSVC
    {

    public TESTSVCProxy()
    {
    }

    public TESTSVCProxy(string endpointConfigurationName) :
    base(endpointConfigurationName)
    {
    }

    public TESTSVCProxy(string endpointConfigurationName, string remoteAddress) :
    base(endpointConfigurationName, remoteAddress)
    {
    }

    public TESTSVCProxy(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) :
    base(endpointConfigurationName, remoteAddress)
    {
    }

    public TESTSVCProxy(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) :
    base(binding, remoteAddress)
    {
    }

    GetDataResponse TESTSVC.GetData(GetDataRequest request)
    {
    return base.InnerProxy.GetData(request);
    }

    public WCFSAMPLES.MyData GetData()
    {
    GetDataRequest inValue = new GetDataRequest();
    inValue.Body = new GetDataRequestBody();
    GetDataResponse retVal = ((TESTSVC)(this)).GetData(inValue);
    return retVal.Body.GetDataResult;
    }
    }



  • DaveInCT

    Instead of DataMember Attribute, use EnumMember Attribute to specify members of enum. From Feb CTP, only if you use EnumMemberAttribute, your enums are created properly in proxy.

     

     



  • SANDEEP MAMUNURI

    Hi

    And which is the target of another member attribute Why it was necesary to difference a member attribute from enum attribute

    Thanks in advance

    Javier


  • MattTaylor

    that did the trick,

    thanks a lot.

    Scott.


  • Enum?