473,516 Members | 2,889 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3935
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
467
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 service consumer who will take action on it. Is it possible? If yes, how to implement? If possible, please provide me the link. Thanks lot.
21
4572
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
20900
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 rows then I need to return those rows to the consumer. I can't tell if the consumer of the web service will use .Net or maybe java. 1) If the web...
6
1898
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 for service consumers, at design time. But, I think the cnsumers must completely know all aspects of that service. This sounds not good, and breaks...
6
10030
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
11810
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 (NT_AUTHORITY\SYSTEM). I understand that when the service starts, no user may be logged in, but that's ok, as the app I am monitoring can only be run...
0
7276
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7408
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7581
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7142
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7548
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5110
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4773
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
825
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
488
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.