是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(在架构中定义)并使两个参数需要。这是我得到的肥皂水。
<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。
答案 0 :(得分:10)
如果检查Web服务的WSDL文件,则参数应为minOccurs = 0。这就是SOAPUI请求将可选注释放在那里的原因。
请使用@XmlElement(required=true)
注释所需的WebParam。