java - minOccurs 和 maxOccurs

标签 java web-services cxf

我使用的是apache cxf 3.1.8,wsdl是由cxf引擎自动生成的。 我想为字段 ProductId 设置 minOccurs 和 maxOccurs,如下所示:

预计:

<xs:element minOccurs="0" maxOccurs="1" name="ProductId" type="xs:int"/> 

实际:

 <xs:element minOccurs="0" name="ProductId" type="xs:int"/>

换句话说,我希望元素 ProductId 在我的请求中只能出现一次。

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:v1="http://nameSpace/">
<soapenv:Header/>
<soapenv:Body>
<getProductService>
    <arg0>
        <ProductDate>2016-04-01</ProductDate>
        <ProductId>prod1</ProductId>
        ##<ProductId>prod1</ProductId>##
    </arg0>
</getProductService>
</soapenv:Body>
</soapenv:Envelope>

我的产品类定义如下:

public class Product{
private static final long serialVersionUID = 1L;
@XmlElement(name = "ProductId")
protected int productId;
@XmlElement(name = "OperationType")
protected String operationType;
}

感谢您的帮助。

最佳答案

您至少需要在服务器端启用 XML 架构验证,如果您还想检测来自服务器的格式错误的响应,则可能需要在客户端启用 XML 架构验证。

在 CXF 中,您可以使用 jaxws 客户端或端点(服务器端)上的 schema-validation-enabled 属性启用架构验证,如 CXF FAQ 中所述。 。此外,从 CXF 2.3 开始,您可以在代码中使用 SchemaValidation 注释。

Glen Mazza 博客上的更多示例: https://glenmazza.net/blog/entry/soap-xml-schema-validation

关于java - minOccurs 和 maxOccurs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54314588/

相关文章:

java - 用 % 处理溢出

java - JDBC批处理在insert语句中使用 "CASE WHEN"

web-services - 有人可以向我指出 Web 服务 URI 命名约定吗?

c# - 继承现有的 .Net 类序列化错误

java - Apache CXF 能否生成客户端并自动获取 WSDL 和模式的本地副本?

java - 使用 XML 可绘制的 RadioButton 样式

java - 中文文件名的 InvalidPathException

javascript - AngularJS 从 ng-repeat 创建的表单中选择值

java - 将自定义请求编码器提交到 JAXRSClientFactory

java - Apache CXF AtomPullServer