Solved

C# Webservices Enum default value overide ignored

Posted on 2009-04-03
2
1,061 Views
Last Modified: 2013-11-18
Hello I have the following enum in a class that is used in a web service

    public enum Genders
    {
      Male = 1,
      Female = 2
    }

When I reference the webservice in a c# winform I get an error if I instantiate a class that is referenced to that web sevice
 profile p = new profile();
 p.Gender = (Genders)2;

When I run the code I get "There was an error generating the XML document." the stack trace goes back to the Reference.cs file. Sure enough in the reference I have code that looks like this

    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "2.0.50727.1433")]
    [System.SerializableAttribute()]
    [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://xxxxxxxx.net/")]
    public enum Genders {
       
        /// <remarks/>
        Male,
       
        /// <remarks/>
        Female,
    }

So it is being cause by the local reference reseting the default back to 0 when it generates. If I go in and manually change the code in the reference.cs to

    public enum Genders {
       
        /// <remarks/>
        Male=1,
       
        /// <remarks/>
        Female=2,
    }

it works. However i can not do that because when it autogenerates it wipes my changes out as soon as I update the web reference.  

Any Ideas why this is happening and what I can do to fix it?
0
Comment
Question by:charlesbaldo
2 Comments
 
LVL 14

Accepted Solution

by:
jjardine earned 500 total points
ID: 24065831
May be a bug in the way the proxies are generated or that the proxies just don't look at the actual value, they just create the enum.   I am assuming you are using visual studio 2005 for this.  I have run into other issues where modifying the reference.cs was the only way to get the solution to work.  It is a pain to do, but does get the job done.  If anyone has a better solution, I would like to hear it.   Relying on modifying that file is not very stable, forcing you to remember to go in and update it each time you update your reference.
0
 

Author Closing Comment

by:charlesbaldo
ID: 31566509
I am actually using 2008 but its a RTM version and I was suspecting the same thing. I think I may abandon starting at 1 and just go with the defalt and start at zero.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The viewer will learn how to count occurrences of each item in an array.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now