问题描述
Jax-WS Web服务的代码优先方法.
The is code first approach to Jax-WS web service.
@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请求生成了这样的内容
In the above code MyInstallPhotoResponse is defined in a xml schema. The SoapUI request generated something like this
<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请求.
How can make the BadgeNumber and LastName a required field as opposed to optional as per the soapui request. I tried to move the badgeNumber and lastName to a object myinstallphotorequest (defined in schema) and made the two parameters requried. this the soapui request I got.
<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"的可选".
Again I was not able to remove the Optional for the parameter "MyInstallPhotoRequest".
推荐答案
如果检查Web服务的WSDL文件,则该参数应具有minOccurs = 0.这就是为什么SOAPUI请求在此处放置可选注释的原因.
If you check the WSDL file for your web service, the parameter should have minOccurs=0. That's why the SOAPUI request put the optional comments there.
请使用@XmlElement(required=true)
注释所需的WebParam.
Please use @XmlElement(required=true)
to annotate your WebParam that is required.
这篇关于将Web服务请求参数设为必填字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!