Solved

C# Webservices Enum default value overide ignored

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The task of choosing a web design company to build a website for your business should never be taken in a light manner. Provided the fact that your website will act as a representative to your business and will be responsible for imposing an online …
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to dynamically set the form action using jQuery.

830 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