Web Service export enum to consumer

Discussion in 'ASP .Net' started by bsma1@hotmail.com, Mar 9, 2007.

  1. Guest

    I building a web service that has an enum I want the consuming
    application to be able to use.

    I have the enum declared in the web service as:
    public enum myEnum
    {
    ONE = 1,
    TWO = 2,
    };

    I want to be able to access these from the consuming application such
    as: myConsumer.localhost.myEnum.ONE. However, I can't seem to get it
    to work. How do I make this visible/export this enum to the consumer?
    I would rather not duplicate the code. Thanks for any and all help.
    , Mar 9, 2007
    #1
    1. Advertising

  2. Apply the Attribute XmlEnumAttribute for each option of the enumearion.

    <> wrote in message
    news:...
    >I building a web service that has an enum I want the consuming
    > application to be able to use.
    >
    > I have the enum declared in the web service as:
    > public enum myEnum
    > {
    > ONE = 1,
    > TWO = 2,
    > };
    >
    > I want to be able to access these from the consuming application such
    > as: myConsumer.localhost.myEnum.ONE. However, I can't seem to get it
    > to work. How do I make this visible/export this enum to the consumer?
    > I would rather not duplicate the code. Thanks for any and all help.
    >
    Mariano Omar Rodriguez, Mar 9, 2007
    #2
    1. Advertising

  3. "Mariano Omar Rodriguez" <> wrote in message
    news:...
    > Apply the Attribute XmlEnumAttribute for each option of the enumearion.
    >


    I don't believe that this will permit the client to treat the type as an
    "enum". The reason is that there is no such thing as an enum in XML Schema,
    and XML Schema is what is used to communicate type information from server
    to client via the WSDL.

    There is an xs:enumeration facet in XML schema, but it doesn't quite produce
    the same thing as an enum in C#. Instead, it "enumerates" the set of
    possible values for a type. It does not then associate a name with each
    possible value.

    One might manage some magic with schema importer extensions, but this would
    only work for .NET clients. Note in particular, that not all languages have
    the concept of an "enum".

    John
    John Saunders, Mar 9, 2007
    #3
  4. Guest

    Thanks for the reply. I'm having trouble figuring out how to apply the
    XmlEnumAttribute. Here's what I tried, but neither worked:

    public enum myEnum
    {
    [System.Xml.Serialization.XmlEnumAttribute]
    ONE = 1,
    [System.Xml.Serialization.XmlEnumAttribute]
    TWO = 2,
    }

    I also tried:
    [System.Xml.Serialization.XmlEnumAttribute]
    public enum myEnum
    {
    ONE = 1,
    TWO = 2,
    }

    Thanks for any and all help.

    On Mar 9, 9:47 am, "Mariano Omar Rodriguez" <>
    wrote:
    > Apply the Attribute XmlEnumAttribute for each option of the enumearion.
    >
    > <> wrote in message
    >
    > news:...
    >
    > >I building a web service that has an enum I want the consuming
    > > application to be able to use.

    >
    > > I have the enum declared in the web service as:
    > > public enum myEnum
    > > {
    > > ONE = 1,
    > > TWO = 2,
    > > };

    >
    > > I want to be able to access these from the consuming application such
    > > as: myConsumer.localhost.myEnum.ONE. However, I can't seem to get it
    > > to work. How do I make this visible/export this enum to the consumer?
    > > I would rather not duplicate the code. Thanks for any and all help.
    , Mar 9, 2007
    #4
  5. Guest

    What would be the best way to share a bunch on constants (these are
    preprocessor macros for a native DLL) between a web service and it's
    consumer? Please include some C# code samples because I'm a newbie.
    Thanks for the help.

    On Mar 9, 10:17 am, "John Saunders" <john.saunders at trizetto.com>
    wrote:
    > "Mariano Omar Rodriguez" <> wrote in messagenews:...
    >
    > > Apply the AttributeXmlEnumAttributefor each option of the enumearion.

    >
    > I don't believe that this will permit the client to treat the type as an
    > "enum". The reason is that there is no such thing as an enum in XML Schema,
    > and XML Schema is what is used to communicate type information from server
    > to client via the WSDL.
    >
    > There is an xs:enumeration facet in XML schema, but it doesn't quite produce
    > the same thing as an enum in C#. Instead, it "enumerates" the set of
    > possible values for a type. It does not then associate a name with each
    > possible value.
    >
    > One might manage some magic with schema importer extensions, but this would
    > only work for .NET clients. Note in particular, that not all languages have
    > the concept of an "enum".
    >
    > John
    , Mar 9, 2007
    #5
  6. Green Mellon Guest

    On Mar 9, 2:23 pm, wrote:
    > What would be the best way to share a bunch on constants (these are
    > preprocessor macros for a native DLL) between a web service and it's
    > consumer? Please include some C# code samples because I'm a newbie.
    > Thanks for the help.
    >
    > On Mar 9, 10:17 am, "John Saunders" <john.saunders at trizetto.com>
    > wrote:
    >
    > > "Mariano Omar Rodriguez" <> wrote in messagenews:...

    >
    > > > Apply the AttributeXmlEnumAttributefor each option of the enumearion.

    >
    > > I don't believe that this will permit the client to treat the type as an
    > > "enum". The reason is that there is no such thing as an enum in XML Schema,
    > > and XML Schema is what is used to communicate type information from server
    > > to client via the WSDL.

    >
    > > There is an xs:enumeration facet in XML schema, but it doesn't quite produce
    > > the same thing as an enum in C#. Instead, it "enumerates" the set of
    > > possible values for a type. It does not then associate a name with each
    > > possible value.

    >
    > > One might manage some magic with schema importer extensions, but this would
    > > only work for .NET clients. Note in particular, that not all languages have
    > > the concept of an "enum".

    >
    > > John


    First of all, if I understand your problem, you need the client to
    know *the values* of the enum members. The *list* of enum members is
    exported to the client just declaring a parameter of this type in any
    of the methods in the WebService.
    Now, to the point...
    I've had problems like this in an application that I was developing a
    while ago. After unsuccessfully trying to export those values to the
    client, I finally took the decision to review my objectives. The
    point is: Why do you want to export those values to the client as an
    enum?
    If the values are hardly related: They must be in separated constants.
    If you want the client to use those values when it invokes some of
    your methods, change the type of the arguments of those methods to the
    enum type, so you get rid of values (enums are correctly published to
    the client, then, but without the associated values).
    If you want the client to use those values for itself you can export
    an enum and a method who translates enums to values. Here is a sample
    code:

    ....
    public enum myEnum
    {
    ONE = 1,
    TWO = 2,
    }

    [WebMethod]
    public int getEnumValue(myEnum e)
    {
    return (int)e;
    }
    ....

    I know the performance issues that this approach has but I couldn't
    figure out a better way to do it yet.
    Green Mellon, Mar 9, 2007
    #6
  7. "John Saunders" <john.saunders at trizetto.com> wrote in message
    news:%...
    > "Mariano Omar Rodriguez" <> wrote in message
    > news:...
    >> Apply the Attribute XmlEnumAttribute for each option of the enumearion.
    >>

    >
    > I don't believe that this will permit the client to treat the type as an
    > "enum". The reason is that there is no such thing as an enum in XML
    > Schema, and XML Schema is what is used to communicate type information
    > from server to client via the WSDL.


    Ok, I take back part of this.

    If you have an enum type like this:

    public enum MyEnum
    {
    One = 1,
    Two = 2
    }

    Then this will be translated into the following XML Schema type:

    <s:simpleType name="MyEnum">
    <s:restriction base="s:string">
    <s:enumeration value="One" />
    <s:enumeration value="Two" />
    </s:restriction>
    </s:simpleType>

    This will cause the following client proxy to be created:

    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml",
    "2.0.50727.42")]
    [System.SerializableAttribute()]
    [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://tempuri.org/")]
    public enum MyEnum {
    /// <remarks/>
    One,
    /// <remarks/>
    Two,
    }

    Note that the integer value of "One" on the client is zero.

    The reason that I didn't think this would work is that the web services I've
    recently created couldn't simply use s:restriction base="string". They had
    to use s:restriction base="s:int".

    Note that you can get some interesting effects when your <s:enumeration>
    values are not valid .NET identifiers. For instance, an enum member with
    value "a b c" gets the name "abc" on the client:

    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml",
    "2.0.50727.42")]
    [System.SerializableAttribute()]
    [System.Xml.Serialization.XmlTypeAttribute(Namespace="urn:customerSpecific.types.umcase.um.cca.webservices.trizetto.com")]
    public enum aaTesting {
    /// <remarks/>
    [System.Xml.Serialization.XmlEnumAttribute("a b c")]
    abc,
    /// <remarks/>
    [System.Xml.Serialization.XmlEnumAttribute("d e f")]
    def,
    }

    John
    John Saunders, Mar 9, 2007
    #7
    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. Lord0
    Replies:
    0
    Views:
    385
    Lord0
    Feb 19, 2007
  2. John Lau
    Replies:
    0
    Views:
    184
    John Lau
    Sep 13, 2004
  3. John Smith

    How-to find IP address of a web service consumer?

    John Smith, Jan 30, 2004, in forum: ASP .Net Web Services
    Replies:
    1
    Views:
    202
    Jan Tielens
    Jan 30, 2004
  4. tooniron

    Web Service Consumer Deployment Problem

    tooniron, Feb 4, 2004, in forum: ASP .Net Web Services
    Replies:
    4
    Views:
    119
    tooniron
    Feb 5, 2004
  5. Michael Fan
    Replies:
    2
    Views:
    132
    Michael Fan
    Jul 16, 2004
Loading...

Share This Page