Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

C# Webservices Enum default value overide ignored

Posted on 2009-04-03
2
Medium Priority
?
1,090 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:Charles Baldo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 14

Accepted Solution

by:
jjardine earned 2000 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:Charles Baldo
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

Automating Your MSP Business

The road to profitability.
Delivering superior services is key to ensuring customer satisfaction and the consequent long-term relationships that enable MSPs to lock in predictable, recurring revenue. What's the best way to deliver superior service? One word: automation.

Question has a verified solution.

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

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

660 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