Solved

C# Webservices Enum default value overide ignored

Posted on 2009-04-03
2
1,059 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

To properly understand GitHub, let’s divide it into two words ‘Git’ and ‘Hub’. Git is basically a ‘Distribution Version Control’ (DVC) and ‘Source Code Management’ (SCM) system widely used by software programmers while Hub means the efficient centre…
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 …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

705 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

18 Experts available now in Live!

Get 1:1 Help Now