Fog Creek Software
Discussion Board

Welcome! and rules

Joel on Software

Constant Equivalent of [WebMethod]

I've got a good one: what is the equivalent of the WebMethod directive that exports a constant to be part of a web service so that it can be used by the calling client?

If there is no such directive, how have you guys got around the problem of having no constants available.

For a bit of context I'm writing a header and footer web service for our intranet so that we don't have to copy changes to 30+ places when the header/stylesheet/etc. changes.  One of the constants I want is for DOCTYPE (some of our pages are HTML 3.2, some are HTML 4.01 and some are XHTML 1.0) so that when I call  GetHeader from the web service I can pass it a constant it understands.



Thomas Baker
Tuesday, November 12, 2002

Have you thought about using an enumeration?

Define the enumeration in your web service library:

public enum DocType
    Html3_2,                // or    Html_3_2      ???
    Html4_01                // and  Html_4_01    ???

and then in your web service class:

public string GetHeader(DocType docType)
    if (docType == DocType.Html3_2)
        return ...;
    else if (docType == DocType.Html4_01)
        return ...;
        return ...; 

Browse the WSDL markup for the web service and notice that the enumeration is defined along with the other types.  Also note that you can only enter valid enumeration values as specified in the WSDL markup (and in your original enumeration).  Anything else generates an ArgumentException.

Guy Incognito, MVP DOA
Tuesday, November 12, 2002

What's the standard way for representing a period (such as in a version number) in a constant?

Is Html4_01 ok?  Or is Html401 better?  I thought that looked too much like the 401 page not found error, so I opted for the underscores.  :)

Guy Incognito, MVP DOA
Tuesday, November 12, 2002

*  Recent Topics

*  Fog Creek Home