4
Jax-WS Web服務是代碼優先的方法。使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>
怎樣才能讓BadgeNumber和姓氏必填字段,而不是可選的,因爲每soapUI的請求。我嘗試將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」。
是的,WSDL將它顯示爲minOccures = 0。此外,我無法將@XmlElement(required = true)添加到Web參數中,它說「註釋XmlElement不允許用於此位置」。我做了這個公共MyInstallPhotoResponse getBadgePhoto(@XmlElement(required = true)@WebPa ....這是正確的嗎? – Ravi 2013-02-25 17:27:09
請讀取線程:http://stackoverflow.com/questions/8211420/xmlelement-annotation-dissallowed-with- webparam。 – Lan 2013-02-25 18:38:04
順便說一句,我強烈建議「合同優先」的方法,而不是「代碼優先」的方法。 – Lan 2013-02-25 19:34:18