Web service returning enumerated type

Web service returning enumerated type

Post by Um9i » Tue, 02 Nov 2004 21:30:04


Hi,

I have defined an enumeration thus:

Public Enum CollectionDayOfWeek
NoCollectionDay = -1
Sunday = DayOfWeek.Sunday
Monday = DayOfWeek.Monday
Tuesday = DayOfWeek.Tuesday
Wednesday = DayOfWeek.Wednesday
Thursday = DayOfWeek.Thursday
Friday = DayOfWeek.Friday
Saturday = DayOfWeek.Saturday
End Enum

I have a web service which returns a value of this type.

Now when I run wsdl to create my proxy, the enumeration loses its
initializers so that NoCollectionDay = 0, Sunday = 1, etc.

Can I do anything to correct this behaviour? Or am I better off not setting
initializers on my enumerations when writing web services?

Thanks,

Rob
 
 
 

Web service returning enumerated type

Post by Martin Kul » Fri, 05 Nov 2004 22:15:11

Hi Rob,

Since web services are using xml/soap it is better the data that you pass through to be human readable. The purpose is not to be just read by humans, but to maintain compatibility in the future. So if I were you I would implement it returning the strings themselves. The enum type even has a GetName method that does the exact thing.

Best regards,
Martin Kulov
www.codeattest.com

 
 
 

Web service returning enumerated type

Post by Um9i » Sat, 06 Nov 2004 02:29:05

Hi Martin,
Thanks for the reply. Yes looking at the WSDL for my web service I can see
that my enumeration is described in text only. As you say I guess that I am
limited to returning either the string itself or not attempting any form of
initialization.

The reason I noticed this is that in my proxy I attempted to convert the day
to a DayOfWeek type and noticed that Wednesday became Tuesday. If I want to
do this sort of conversion then I am best doing it through the name of the
value.

Regards,

Rob
 
 
 

Web service returning enumerated type

Post by Martin Kul » Sat, 06 Nov 2004 06:15:29

Hi Rob,
I do not know how Wednesday became Thursday. May be it is some time zone issue. How did you convert DayOfWeek type?
IMHO DayOfWeek.Friday.ToString() should always return Friday.

Regards,
Martin
 
 
 

Web service returning enumerated type

Post by Um9i » Sat, 06 Nov 2004 20:27:03

Hi Martin,
Sorry - I wasn't very clear in my last post.

In my web service my enumeration is defined as follows

Public Enum CollectionDayOfWeek
NoCollectionDay = -1

End Enum
 
 
 

Web service returning enumerated type

Post by Um9i » Sat, 06 Nov 2004 20:32:02

Last post was mangled...

My enumeration in the web service is defined as

Public Enum CollectionDayOfWeek
NoCollectionDay = -1
Sunday = DayOfWeek.Sunday
Monday = DayOfWeek.Monday
etc
End Enum


My proxy does not have the initializers so the enumeration here is
(Parentheses are mine)

Public Enum CollectionDayOfWeek
NoCollectionDay (=0)
Sunday (=1)
Monday (=2)
etc
End Enum

So if in my client I have a variable of type CollectionDayOfWeek and cast it
to DayOfWeek as follows
CType(var, DayOfWeek) then Sunday becomes Monday, Monday becomes Tuesday etc.

I agree though that my approach is flawed - I just wanted to explain how I
noticed that I had a problem in the first place.

Regards,

Rob