e-cal
e-cal

Reputation: 1661

How to use enum in an asmx web service

I'm writing an asmx web service in visual basic, and I would like to put in my web service an enum that should be available to the web service's callers through the wsdl. But how could that be done? I'm writing my enum in the web service class, but it's not being published in the wsdl. I've already done this kind of thing successfully using C#, but I cannot understand how this is done in VB.

Upvotes: 1

Views: 2622

Answers (1)

ClayKaboom
ClayKaboom

Reputation: 1833

You cannot only create the enum, you must create a method that exposes the existence of that Enum to the client. That is: if you have a class which contains a property of the Enum type , the method should expose the class:

Public Class MyClassType
    Public Enum MyEnum
        Value1, Value2
    End Enum
End Class
 <WebMethod()> _
Public Sub ExposeTypes(MyObject As MyClassType)
  'This will make the client recognize it will receive a  class (complex type) with the enum property 
End Sub

Another approach would be exposing only the Enum Type:

     Public Enum MyEnum
        Value1, Value2
    End Enum

  <WebMethod()> _
Public Sub ExposeTypes(enum As MyEnum)
  'This will make the client recognize it will receive a simple type
End Sub

That is basically what you could do to make the client apps recognize your enum, however you may do something like generating the contract first in order to avoid these "Exposing" methods approach.

Upvotes: 2

Related Questions