wsdl - 将 Web 服务请求参数设为必填字段

标签 wsdl xsd jax-ws

Jax-WS Web 服务的代码优先方法。

@WebService (serviceName = "MyInstallPhotoService")
@SOAPBinding(style=SOAPBinding.Style.DOCUMENT, use=SOAPBinding.Use.LITERAL, parameterStyle=SOAPBinding.ParameterStyle.WRAPPED)
public class MyInstallPhotoWS {

    private MyInstallPhotoManager myInstallPhotoManager;

    @Resource
    WebServiceContext context;


    @WebMethod(operationName = "getMyInstallPhoto")
    @WebResult(name = "PhotoRetrievalResponse", partName = "PhotoRetrievalResponse")
    public MyInstallPhotoResponse getBadgePhoto(@WebParam(name = "BadgeNumber", partName = "BadgeNumber") String badgeNumber, @WebParam(name = "LastName", partName = "LastName") String lastName) {
        MyInstallPhotoResponse myInstallPhotoResponse = new MyInstallPhotoResponse();
        try {
            // more code here
        } catch (Exception e) {
          e.printStackTrace();
        }
        return myInstallPhotoResponse;
     }
}

在上面的代码中 MyInstallPhotoResponse 是在一个 xml 模式中定义的。 SoapUI 请求生成了这样的东西
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Header/>
   <soapenv:Body>
      <rsw:getBadgePhoto>
         <!--Optional:-->
         <rsw:BadgeNumber>I180748-003</rsw:BadgeNumber>
         <!--Optional:-->
         <rsw:LastName>Jones</rsw:LastName>
      </rsw:getBadgePhoto>
   </soapenv:Body>
</soapenv:Envelope>

如何使 BadgeNumber 和 LastName 成为必填字段,而不是根据soapui 请求的可选字段。我试图将徽章编号和姓氏移动到对象 myinstallphotorequest(在架构中定义)并要求这两个参数。这是我收到的soapui 请求。
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:myin="http://www.lexisnexis.com/myInstallPhotoService" xmlns:myin1="http://www.lexisnexis.com/schema/myInstallPhotoServiceTypes">
   <soapenv:Header/>
   <soapenv:Body>
      <myin:getMyInstallPhoto>
         <!--Optional:-->
         <myin:MyInstallPhotoRequest>
            <myin1:badgeNumber>?</myin1:badgeNumber>
            <myin1:lastName>?</myin1:lastName>
         </myin:MyInstallPhotoRequest>
      </myin:getMyInstallPhoto>
   </soapenv:Body>
</soapenv:Envelope>

我再次无法删除参数“MyInstallPhotoRequest”的可选。

最佳答案

如果您检查 Web 服务的 WSDL 文件,则该参数应具有 minOccurs=0。这就是 SOAPUI 请求将可选注释放在那里的原因。

请使用 @XmlElement(required=true)注释您需要的 WebParam。

关于wsdl - 将 Web 服务请求参数设为必填字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15071772/

相关文章:

通过客户端 stub 访问 WSDL 时发生 Java InaccessibleWSDLException

java - spring-ws 错误动态创建 wsdl

xml - 错误 : The prefix "xsi" for attribute "xsi:schemaLocation" is not bound

java - xsd 未在某些系统上验证 : "Cannot resolve the name to a(n) ' type definition' component.“

java - JAX-WS:独立于 WSDL 的编译模式

java - Axis2 用户认证

java - 为什么我的 wsdl 不显示元素

gradle - gradle安装 “error: package XXXXX does not exist”

web-services - 返回 Pojo WebService JaxWS。重命名 <return> 节点

java - CXF 错误解码错误 UnsupportedOperationException