all groups > asp.net webservices > september 2007 >
You're in the

asp.net webservices

group:

Problem using enum as web method parameter


Problem using enum as web method parameter Ren
9/25/2007 3:07:16 PM
asp.net webservices:
Hello all,

I am trying to localize some of the web methods in my web service so
I've created an enum in my web service of the allowed languages:

public enum Language
english
french
end enum

The first parameter in my new web methods is of the type "language".
On my client side if I pass either "english" or "french" everything is
fine, however if I leave the parameter blank I receive the error:

Cannot convert to WebService.Service+Language.
Parameter name: type --> Must specify valid information for parsing in
the string.

Is there anyway that I can accept either a blank (null) or an enum
value for this parameter without throwing this error if the value is
blank? I'd like to be able to default the language to english if no
language is specified.

thanks for you help

Re: Problem using enum as web method parameter John Saunders [MVP]
9/25/2007 3:15:47 PM
[quoted text, click to view]

Could you do that in VB? Is blank or null a valid value for your enum?

If you're using .NET 2.0, you could try using a nullable type for your
parameter. It would be of type Nullable(Of Language).
--
--------------------------------------------------------------------------------
John Saunders | MVP - Windows Server System - Connected System Developer
Re: Problem using enum as web method parameter Ren
9/26/2007 3:20:04 PM
On Tue, 25 Sep 2007 15:15:47 -0400, "John Saunders [MVP]"
[quoted text, click to view]


Hi John, thanks for your reply. I should have specified that I'm
still using version 1.1 of the framework and coding in VB. I'm not
sure how to specify blank as a valid value in my enum since "" is an
invalid value. I'd like to specify both "" (blank) and Nothing as
valid values in the enum but don't think that's possible.

I suppose that I could try and enclose the enum in a wrapper class.
I'm coming to the conclusion that an enum is probably not the best way
Re: Problem using enum as web method parameter John Saunders [MVP]
9/26/2007 7:05:57 PM
[quoted text, click to view]

My point was that, since you can't use blank or null as a value for an enum
in VB, it doesn't make sense to try to do that in a web service.
--
--------------------------------------------------------------------------------
John Saunders | MVP - Windows Server System - Connected System Developer
Re: Problem using enum as web method parameter Ren
9/28/2007 12:29:36 PM
On Wed, 26 Sep 2007 19:05:57 -0400, "John Saunders [MVP]"
[quoted text, click to view]

<snip>
[quoted text, click to view]

Thanks for the clarification John. What would be the best way to
implement this then, if I want to have only the options "english,
french, blank/nothing" shown in the wsdl? Thanks for your patiance,
Re: Problem using enum as web method parameter John Saunders [MVP]
9/28/2007 1:16:44 PM
[quoted text, click to view]

In the schema, define the element as a simple type, restriction of
xs:token, with enumerations of "english" and "french", and with a
minLength=0. If the element is also minOccurs=0, that should take care of
it.
--
--------------------------------------------------------------------------------
John Saunders | MVP - Windows Server System - Connected System Developer
AddThis Social Bookmark Button