我已在我的应用程序中实现了Web服务。当我想通过SOA上的Web服务使用Soap UI将对象发送到我的服务器时,我得到这样的结果:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:impl="http://impl.arg.lou.com/">
<soapenv:Header/>
<soapenv:Body>
<impl:addStudent>
<!--Optional:-->
<student>
<!--Optional:-->
<name>?</name>
</student>
</impl:addStudent>
</soapenv:Body>
</soapenv:Envelope>
我不希望name字段是可选的,它应该是必填字段。我该怎么做?
我使用Apache cxf。
答案 0 :(得分:2)
在您的Web服务定义中,您有一个类型部分,用于定义邮件的XML架构。在该定义中,您可以设置多个约束,例如“必填字段”。
示例:强>
<wsdl:definitions name="myService" ...>
<wsdl:types>
<xs:schema version="1.0" targetNamespace="myNameSpace" xmlns:tns="myNameSpace">
<xs:complexType name="studentType">
<xs:attribute name="name" type="xs:string" use="required" />
</xs:complexType>
<xs:element name="student" nillable="false" type="tns:studentType"/>
</xs:schema>
</wsdl:types>
...
</wsdl:definitions>
现在,如果您没有在apache CXF配置中激活模式验证,则不会在服务器端验证这一点:
<jaxws:endpoint id="myService" ...>
<jaxws:properties>
<entry key="schema-validation-enabled" value="true" />
...
</jaxws:properties>
...
</jaxws:endpoint>
PS:SOAP UI使用目标Web服务的XML架构生成默认请求。如果XML架构没有use="required"
或nillable="false"
,则会在元素上添加<!-- optional -->
条评论