WCF / ASMX :: How To Serialize Enum To Its Value
Feb 12, 2011
I am facing an critical problem in Enum serialization in WCF. Here is the scenario: I have an enum like this...
[Serializable] [DataContract(Namespace = "http://www.geniusdoc.portal.com/serivces/2011/v1/GdService", Name = "AppointmentMode")] public enum AppointmentMode : int { // 1: Email, 2: Phone [EnumMember(Value = "1")] None = 1, [EnumMember(Value = "2")] Email = 2, [EnumMember(Value = "3")] Phone = 3 }
Here I decorated each enum value with [EnumMember], so that I can use the Enum as Data Contract in WCF.
And, AppointmentMode will be saved as INTEGER in database. So I need to serialize this Enum to its value. So I have specified value to each member like... [EnumMember(Value = "1")]
Problems:
If I use the above code as it is...SvcUtil not considering Enum Text, and generating the Enum in Proxy as below...
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")] [System.Runtime.Serialization.DataContractAttribute(Name="AppointmentMode", Namespace="http://www.geniusdoc.portal.com/serivces/2011/v1/GdService")] public enum AppointmentMode: int { [System.Runtime.Serialization.EnumMemberAttribute(Value="1")] _1 = 1, [System.Runtime.Serialization.EnumMemberAttribute(Value="2")] _2 = 2, [System.Runtime.Serialization.EnumMemberAttribute(Value="3")] _3 = 3, }
If I remove the Value from [EnumMember(Value = "1")], while deserialization is considering Enum Text, and giving results as below
<AppointmentMode>None</AppointmentMode>
Expected result:
1. Enum in the Client proxy should be same original Enum.
2. Enum Deserialization should consider EnumValue, such a way that it will return
<AppointmentMode>1</AppointmentMode>
How to get this done?
View 5 Replies
Similar Messages:
Jun 18, 2010
Let's say I have a function that takes a string. That string contains the fully name of an enum type (e.g. "MyCompany.Area.AotherNamespace.MyEnum").
How could I create an array of strings (or List<string>) whose elements are the values of MyCompany.Area.AotherNamespace.MyEnum?
Is that even possible?I'm basically trying to serialize an enum type serverside and then output it in clientside JavaScript so I don't have to define an enum in two places--in my C# and my JavaScript.
View 1 Replies
Feb 8, 2011
i am generating a wcf data contract from a schema, using svcutil /d: option, however the enum of type xsd:int in schema is generating all the values as ints, with underscores, obviously to make valid code. How can i get the actual value of 1000
E.g Enum Impact with values 1000,2000,3000 generates code
public enum Impact : int
{
[System.Runtime.Serialization.EnumMemberAttribute(Value = "1000")]
_1000 = 1,
[System.Runtime.Serialization.EnumMemberAttribute(Value = "2000")]
_2000 = 2,
[System.Runtime.Serialization.EnumMemberAttribute(Value = "3000")]
_3000 = 3
}
View 2 Replies
Apr 30, 2010
I have a webmethod that has three parameters:
public AuthenticationResult Authenticate(Enum type, string userName, string password) But the problem I had is that if a null/invalid enum is entered for the type variable it throws an error message.
So the obvious solution is to use a string/int instead but I am cannot do this as current users already use the existing webmethod.
So i was thinking:
public AuthenticationResult Authenticate(object type, string userName, string password) and handling the casting myself but the problem I had with this is that now my users do not have access to the Enum type.
So my question is can I publish the enum type without having it as a parameter/return value? Allow the client to access the Enum so they can pass it into the method. Would using a method that returned a type that was my enum work? Or is there a way to catch this custom error: (I dont think so as it appears to be on the client end when converting Enum to xml). The error is: (System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidOperationException: Instance validation error: '45465' is not a valid value for Enum.)
View 1 Replies
Sep 28, 2010
whats wrong with this code, i try also Enum.Parse but didnt work.
public enum RoleNames
{
Administrator,
[code]...
View 1 Replies
May 25, 2010
We are developing SOA based application using .NET 3.5 and WCF & WPF.
One common issue we are facing is mapping between WCF enum and WPF enums. We had to do mapping between WCF enums to WPF enums. Following is sample code
Switch(WCFServiceObject.Status)
{
Case WCFServiceStatus.Married[code]....
You can see that we have to do mapping WPF and WCF enums. Is there any easiest way to achieve this mapping without writing tedious switch statements? One way of doing this is using Dictionary, but apart from this, is there any good way? We have lots of enums for which have to do mappings.
View 1 Replies
Jan 25, 2010
Im using DataTable to write some XML. but i got Serialization problem. when i try write i got error message, your datatable is not serialize.(i dont want use DataSet)How i Serialize DataTable?
View 2 Replies
Mar 31, 2011
I'm trying to serialize a Request object for logging purposes. The code
System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(obj.GetType());
// obj is a Request object
gives me the following exception:To be XML serializable, types which inherit from ICollection must have an implementation of Add(System.String) at all levels of their inheritance hierarchy. System.Web.HttpValueCollection does not implement Add(System.String).
View 2 Replies
Jan 23, 2010
i have tables like Lookup and lookupvalues in the lookup table like and lookup values like
LookupId LookupName | lookupValueId lookupId Name
1 Country | 1 1 Usa (country)
2 State | 2 2 All(state)
3 Relation | 3 2 Colarado (state)
4 3 agenttoClient(relation)
now i want create enum class form databse
my req is
enum lookup{
Country,state,Relation(these should be come from Databse when ever application intialised)
}
now i able acces lookupvalues
lookup.country.1=>USa
lookup.State.1=>All
lookup.State.2=>Colorado
lookup.Relation.1=>Agent to client
View 1 Replies
Apr 28, 2010
i am fresher, so i want to learn Enum deeply.
What is enum, when to use it and why to use it?
Because i want to clear from basic. Infact i want to become my basic concepts strong in OOPS, Collections.
View 4 Replies
Oct 6, 2010
I know this is asking alot...and as far as I know there is no way to do this..but I still tought that I whould ask you guys if you might some how figured this one out. The thing is that I have a database-table that contains information about different user-roles...and I whould like to retrive each roles-name in an enum..and as the data changes in teh table I whould like the enum to change aswell...and I also whould like
it to be possible to actually get intellisense once trying to access the enum..
I have looked at the following link and sulotion:[URL] The problem with that as far as I have understod, is that I dont get the intellisense and the code kind of gets even harder to understand...since the whole point with enums is to make the code easy to understand..atleast as far as I know.
View 5 Replies
Aug 31, 2010
i need to display the name of enum in gridview by data table returns its numeric value
i am using this for other columns
<asp:BoundField DataField="Name" HeaderText="User Name" />
i need to use it for enum to display the string value of enum Gender
<asp:BoundField DataField="Gender" HeaderText="Gender" />
View 1 Replies
Feb 9, 2011
I'd like to mimic the behavior of the "profile provider" that is available in .Net. The profile provider acquires profile properties from the web.config and those properties are immediately available as an enum for use in the code behind.I'm unsure how to do this, and wondered whether someone may be able to help.Essentially I'd like to allow developers to enter Role information into the web.config, and then have this role information available for use within an enum in the codebehind.
View 2 Replies
Mar 23, 2010
how we can serialize a datareader in webservices.
View 1 Replies
Mar 20, 2010
How to serialize the DataReader in webservices in asp.net?
View 4 Replies
Jun 14, 2010
I have a shared object through net remoting. The problem is that this object has some EntitySet and EntityRef attributes. When I try to run the program I get an exception telling me that EntitySet is not marked as Serializable. If I mark it as Serializable everything seems to be ok, but when I try to access from outsied to the attribute represented by the EntitySet, I am not able to use it.
BTW, Does anyone know how change the default binary serialization of tcp channel?
View 3 Replies
Jun 21, 2010
I have no problem getting a custom profile class to work as it should in Asp.Net MVC 2, C# -- as long as I am content that the profile info is serialized as xml.The question is how to get it to serialize as Binary, rather than xml -- Is that possible?in the web.config...
<profile defaultProvider="MIProvider" inherits="Models.MbrProfile" automaticSaveEnabled="false">
<providers>
<clear />
<add name="MIProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="MIconnect" applicationName="myApp" />
[code]...
View 2 Replies
Oct 13, 2010
Type 'System.Data.Linq.ChangeTracker+StandardChangeTracker' in Assembly 'System.Data.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable
have read all threads but still cant solve the error. I can do insert update and delete but dont know where exactly the error occurs and how??
View 1 Replies
Oct 21, 2010
i need to serialize and deserialize an image for my project. i have been googling it for a few days but i cannot find any VB codes related to image serialization... can someone give me some hints on how i should start?? for my program, i need to save the image to sql database and then i need to retrieve all the image for my product catalog
View 2 Replies
Jun 23, 2010
If have the following enum
public enum EmployeeType
{
Manager = 1,
TeamLeader,
Senior,
Junior
}
and i have DropDownList and i want to bind this enum to it .. is it any way to do that ?
View 1 Replies
Mar 22, 2011
I want to add the below values from Enum to drop down list
<option value="0">-- Select --</option>
<option value="AC">Active</option>
<option value="IN">InActive</option>
<option value="PC">Pending Closure</option>
View 2 Replies
Jan 22, 2010
Can we access an enum which has been defined in the master page. I read about the master page on [URL]
View 1 Replies
Mar 14, 2010
I have a class that contains an enum property, and upon serializing the object using JavaScriptSerializer, my json result contains the integer value of the enumeration rather than its string "name". Is there a way to get the enum as a string in my json without having to create a custom JavaScriptConverter? Perhaps there's an attribute that I could decorate the enum definition, or object property, with?As an example:
enum Gender { Male, Female }
class Person
{
[code]...
View 2 Replies
Apr 26, 2010
I would like someone to explain how I can pass a drop down list from the presentation layer to the controller using the Model View Controller Design Pattern from Microsoft in order to bind enum values to it?
View 2 Replies
Mar 17, 2011
I have a linqdatasource and I want to use an enum for Type as below:
<asp:linqdatasource id="GridDataSource" runat="server" enabledelete="true" Where="Type == @Type">
<whereparameters>
<asp:dynamiccontrolparameter controlid="FilterRepeater" />
<asp:QueryStringParameter QueryStringField="Type" Name="Type" ConvertEmptyStringToNull="false" />
</whereparameters>
</asp:linqdatasource>
It keeps throwing an error:
Operator '==' incompatible with operand types 'ProductType' and 'String' ProductType is my Enum, and String is my input type. I don't seem to be able to convert one to the other.
View 2 Replies