Enum Problems

Discussion in 'ASP .Net Web Services' started by Oldman, Jul 3, 2006.

  1. Oldman

    Oldman Guest

    I have an enum being passed into one of my webservice methods.
    The actual enum is defined as follows:

    [pre]
    public enum StatusType
    {
    SPECIAL_1 = -2,
    SPECIAL_2 = -1,
    ENUM1 = 1,
    ENUM2,
    ENUM3,
    ENUM4
    }
    [/pre]

    The issue is that this is created in the proxy class like this:

    [pre]
    public enum StatusType
    {
    SPECIAL_1,
    SPECIAL_2,
    ENUM1,
    ENUM2,
    ENUM3,
    ENUM4
    }
    [/pre]

    So when the client passes up ENUM4 the web service thinks it has ENUM2.
    Is there are way to fix this?

    Thanks,

    Chris
    Oldman, Jul 3, 2006
    #1
    1. Advertising

  2. Oldman

    Guest

    Hallo Oldman,
    I was confused, so I have tried this one out. In fact, when you are
    passing enum types - during wsdl and everywhere on its way it is passed
    as string (complex string type with restriction). So it does not matter
    what enumeration id you assign them, you are allways passing enum's
    item name.
    I suppose, here in your case could be any other mistake before you pass
    this enum type to webservice.

    **I have used this client for my tests:
    static void Main(string[] args) {
    localhost.Service ss = new EnumType_WSTesting.localhost.Service();
    localhost.StatusType st;
    foreach (string s in Enum.GetNames(typeof(localhost.StatusType))) {
    Console.WriteLine(
    ss.HelloWorld(
    (localhost.StatusType)Enum.Parse(typeof(localhost.StatusType),
    s),
    out st)
    );
    Console.WriteLine(string.Format(" out st: {0}",st));
    }
    Console.ReadKey();
    }
    **And this code as webservice:
    public enum StatusType
    {
    SPECIAL_1 = -2,
    SPECIAL_2 = -1,
    ENUM1 = 1,
    ENUM2,
    ¨ ENUM3,
    ENUM4
    }
    [WebMethod]
    public string HelloWorld(StatusType stin, out StatusType stout) {
    stout = stin;
    return stin.ToString();
    }
    ---
    enjoy, Martin

    Oldman wrote:
    > I have an enum being passed into one of my webservice methods.
    > The actual enum is defined as follows:
    >
    > [pre]
    > public enum StatusType
    > {
    > SPECIAL_1 = -2,
    > SPECIAL_2 = -1,
    > ENUM1 = 1,
    > ENUM2,
    > ENUM3,
    > ENUM4
    > }
    > [/pre]
    >
    > The issue is that this is created in the proxy class like this:
    >
    > [pre]
    > public enum StatusType
    > {
    > SPECIAL_1,
    > SPECIAL_2,
    > ENUM1,
    > ENUM2,
    > ENUM3,
    > ENUM4
    > }
    > [/pre]
    >
    > So when the client passes up ENUM4 the web service thinks it has ENUM2.
    > Is there are way to fix this?
    >
    > Thanks,
    >
    > Chris
    , Jul 4, 2006
    #2
    1. Advertising

  3. Oldman

    Oldman Guest

    I have read the same thing but try it out. If you pass up a status type from
    the client to the server you get the behavior I described. I have not had
    problems passing back statuses from the server to client.

    However, I seemed to have fixed my problem by adding XmlEnum attributes to
    the Enum. I will dig into this some more but let me know if you can
    reproduce the problem I described.

    Thanks,

    Chris

    "" wrote:

    > Hallo Oldman,
    > I was confused, so I have tried this one out. In fact, when you are
    > passing enum types - during wsdl and everywhere on its way it is passed
    > as string (complex string type with restriction). So it does not matter
    > what enumeration id you assign them, you are allways passing enum's
    > item name.
    > I suppose, here in your case could be any other mistake before you pass
    > this enum type to webservice.
    >
    > **I have used this client for my tests:
    > static void Main(string[] args) {
    > localhost.Service ss = new EnumType_WSTesting.localhost.Service();
    > localhost.StatusType st;
    > foreach (string s in Enum.GetNames(typeof(localhost.StatusType))) {
    > Console.WriteLine(
    > ss.HelloWorld(
    > (localhost.StatusType)Enum.Parse(typeof(localhost.StatusType),
    > s),
    > out st)
    > );
    > Console.WriteLine(string.Format(" out st: {0}",st));
    > }
    > Console.ReadKey();
    > }
    > **And this code as webservice:
    > public enum StatusType
    > {
    > SPECIAL_1 = -2,
    > SPECIAL_2 = -1,
    > ENUM1 = 1,
    > ENUM2,
    > ¨ ENUM3,
    > ENUM4
    > }
    > [WebMethod]
    > public string HelloWorld(StatusType stin, out StatusType stout) {
    > stout = stin;
    > return stin.ToString();
    > }
    > ---
    > enjoy, Martin
    >
    > Oldman wrote:
    > > I have an enum being passed into one of my webservice methods.
    > > The actual enum is defined as follows:
    > >
    > > [pre]
    > > public enum StatusType
    > > {
    > > SPECIAL_1 = -2,
    > > SPECIAL_2 = -1,
    > > ENUM1 = 1,
    > > ENUM2,
    > > ENUM3,
    > > ENUM4
    > > }
    > > [/pre]
    > >
    > > The issue is that this is created in the proxy class like this:
    > >
    > > [pre]
    > > public enum StatusType
    > > {
    > > SPECIAL_1,
    > > SPECIAL_2,
    > > ENUM1,
    > > ENUM2,
    > > ENUM3,
    > > ENUM4
    > > }
    > > [/pre]
    > >
    > > So when the client passes up ENUM4 the web service thinks it has ENUM2.
    > > Is there are way to fix this?
    > >
    > > Thanks,
    > >
    > > Chris

    >
    >
    Oldman, Jul 4, 2006
    #3
  4. Oldman

    Oldman Guest

    Whoops, sorry I looked at your example again and noticed you are passing up a
    status from the client. The first time I looked at it I just saw the out
    parameter.
    Hmm. Ok, I'll dig deeper.

    Thanks,

    Chris

    "" wrote:

    > Hallo Oldman,
    > I was confused, so I have tried this one out. In fact, when you are
    > passing enum types - during wsdl and everywhere on its way it is passed
    > as string (complex string type with restriction). So it does not matter
    > what enumeration id you assign them, you are allways passing enum's
    > item name.
    > I suppose, here in your case could be any other mistake before you pass
    > this enum type to webservice.
    >
    > **I have used this client for my tests:
    > static void Main(string[] args) {
    > localhost.Service ss = new EnumType_WSTesting.localhost.Service();
    > localhost.StatusType st;
    > foreach (string s in Enum.GetNames(typeof(localhost.StatusType))) {
    > Console.WriteLine(
    > ss.HelloWorld(
    > (localhost.StatusType)Enum.Parse(typeof(localhost.StatusType),
    > s),
    > out st)
    > );
    > Console.WriteLine(string.Format(" out st: {0}",st));
    > }
    > Console.ReadKey();
    > }
    > **And this code as webservice:
    > public enum StatusType
    > {
    > SPECIAL_1 = -2,
    > SPECIAL_2 = -1,
    > ENUM1 = 1,
    > ENUM2,
    > ¨ ENUM3,
    > ENUM4
    > }
    > [WebMethod]
    > public string HelloWorld(StatusType stin, out StatusType stout) {
    > stout = stin;
    > return stin.ToString();
    > }
    > ---
    > enjoy, Martin
    >
    > Oldman wrote:
    > > I have an enum being passed into one of my webservice methods.
    > > The actual enum is defined as follows:
    > >
    > > [pre]
    > > public enum StatusType
    > > {
    > > SPECIAL_1 = -2,
    > > SPECIAL_2 = -1,
    > > ENUM1 = 1,
    > > ENUM2,
    > > ENUM3,
    > > ENUM4
    > > }
    > > [/pre]
    > >
    > > The issue is that this is created in the proxy class like this:
    > >
    > > [pre]
    > > public enum StatusType
    > > {
    > > SPECIAL_1,
    > > SPECIAL_2,
    > > ENUM1,
    > > ENUM2,
    > > ENUM3,
    > > ENUM4
    > > }
    > > [/pre]
    > >
    > > So when the client passes up ENUM4 the web service thinks it has ENUM2.
    > > Is there are way to fix this?
    > >
    > > Thanks,
    > >
    > > Chris

    >
    >
    Oldman, Jul 4, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. -

    enum within an enum

    -, Jun 12, 2005, in forum: Java
    Replies:
    6
    Views:
    522
  2. Jerminia
    Replies:
    3
    Views:
    611
    Roedy Green
    Oct 7, 2005
  3. Ernst Murnleitner

    How to enum an enum?

    Ernst Murnleitner, Nov 12, 2003, in forum: C++
    Replies:
    5
    Views:
    440
    Rolf Magnus
    Nov 13, 2003
  4. mrhicks
    Replies:
    2
    Views:
    400
    Dave Thompson
    Jun 10, 2004
  5. Randy
    Replies:
    1
    Views:
    508
    David Harmon
    Jan 7, 2006
Loading...

Share This Page