17003

Flex, .NET Web Service and Numeric Enums

Question:

We're using Flex 3 to consume a .NET Web Service. The web service uses an enum and we use Flex Builder to automatically generate the web service objects. Here is the .NET web service enum definition:

/// <summary>    /// User type    /// </summary>    public enum UserTypeEnum    {        Admin = 1,        User = 3,        Manager = 4    }

When Flex generates the web service objects, it treats them as strings instead of integer values.

[Inspectable(category="Generated values", enumeration="Admin, User, Manager", type="String")] public var _UserTypeEnum:String;public function toString():String { return _UserTypeEnum.toString(); }

When we get data from the web service, any property that uses this enumeration is Null instead of 'admin' or '1'. Is there any way to make this work?

Answer1:

Be aware that there are issues with enumerations and web services.

See this <a href="https://stackoverflow.com/questions/505617/flags-with-web-services/505628#505628" rel="nofollow">question</a>.

<ul><li>Should be using [Serializable,Flags] in web service.</li> <li>Flags should be multiples of two</li> <li>The enumeration definition should start from 1 rather than 0.</li> </ul>

Answer2:

<a href="http://www.google.com/search?hl=en&safe=off&rlz=1T4HPIA_en&q=+site:bugs.adobe.com+FLEX+wsdl+enum" rel="nofollow">There are some bugs listed at Adobe re: Flex 3 and enum's in WSDL</a> .. Are you sure you have the latest update ?

Answer3:

In the languages derived from C (C#, C++, Java), an enum is effectively a set of named integral values.

There is no corresponding concept in XML Schema, therefore there is no such concept in web services.

Before you or anyone else mentions the <xs:enumeration/> facet, that's not what it's for. <xs:enumeration/> provides a list (an enumeration) of the possible lexical values for a type. There is no way to associate numbers with those lexical values. The following enum:

public enum Enumeration1 { E1a = 1, E1b = 2, E1c = 4 }

becomes the following XML Schema:

<s:simpleType name="Enumeration1"> <s:restriction base="s:string"> <s:enumeration value="E1a"/> <s:enumeration value="E1b"/> <s:enumeration value="E1c"/> </s:restriction> </s:simpleType>

Note the absence of 1, 2, or 4.

All this says is that an element or attribute of this type will be a string, and may have one of the values "E1a", "E1b", or "E1c".

If a client proxy is built from a WSDL with such schema, and if the proxy code generator is smart enough, it may decide that this was originally a programming language enum. In this case, it would create the type as

public enum Enumeration1 { E1a, E1b, E1c }

Since it has no access to the integers.

Recommend

  • DocumentDB Query Requires Unexpected High RUs
  • Comparing two Strings s = “ja”.concat(“va”); and s1=s.intern(); with == operator returns false. Why?
  • Take one table values and insert it into another Table
  • Debugging web apps added to home screen on iOS Safari
  • Creating a multiline label inside a custom togglebuttonbar
  • Figure title with several colors in matplotlib
  • FormData ajax to php
  • Use Sheet Name as a Loop Parameter
  • Django Form Showing No Input Fields
  • When I instantiate a class in PHP, do I get a pointer to the object?
  • Bar chart in seaborn
  • Filter Values of Current Week with XQuery
  • Scrolling News Ticker Jquery - Issues
  • Using extern @class in order to add a category?
  • “A GKScore must specify a leaderboard.”
  • Database structure design with variable amounts of fields
  • How do I fake an specific browser client when using Java's Net library?
  • How to get a value (ex: baseURL) in every Karate feature?
  • Javascript convert timezone issue
  • How to delete a row from a dynamic generate table using jquery?
  • KeystoneJS: Relationships in Admin UI not updating
  • using HTMLImports.whenReady not working in chrome
  • FormattedException instead of throw new Exception(string.Format(…)) in .NET
  • embed rChart in Markdown
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • Authorize attributes not working in MVC 4
  • apache spark aggregate function using min value
  • EntityFramework adding new object to nested object collection
  • Is there any way to bind data to data.frame by some index?
  • Checking variable from a different class in C#
  • Django query for large number of relationships
  • How to get NHibernate ISession to cache entity not retrieved by primary key
  • Why is Django giving me: 'first_name' is an invalid keyword argument for this function?
  • Binding checkboxes to object values in AngularJs
  • How can I use `wmic` in a Windows PE script?
  • Unable to use reactive element in my shiny app
  • Net Present Value in Excel for Grouped Recurring CF
  • How to push additional view controllers onto NavigationController but keep the TabBar?
  • jQuery Masonry / Isotope and fluid images: Momentary overlap on window resize
  • How to load view controller without button in storyboard?