Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / April 2006

Tip: Looking for answers? Try searching our database.

Using Enum type as Webservice Parameter

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Martin Engelhardt - 06 Apr 2006 14:33 GMT
Hi,

I want to use the following:

Class Test ...

Public Enum TestEnum as integer
 Enum1 = 128
 Enum2 = 256
End Enum

<Webmethod...> _
Public Sub TestSub( parm as TestEnum)
...
End Sub
...
End Class

The enum we want to use is a enum from oracle .net client (db-datatypes)
which we can't change. TestEnum is only an example.

On client app we see the enum, but the corresponding values are wrong:
 Enum1 = 0
 Enum2 = 1

So if we call TestSub(TestEnum.Enum1) then value isn't 128 but 0 ?
If it would be a custom enum, we could change the values to correspond, but
we can't change the oracle enum values ????

Would be .NET Remoting a better way to program such things ?

Martin
Martin Kulov [MVP] - 07 Apr 2006 01:12 GMT
> Hi,
>
[quoted text clipped - 29 lines]
>
> Martin

Hi Martin,

when enum is serialized to XML only its string representation is send to the
client. That's the whole idea of XML communication channel. If you want to
transfer also the numeric value, you need to implement a custom solution.
Remoting would work in this case, but your decision to you Remoting or not
should not be based on this particular problem. It depends much more on the
transport protocol, network and software environment and others.
See "Choosing Communication Options in .NET" [1] for more information how to
make your choice.

[1]
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cp
conchoosingcommunicationoptionsinnet.asp


Regards,

Signature

Martin Kulov
http://www.codeattest.com/blogs/martin

MVP, MCT, MCSD.NET Early Achiever

Steven Cheng[MSFT] - 07 Apr 2006 04:20 GMT
Hi Martin,

As Martin Kulov mentioned, generally enum types are represented by xsd
enumeration simple type like below:

<s:simpleType name="TestEnum">
- <s:restriction base="s:string">
 <s:enumeration value="A" />
 <s:enumeration value="B" />
 </s:restriction>
 </s:simpleType>

so it can not hold two value pairs(or the mapping info). For your
scenario,I think you can consider use the XmlEnumAttribute to
specify the enum's actual number value as the underlying xmlserialization
value. e.g:

=================
Public Enum TestEnum As Integer

   <XmlEnum("128")> _
   Enum1 = 128

   <XmlEnum("256")> _
   Enum2 = 256

End Enum
====================

thus, the   "Enum1" will be transfered as "128", "Enum2" will be transfered
as "256" in SOAP message, and when arrive the other side, it will be
deserizlied to the .net enum value.

Hope this helps.

Regards,

Steven Cheng
Microsoft Online Community Support

==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Signature

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.