473,414 Members | 1,723 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Web Service export enum to consumer

I building a web service that has an enum I want the consuming
application to be able to use.

I have the enum declared in the web service as:
public enum myEnum
{
ONE = 1,
TWO = 2,
};

I want to be able to access these from the consuming application such
as: myConsumer.localhost.myEnum.ONE. However, I can't seem to get it
to work. How do I make this visible/export this enum to the consumer?
I would rather not duplicate the code. Thanks for any and all help.

Mar 9 '07 #1
6 2743
Apply the Attribute XmlEnumAttribute for each option of the enumearion.

<bs***@hotmail.comwrote in message
news:11**********************@q40g2000cwq.googlegr oups.com...
>I building a web service that has an enum I want the consuming
application to be able to use.

I have the enum declared in the web service as:
public enum myEnum
{
ONE = 1,
TWO = 2,
};

I want to be able to access these from the consuming application such
as: myConsumer.localhost.myEnum.ONE. However, I can't seem to get it
to work. How do I make this visible/export this enum to the consumer?
I would rather not duplicate the code. Thanks for any and all help.
Mar 9 '07 #2
Thanks for the reply. I'm having trouble figuring out how to apply the
XmlEnumAttribute. Here's what I tried, but neither worked:

public enum myEnum
{
[System.Xml.Serialization.XmlEnumAttribute]
ONE = 1,
[System.Xml.Serialization.XmlEnumAttribute]
TWO = 2,
}

I also tried:
[System.Xml.Serialization.XmlEnumAttribute]
public enum myEnum
{
ONE = 1,
TWO = 2,
}

Thanks for any and all help.

On Mar 9, 9:47 am, "Mariano Omar Rodriguez" <mrodr...@yahoo.com>
wrote:
Apply the Attribute XmlEnumAttribute for each option of the enumearion.

<b...@hotmail.comwrote in message

news:11**********************@q40g2000cwq.googlegr oups.com...
I building a web service that has an enum I want the consuming
application to be able to use.
I have the enum declared in the web service as:
public enum myEnum
{
ONE = 1,
TWO = 2,
};
I want to be able to access these from the consuming application such
as: myConsumer.localhost.myEnum.ONE. However, I can't seem to get it
to work. How do I make this visible/export this enum to the consumer?
I would rather not duplicate the code. Thanks for any and all help.

Mar 9 '07 #3
"Mariano Omar Rodriguez" <mr******@yahoo.comwrote in message
news:eu**************@TK2MSFTNGP02.phx.gbl...
Apply the Attribute XmlEnumAttribute for each option of the enumearion.
I don't believe that this will permit the client to treat the type as an
"enum". The reason is that there is no such thing as an enum in XML Schema,
and XML Schema is what is used to communicate type information from server
to client via the WSDL.

There is an xs:enumeration facet in XML schema, but it doesn't quite produce
the same thing as an enum in C#. Instead, it "enumerates" the set of
possible values for a type. It does not then associate a name with each
possible value.

One might manage some magic with schema importer extensions, but this would
only work for .NET clients. Note in particular, that not all languages have
the concept of an "enum".

John
Mar 9 '07 #4
What would be the best way to share a bunch on constants (these are
preprocessor macros for a native DLL) between a web service and it's
consumer? Please include some C# code samples because I'm a newbie.
Thanks for the help.

On Mar 9, 10:17 am, "John Saunders" <john.saunders at trizetto.com>
wrote:
"Mariano Omar Rodriguez" <mrodr...@yahoo.comwrote in messagenews:eu**************@TK2MSFTNGP02.phx.gbl. ..
Apply the AttributeXmlEnumAttributefor each option of the enumearion.

I don't believe that this will permit the client to treat the type as an
"enum". The reason is that there is no such thing as an enum in XML Schema,
and XML Schema is what is used to communicate type information from server
to client via the WSDL.

There is an xs:enumeration facet in XML schema, but it doesn't quite produce
the same thing as an enum in C#. Instead, it "enumerates" the set of
possible values for a type. It does not then associate a name with each
possible value.

One might manage some magic with schema importer extensions, but this would
only work for .NET clients. Note in particular, that not all languages have
the concept of an "enum".

John
Mar 9 '07 #5
On Mar 9, 2:23 pm, b...@hotmail.com wrote:
What would be the best way to share a bunch on constants (these are
preprocessor macros for a native DLL) between a web service and it's
consumer? Please include some C# code samples because I'm a newbie.
Thanks for the help.

On Mar 9, 10:17 am, "John Saunders" <john.saunders at trizetto.com>
wrote:
"Mariano Omar Rodriguez" <mrodr...@yahoo.comwrote in messagenews:eu**************@TK2MSFTNGP02.phx.gbl. ..
Apply the AttributeXmlEnumAttributefor each option of the enumearion.
I don't believe that this will permit the client to treat the type as an
"enum". The reason is that there is no such thing as an enum in XML Schema,
and XML Schema is what is used to communicate type information from server
to client via the WSDL.
There is an xs:enumeration facet in XML schema, but it doesn't quite produce
the same thing as an enum in C#. Instead, it "enumerates" the set of
possible values for a type. It does not then associate a name with each
possible value.
One might manage some magic with schema importer extensions, but this would
only work for .NET clients. Note in particular, that not all languages have
the concept of an "enum".
John
First of all, if I understand your problem, you need the client to
know *the values* of the enum members. The *list* of enum members is
exported to the client just declaring a parameter of this type in any
of the methods in the WebService.
Now, to the point...
I've had problems like this in an application that I was developing a
while ago. After unsuccessfully trying to export those values to the
client, I finally took the decision to review my objectives. The
point is: Why do you want to export those values to the client as an
enum?
If the values are hardly related: They must be in separated constants.
If you want the client to use those values when it invokes some of
your methods, change the type of the arguments of those methods to the
enum type, so you get rid of values (enums are correctly published to
the client, then, but without the associated values).
If you want the client to use those values for itself you can export
an enum and a method who translates enums to values. Here is a sample
code:

....
public enum myEnum
{
ONE = 1,
TWO = 2,
}

[WebMethod]
public int getEnumValue(myEnum e)
{
return (int)e;
}
....

I know the performance issues that this approach has but I couldn't
figure out a better way to do it yet.

Mar 9 '07 #6
"John Saunders" <john.saunders at trizetto.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
"Mariano Omar Rodriguez" <mr******@yahoo.comwrote in message
news:eu**************@TK2MSFTNGP02.phx.gbl...
>Apply the Attribute XmlEnumAttribute for each option of the enumearion.

I don't believe that this will permit the client to treat the type as an
"enum". The reason is that there is no such thing as an enum in XML
Schema, and XML Schema is what is used to communicate type information
from server to client via the WSDL.
Ok, I take back part of this.

If you have an enum type like this:

public enum MyEnum
{
One = 1,
Two = 2
}

Then this will be translated into the following XML Schema type:

<s:simpleType name="MyEnum">
<s:restriction base="s:string">
<s:enumeration value="One" />
<s:enumeration value="Two" />
</s:restriction>
</s:simpleType>

This will cause the following client proxy to be created:

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("Sy stem.Xml",
"2.0.50727.42")]
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(Namespac e="http://tempuri.org/")]
public enum MyEnum {
/// <remarks/>
One,
/// <remarks/>
Two,
}

Note that the integer value of "One" on the client is zero.

The reason that I didn't think this would work is that the web services I've
recently created couldn't simply use s:restriction base="string". They had
to use s:restriction base="s:int".

Note that you can get some interesting effects when your <s:enumeration>
values are not valid .NET identifiers. For instance, an enum member with
value "a b c" gets the name "abc" on the client:

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("Sy stem.Xml",
"2.0.50727.42")]
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(Namespac e="urn:customerSpecific.types.umcase.um.cca.webser vices.trizetto.com")]
public enum aaTesting {
/// <remarks/>
[System.Xml.Serialization.XmlEnumAttribute("a b c")]
abc,
/// <remarks/>
[System.Xml.Serialization.XmlEnumAttribute("d e f")]
def,
}

John
Mar 9 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Michael Fan | last post by:
I am a newbie for web servcie and want to write a web service which monitors the certain field in the database. Once it exceeds the certain value, web service will send out notification to web...
21
by: Andreas Huber | last post by:
Hi there Spending half an hour searching through the archive I haven't found a rationale for the following behavior. using System; // note the missing Flags attribute enum Color {
1
by: R.A. | last post by:
Hi, I have an web service method that accept an xml document and returns a different xml document. Based on the input xml I fill a dataset with information from a database. If the dataset has...
6
by: dotNeter | last post by:
The services, talked here, are things used in IServiceContainer, IServiceProvider, etc. In my opinion, everything can be a service, and a service is generally used for providing specific features...
6
by: bsma1 | last post by:
I building a web service that has an enum I want the consuming application to be able to use. I have the enum declared in the web service as: public enum myEnum { ONE = 1, TWO = 2, };
33
by: JamesB | last post by:
I am writing a service that monitors when a particular app is started. Works, but I need to get the user who is currently logged in, and of course Environment.UserName returns the service logon...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.