C#Asp.Net Web服务

编程入门 行业动态 更新时间:2024-10-26 22:19:09
本文介绍了C#Asp.Net Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

你好 我有以下情况:我有一个WCF网络服务,其中包含枚举。我有另一个应用程序(一个网站),我在其中调用Web服务并使用Web服务中的枚举来创建下拉列表。当我在localhost上运行网站时,一切都很好。但是在我在Web服务器上部署我的解决方案之后,我使用枚举生成的下拉列表被混淆了(枚举的值以另一个顺序显示)。欢迎任何形式的帮助。 查找下面的代码示例: 1.使用的枚举

Hello I have the following situation: I have a WCF web service which contains, among others, enums. I have another application (a web site), in which I call the web service and use the enums from the web service to create dropdown lists. When I run the web site on localhost, everything is fine. But after I deploy my solutions on a web server, my dropdown lists generated with enums are mixed up (the values of the enum are shown in another order). Any kind of help is welcome. Find below a code example: 1. An enum used

[System.Runtime.Serialization.DataContract(Namespace = Cfg.MtplSchemaNamespace)] public enum MtplLegalEntityEnum : int { [System.Runtime.Serialization.EnumMember] PhysicalPerson = 1, [System.Runtime.Serialization.EnumMember] JuridicalPerson = 2, [System.Runtime.Serialization.EnumMember] SelfEmployed = 3 }

2.我用来从我的枚举中生成下拉列表的函数:

2. The functions I use to generate dropdown lists from my enums:

public void InitDropDownList(DropDownList dropDownList, Type enumerator) { Hashtable ht = GetEnumForBind(enumerator); dropDownList.DataSource = ht; dropDownList.DataTextField = "value"; dropDownList.DataValueField = "key"; dropDownList.DataBind(); } private Hashtable GetEnumForBind(Type enumeration) { string[] names = Enum.GetNames(enumeration); Array values = Enum.GetValues(enumeration); Hashtable ht = new Hashtable(); for (int i = 0; i < names.Length; i++) { // Get the global resource string. try { // Look in the global resource file called MyResource.resx. string resKey = enumeration.Name + "_" + names[i]; if ((String)GetGlobalResourceObject("enums", resKey) == null) throw new Exception("Could not find global resource."); ht.Add(Convert.ToInt32(values.GetValue(i)).ToString(), (String)GetGlobalResourceObject("enums", resKey)); } catch { ht.Add(Convert.ToInt32(values.GetValue(i)).ToString(), names[i]); } } return ht; }

3.函数的调用:

3. The call of the function:

InitDropDownList(ddlPersonType, typeof(Sk.Mtpl.MtplLegalEntityEnum));

提前谢谢。

Thank you in advance.

推荐答案

请参阅我对该问题的评论。使用枚举类型是高效和健壮的,但是...枚举成员,它们的值和顺序存在一些非平凡的问题。我在文章中描述了这些问题的详细程度: 枚举类型不能枚举!解决.NET和语言限制 [ ^ ]。 即使您在问题中提供的信息远远不够,也许您将能够在阅读了我对枚举问题的解释之后解决了这个问题。 再次,如果你提供更多信息,也许我将能够找出你的问题并建议解决方案。
-SA
Please see my comment to the question. Using enumeration types is highly productive and robust, but… There are some non-trivial issues with the enumeration members, their values and order. I describe these problem is good level of detail in my article: Enumeration Types do not Enumerate! Working around .NET and Language Limitations[^]. Even though the information you provided in your question is by far insufficient, perhaps you will be able to sort things out after reading of my explanation of the enumeration issues. Again, if you provide more information, maybe I will be able to identify your problem and suggest the resolution.
—SA

我发现了问题。该问题由InitDropDownList函数生成。谢谢你的建议Sergey Alexandrovich。 祝你好运, Mihai。 I have found the problem. The issue was generated by the InitDropDownList function. Thank you for your suggestions Sergey Alexandrovich. Best regards, Mihai.

更多推荐

C#Asp.Net Web服务

本文发布于:2023-10-29 13:17:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1539793.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Asp   Net   Web

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!