I'm building an ASP.NET 3.5 application and would like to expose an enum I have in my WebService class without using it as a parameter in once of my WebMethods.
I have a really simple example to illustrate what I want... Let's say I have the following WebService (I'll call it Agent.asmx):
<System.Web.Script.Services.ScriptService()> _
<System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class Agent
Inherits System.Web.Services.WebService
<WebMethod(EnableSession:=True)> _
Public Function DoSomething(ByVal doWhat As WhatEnum) As Boolean
Return ...
End Function
End Class
Public Enum WhatEnum
AskStackOverflowQuestion
PhoneAFriend
FiftyFifty
End Enum
Because I used the Enum in one of the WebMethods, it will output the following in the JavaScript in generates for the Agent when the WebService is referenced in my .aspx page (from http://localhost/Agent.asmx/js):
if (typeof(SomeNamespace.WhatEnum) === 'undefined') {
SomeNamespace.WhatEnum = function() { throw Error.invalidOperation(); }
SomeNamespace.WhatEnum.prototype = { AskStackOverflowQuestion: 0,PhoneAFriend: 1,FiftyFifty: 2}
SomeNamespace.WhatEnum.registerEnum('SomeNamespace.WhatEnum', true);
}
Now I can go and use these enums wherever I want on the client side. Now, that's all fine and dandy, but I have another Enum in my Agent that I don't actually use in any of the WebMethods, which I would also like to be automatically exposed in the Agent's JavaScript. Is there a way, perhaps an attribute or something I could use, to cause it to be included?
If not, my fallback solution is to just create a dummy method with my Enum as a parameter so that it will be available, and simply never call it from the JS, though I'd rather not litter the code. Thanks!