我如何通过我的 asmx 公开第 3 方的枚举?

发布于 2024-09-01 01:51:10 字数 175 浏览 1 评论 0原文

给定:

  • 一个 asmx Web 服务。
  • 包含有用枚举的第 3 方 dll。

问题:

我如何通过我的 网络服务,无需重复 我自己并重新输入枚举的成员 在我的网络服务的公共类中?

Given:

  • An asmx web service.
  • A 3rd party dll that contains a useful enum.

Question:

How can I expose this enum through my
web service without having to repeat
myself and re-type the enum's members
in my webservice's public class?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

↙厌世 2024-09-08 01:51:10

您可以创建一个方法,该方法接受或返回一个包含枚举的值。当它们生成代理类时,枚举上的命名空间将更改为您的服务命名空间,但您将拥有它们在您端输入的值。不过,只要他们不尝试在您的服务和第三方中使用相同的枚举,这就不应该成为问题。

You can create a method which either takes or returns a value with their enum in it. The namespace on the enum will change to your service namespace when they generate the proxy class, but you'll have the values they input on your end. This shouldn't be a problem though as long as they aren't trying to use the same enum in your service and the third party.

和我恋爱吧 2024-09-08 01:51:10

这个问题询问如何通过 SOAP Web 服务公开编程语言枚举。这是不可能的。原因如下:

通过“enum”,OP 表示一种编程语言构造,它生成由命名整数值组成的类型。例如:

public enum MyEnum
{
    Value1 = 10,
    Value2 = 20,
    Value3 = 30
}

这会在名称(例如 Value)和相应的值(例如 10)之间产生关联。 SOAP Web 服务中没有这样的东西。

SOAP Web 服务通过 WSDL(Web 服务描述语言)向客户端描述自身。 WSDL 使用 XML 架构 (XSD) 来描述要在客户端和服务之间交换的数据的形状。

XML 模式有一个“枚举”的概念,它描述某个元素或属性可以具有多个值之一。这些值在 XML 架构中列出(枚举)。例如,

  <xs:simpleType name="MyEnum">
    <xs:restriction base="xs:string">
      <xs:enumeration value="Value1"/>
      <xs:enumeration value="Value2"/>
      <xs:enumeration value="Value3"/>
    </xs:restriction>
  </xs:simpleType>

这定义了一个可以采用三个字符串值之一的类型:“Value1”、“Value2”或“Value3”。这些值不以任何方式与整数值关联。为了便于理解,请考虑以下内容:

  <xs:simpleType name="MyDateEnumeration">
    <xs:restriction base="xs:date">
      <xs:enumeration value="2013-06-01"/>
      <xs:enumeration value="2013-06-05"/>
      <xs:enumeration value="2014-06-01"/>
    </xs:restriction>
  </xs:simpleType>

这定义了一个可以采用三个 date 值之一的类型:2013 年 6 月 1 日、2013 年 6 月 5 日或 2014 年 6 月 1 日。请注意,有既不与任何整数值关联,也不与任何字符串名称关联。

最重要的是,XML 模式无法描述枚举 的编程语言概念。因此,WSDL 无法使用枚举 的编程语言概念,这意味着 SOAP Web 服务无法公开枚举

最好的办法是公开名称或值,但不能同时公开两者,如上面的 MyEnum 所示。当客户端使用该服务时,它可能会将 MyEnum 转换为编程语言的 enum。但是,由于没有与任何名称关联的整数值,因此可以合理地期望每个客户端使用不同的整数值。一个客户端可能使用 1 作为 Value1,而另一个客户端可能使用 0

This question is asking about how to expose a programming language enumeration over a SOAP web service. This cannot be done. Here's why not:

By "enum", the OP means a programming language construct that produces a type consisting of named integer values. For instance:

public enum MyEnum
{
    Value1 = 10,
    Value2 = 20,
    Value3 = 30
}

This produces an association between the names, such as Value, and the corresponding values, such as 10. There is nothing like this in SOAP web services.

SOAP web services describe themselves to clients via WSDL (Web Services Description Language). WSDL uses XML Schema (XSD) to describe the shape of the data to be interchanged between the clients and the service.

XML schema has a concept of "enumeration", which describes that a certain element or attribute can have one of several values. Those values are listed (enumerated) in the XML Schema. For instance,

  <xs:simpleType name="MyEnum">
    <xs:restriction base="xs:string">
      <xs:enumeration value="Value1"/>
      <xs:enumeration value="Value2"/>
      <xs:enumeration value="Value3"/>
    </xs:restriction>
  </xs:simpleType>

This defines a type which can take on one of three string values: "Value1", "Value2" or "Value3". These values are not associated in any way with integer values. Just to hammer it home, consider the following:

  <xs:simpleType name="MyDateEnumeration">
    <xs:restriction base="xs:date">
      <xs:enumeration value="2013-06-01"/>
      <xs:enumeration value="2013-06-05"/>
      <xs:enumeration value="2014-06-01"/>
    </xs:restriction>
  </xs:simpleType>

This defines a type which can take on one of three date values: June 1, 2013, June 5, 2013 or June 1, 2014. Note that there is neither an association with any integer values, nor even any association with any string name.

The bottom line is that XML Schema cannot describe the programming language concept of an enum. As a result, WSDL cannot use the programming language concept of an enum, which means that SOAP web services cannot expose an enum.

The best that can be done is to expose the names, or the values, but not both, as in MyEnum above. When a client consumes that service, it may translate MyEnum into an enum in a programming language. However, since there is no integer value associated with any of the names, each client could reasonably be expected to use a different integer value. One client might use 1 for Value1, while another might use 0.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文