Enum Problems

O

Oldman

I have an enum being passed into one of my webservice methods.
The actual enum is defined as follows:

[pre]
public enum StatusType
{
SPECIAL_1 = -2,
SPECIAL_2 = -1,
ENUM1 = 1,
ENUM2,
ENUM3,
ENUM4
}
[/pre]

The issue is that this is created in the proxy class like this:

[pre]
public enum StatusType
{
SPECIAL_1,
SPECIAL_2,
ENUM1,
ENUM2,
ENUM3,
ENUM4
}
[/pre]

So when the client passes up ENUM4 the web service thinks it has ENUM2.
Is there are way to fix this?

Thanks,

Chris
 
M

Martin.Kunc

Hallo Oldman,
I was confused, so I have tried this one out. In fact, when you are
passing enum types - during wsdl and everywhere on its way it is passed
as string (complex string type with restriction). So it does not matter
what enumeration id you assign them, you are allways passing enum's
item name.
I suppose, here in your case could be any other mistake before you pass
this enum type to webservice.

**I have used this client for my tests:
static void Main(string[] args) {
localhost.Service ss = new EnumType_WSTesting.localhost.Service();
localhost.StatusType st;
foreach (string s in Enum.GetNames(typeof(localhost.StatusType))) {
Console.WriteLine(
ss.HelloWorld(
(localhost.StatusType)Enum.Parse(typeof(localhost.StatusType),
s),
out st)
);
Console.WriteLine(string.Format(" out st: {0}",st));
}
Console.ReadKey();
}
**And this code as webservice:
public enum StatusType
{
SPECIAL_1 = -2,
SPECIAL_2 = -1,
ENUM1 = 1,
ENUM2,
¨ ENUM3,
ENUM4
}
[WebMethod]
public string HelloWorld(StatusType stin, out StatusType stout) {
stout = stin;
return stin.ToString();
}
 
O

Oldman

I have read the same thing but try it out. If you pass up a status type from
the client to the server you get the behavior I described. I have not had
problems passing back statuses from the server to client.

However, I seemed to have fixed my problem by adding XmlEnum attributes to
the Enum. I will dig into this some more but let me know if you can
reproduce the problem I described.

Thanks,

Chris

Hallo Oldman,
I was confused, so I have tried this one out. In fact, when you are
passing enum types - during wsdl and everywhere on its way it is passed
as string (complex string type with restriction). So it does not matter
what enumeration id you assign them, you are allways passing enum's
item name.
I suppose, here in your case could be any other mistake before you pass
this enum type to webservice.

**I have used this client for my tests:
static void Main(string[] args) {
localhost.Service ss = new EnumType_WSTesting.localhost.Service();
localhost.StatusType st;
foreach (string s in Enum.GetNames(typeof(localhost.StatusType))) {
Console.WriteLine(
ss.HelloWorld(
(localhost.StatusType)Enum.Parse(typeof(localhost.StatusType),
s),
out st)
);
Console.WriteLine(string.Format(" out st: {0}",st));
}
Console.ReadKey();
}
**And this code as webservice:
public enum StatusType
{
SPECIAL_1 = -2,
SPECIAL_2 = -1,
ENUM1 = 1,
ENUM2,
¨ ENUM3,
ENUM4
}
[WebMethod]
public string HelloWorld(StatusType stin, out StatusType stout) {
stout = stin;
return stin.ToString();
}
---
enjoy, Martin
I have an enum being passed into one of my webservice methods.
The actual enum is defined as follows:

[pre]
public enum StatusType
{
SPECIAL_1 = -2,
SPECIAL_2 = -1,
ENUM1 = 1,
ENUM2,
ENUM3,
ENUM4
}
[/pre]

The issue is that this is created in the proxy class like this:

[pre]
public enum StatusType
{
SPECIAL_1,
SPECIAL_2,
ENUM1,
ENUM2,
ENUM3,
ENUM4
}
[/pre]

So when the client passes up ENUM4 the web service thinks it has ENUM2.
Is there are way to fix this?

Thanks,

Chris
 
O

Oldman

Whoops, sorry I looked at your example again and noticed you are passing up a
status from the client. The first time I looked at it I just saw the out
parameter.
Hmm. Ok, I'll dig deeper.

Thanks,

Chris

Hallo Oldman,
I was confused, so I have tried this one out. In fact, when you are
passing enum types - during wsdl and everywhere on its way it is passed
as string (complex string type with restriction). So it does not matter
what enumeration id you assign them, you are allways passing enum's
item name.
I suppose, here in your case could be any other mistake before you pass
this enum type to webservice.

**I have used this client for my tests:
static void Main(string[] args) {
localhost.Service ss = new EnumType_WSTesting.localhost.Service();
localhost.StatusType st;
foreach (string s in Enum.GetNames(typeof(localhost.StatusType))) {
Console.WriteLine(
ss.HelloWorld(
(localhost.StatusType)Enum.Parse(typeof(localhost.StatusType),
s),
out st)
);
Console.WriteLine(string.Format(" out st: {0}",st));
}
Console.ReadKey();
}
**And this code as webservice:
public enum StatusType
{
SPECIAL_1 = -2,
SPECIAL_2 = -1,
ENUM1 = 1,
ENUM2,
¨ ENUM3,
ENUM4
}
[WebMethod]
public string HelloWorld(StatusType stin, out StatusType stout) {
stout = stin;
return stin.ToString();
}
---
enjoy, Martin
I have an enum being passed into one of my webservice methods.
The actual enum is defined as follows:

[pre]
public enum StatusType
{
SPECIAL_1 = -2,
SPECIAL_2 = -1,
ENUM1 = 1,
ENUM2,
ENUM3,
ENUM4
}
[/pre]

The issue is that this is created in the proxy class like this:

[pre]
public enum StatusType
{
SPECIAL_1,
SPECIAL_2,
ENUM1,
ENUM2,
ENUM3,
ENUM4
}
[/pre]

So when the client passes up ENUM4 the web service thinks it has ENUM2.
Is there are way to fix this?

Thanks,

Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top