gpt4 book ai didi

java - JAX WS 中 SOAP WS 的枚举参数

转载 作者:行者123 更新时间:2023-12-01 09:02:30 28 4
gpt4 key购买 nike

我想问一下如何在 JAX-WS 中指定 SOAP Web 服务,这样如果我希望通过值 A 或值B。任何其他值都应该返回错误。

我想到了Java中的枚举,但仍然不知道如何实现它。

有什么建议吗?预先感谢您。

最佳答案

您可以使用枚举来实现相同的目的。

在 WSDL 的 XSD 中,您将定义如下元素:-

 <xsd:complexType name="Value">
<xsd:sequence>
<xsd:element name="elementValue" type="constantType" />
</xsd:sequence>
</xsd:complexType>


<xsd:simpleType name="constantType">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="A" />
<xsd:enumeration value="B" />
</xsd:restriction>
</xsd:simpleType>

在上面的示例中,您说有一个名为 elementValue 的元素,其类型为constantType,constantType 的值可以为 A 或 B,其类型为 String。

当您谈论 SOAP 时,基本上 WSDL 是您需要与服务用户共享的契约(Contract)。如果某个特定字段只能有两个值,那么应该在您的契约(Contract)(即 WSDL)中提及这一点。

在java中你可以使用Enum来定义它,如下所示:-

public enum ElementValue
{
A,
B;
}

现在您可以使用以下语法访问这些值:-

ElementValue.A
ElementValue.B

关于java - JAX WS 中 SOAP WS 的枚举参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41564388/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com