Chathuranga Chandrasekara
Chathuranga Chandrasekara

Reputation: 20956

Is this a namespacing problem?

I am experiencing a strange behavior with very basic web service development. This question might be dumb but I think someone would be able to explain this observation.

I am developing a web service with a web method, MyWebMethod

MyWebMethod(MyEnum Param, .....)

Where,

public enum MyEnum : int
    {
       Type_1 =1;
       Type_2 =2;
       Type_3 =3;
    }

Now I am using my client to communicate with this service but for every request type, Type_1, Type_2 etc the service captures it as Type_1. As an example, if I create a break point at MyWebMethod in my web service, I see Type_1 as param1 type. I guess this is a problem with Namespacing. I cannot see any other defects on the code. Any Idea based on the experiences?

Upvotes: 1

Views: 115

Answers (3)

RameshVel
RameshVel

Reputation: 65877

When enum is serialized, only its string representation is transferred through wire (names), not the values. I believe thats the reason you are getting the wrong values.

Check out this 2 articles for more info

  1. WebServices_and_Enums
  2. Using enum in web service parameter

Upvotes: 2

Perpetualcoder
Perpetualcoder

Reputation: 13591

I guess your enum does not need to inherit from int. You are providing name and value in the enumeration, that should suffice. I am assuming all your code is .NET 2.0. As test , return an enumeration value from the webservice. Just to make sure XML Serialization is working as expected when the service is hit directly by the browser.

Upvotes: 0

Darin Dimitrov
Darin Dimitrov

Reputation: 1039368

If this is a WCF web service and a .NET 2.0 client generated with wsdl.exe for each value type in the method signature there will be a boolean parameter added called XXXSpecified which you need to set to true. Check this blog post for more details.

Upvotes: 0

Related Questions