5

这是 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>

根据 soapui 请求,如何使 BadgeNumber 和 LastName 成为必填字段,而不是可选字段。我试图将badgeNumber 和lastName 移动到对象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”的 Optional。

4

1 回答 1

11

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

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

于 2013-02-25T17:18:03.340 回答