Hacer que un parámetro de solicitud de servicio web sea un campo obligatorio
El código es el primer acercamiento al servicio web Jax-WS.
@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;
}
}
En el código anterior, MyInstallPhotoResponse se define en un esquema xml. La solicitud de SoapUI generó algo como esto.
<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>
¿Cómo puede hacer que BadgeNumber y LastName sea un campo obligatorio en lugar de opcional según la solicitud de soapui? Intenté mover el badgeNumber y el lastName a un objeto myinstallphotorequest (definido en el esquema) e hice que los dos parámetros fueran necesarios. Esta es la solicitud de jabón que tengo.
<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>
De nuevo, no pude eliminar la Opcional para el parámetro "MyInstallPhotoRequest".