473,569 Members | 2,793 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.loca lhost.myEnum.ON E. 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 10039
Apply the Attribute XmlEnumAttribut e for each option of the enumearion.

<bs***@hotmail. comwrote in message
news:11******** **************@ q40g2000cwq.goo glegroups.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.loca lhost.myEnum.ON E. 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
XmlEnumAttribut e. Here's what I tried, but neither worked:

public enum myEnum
{
[System.Xml.Seri alization.XmlEn umAttribute]
ONE = 1,
[System.Xml.Seri alization.XmlEn umAttribute]
TWO = 2,
}

I also tried:
[System.Xml.Seri alization.XmlEn umAttribute]
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 XmlEnumAttribut e for each option of the enumearion.

<b...@hotmail.c omwrote in message

news:11******** **************@ q40g2000cwq.goo glegroups.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.loca lhost.myEnum.ON E. 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******** ******@TK2MSFTN GP02.phx.gbl...
Apply the Attribute XmlEnumAttribut e 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.saunder s at trizetto.com>
wrote:
"Mariano Omar Rodriguez" <mrodr...@yahoo .comwrote in messagenews:eu* *************@T K2MSFTNGP02.phx .gbl...
Apply the AttributeXmlEnu mAttributefor 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.co m 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.saunder s at trizetto.com>
wrote:
"Mariano Omar Rodriguez" <mrodr...@yahoo .comwrote in messagenews:eu* *************@T K2MSFTNGP02.phx .gbl...
Apply the AttributeXmlEnu mAttributefor 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(my Enum 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.saunder s at trizetto.comwro te in message
news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
"Mariano Omar Rodriguez" <mr******@yahoo .comwrote in message
news:eu******** ******@TK2MSFTN GP02.phx.gbl...
>Apply the Attribute XmlEnumAttribut e 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:restrictio n base="s:string" >
<s:enumeratio n value="One" />
<s:enumeratio n value="Two" />
</s:restriction>
</s:simpleType>

This will cause the following client proxy to be created:

/// <remarks/>
[System.CodeDom. Compiler.Genera tedCodeAttribut e("System.Xml ",
"2.0.50727. 42")]
[System.Serializ ableAttribute()]
[System.Xml.Seri alization.XmlTy peAttribute(Nam espace="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:enumeratio n>
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.Genera tedCodeAttribut e("System.Xml ",
"2.0.50727. 42")]
[System.Serializ ableAttribute()]
[System.Xml.Seri alization.XmlTy peAttribute(Nam espace="urn:cus tomerSpecific.t ypes.umcase.um. cca.webservices .trizetto.com")]
public enum aaTesting {
/// <remarks/>
[System.Xml.Seri alization.XmlEn umAttribute("a b c")]
abc,
/// <remarks/>
[System.Xml.Seri alization.XmlEn umAttribute("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
4577
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
20909
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
1903
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
2749
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
11824
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
7612
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7922
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
7964
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...
0
6281
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5509
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
5218
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...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3637
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1209
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.