使Web服务请求参数成为必填字段

Rav*_*avi 5 xsd wsdl 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;
     }
}
Run Code Online (Sandbox Code Playgroud)

在上面的代码中,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>
Run Code Online (Sandbox Code Playgroud)

如何根据soapui请求使BadgeNumber和LastName成为必填字段而不是可选字段.我试图将badgeNumber和lastName移动到对象myinstallphotorequest(在架构中定义)并使两个参数需要.这是我得到的肥皂水要求.

<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>
Run Code Online (Sandbox Code Playgroud)

我再次无法删除参数"MyInstallPhotoRequest"的Optional.

Lan*_*Lan 10

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

请用于@XmlElement(required=true)注释所需的WebParam.


归档时间:

查看次数:

32497 次

最近记录:

9 年,8 月 前