我設計了一個新的帶有JAX-WS和Spring的WebService。肥皂調用中的Jax-WS未知名稱空間定義
我不喜歡數組,所以我選擇了方法簽名中的java集合&列表。
使用我得到了一個不可用的WebMethod(在下面的例子中爲unlockBusComponent),因爲在生成的wsdl中是一個名爲「misconfigured」的命名空間。
首先是實體:
@XmlRootElement(namespace ="appstate.entities.web.company.tld",
name="ApplicationState")
public class ApplicationState {
private UUID applicationId;
private String applicationName;
private String hostName;
private String status;
public ApplicationState() {}//... public getter & setter are following
}
@XmlRootElement(namespace ="buscomponent.entities.web.company.tld")
public class BusComponent {
private UUID lockId;
private int mandantId;
private String name;
//... public getter & setter are following
}
現在的服務:
@WebService
public interface BusComponentInfoService {
@WebMethod
public Collection<BusComponent> getBusComponent(/** */
@WebParam(name = "mandantId") final int mandantId,/** */
@WebParam(name = "application") final ApplicationState application) throws Throwable;
@WebMethod
public void unlockBusComponent(/** */
@WebParam(name = "busComponent")
final BusComponent busComponent) throws Throwable;
}
@Component
@WebService(endpointInterface = "tld.company.BusComponentInfoService")
@SOAPBinding(style = SOAPBinding.Style.DOCUMENT, parameterStyle = SOAPBinding.ParameterStyle.WRAPPED)
public class BusComponentInfoServiceImpl extends SpringBeanAutowiringSupport implements BusComponentInfoService {
@Override
public Collection<BusComponent> getBusComponent(final int mandantId, final ApplicationState application) throws Throwable {
//....
final Collection<BusComponent> retval = new ArrayList<BusComponent>();
return retval;
}
@Override
public void unlockBusComponent(final BusComponent busComponent) throws Throwable {
//....
}
}
爲了測試我使用了SoapUI的服務,工作得非常好! 這裏請求:
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:bci="http://bci.lockserver.company.tld/">
<soapenv:Header/>
<soapenv:Body>
<bci:getBusComponent>
<mandantId>1</mandantId>
<!--Optional:-->
<application>
<!--Optional:-->
<applicationId>12345678-abcd-0987-edcb-1234567890ab</applicationId>
<!--Optional:-->
<applicationName>SoapUI Dummy</applicationName>
<!--Optional:-->
<hostName>mycomputer</hostName>
<!--Optional:-->
<status>?</status>
</application>
</bci:getBusComponent>
</soapenv:Body>
</soapenv:Envelope>
和響應:
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns3:getBusComponentResponse xmlns:ns2="buscomponent.entities.web.company.tld" xmlns:ns3="http://bci.lockserver.common.company.tld/" xmlns:ns4="appstate.entities.web.company.tld">
<return>
<lockId>b6226670-b7c6-43e7-bd65-5f73789ae90f</lockId>
<mandantId>1</mandantId>
<name>ABCDEF_001</name>
</return>
</ns3:getBusComponentResponse>
</S:Body>
</S:Envelope>
這個請求上述工作正常。但是以下請求unlockBusComponent是由SoapUI爲提交的buscompontents命名空間生成的。
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:bci="http://bci.lockserver.common.company.tld/"
xmlns:bus="buscomponent.entities.web.company.tld">
<soapenv:Header/>
<soapenv:Body>
<bci:unlockBusComponent>
<bus:busComponent>
<lockId>b6226670-b7c6-43e7-bd65-5f73789ae90f</lockId>
<mandantId>1</mandantId>
<name>ABCDEF_001</name>
</bus:busComponent>
</bci:unlockBusComponent>
</soapenv:Body>
</soapenv:Envelope>
給定BusComponent實體不會轉移到服務。期望的參數在服務器端是空的。如果我從總線刪除總線-命名空間:busComponent -Tags,總線組件將被成功轉移到該服務。
所以我的問題是:
- 哪些錯誤與buscomponent實體? (請注意帶有參數ApplicationState的WebMethod「getBusComponent」工作得非常好!)
- 重新設計(從單個值和集合切換到buscomponent-entities的數組)後,新服務運行良好。但爲什麼?與之前的方法有什麼不同?
現在全成工作服務:
@WebService
public interface BusComponentInfoService {
@WebMethod
public BusComponent[] getBusComponent(/** */
@WebParam(name = "mandantId") final int mandantId, /** */
@WebParam(name = "application") final ApplicationState application) throws Throwable;
@WebMethod
public void unlockBusComponents(/** */
@WebParam(name = "busComponent") final BusComponent[] busComponent) throws Throwable;
}
我同意你的看法,那就是收藏對我來說不好。但是:WebMethod不起作用,不處理集合或數組。只需切換到數組實現「解決」它。第二件事是,即時通訊使用@SOAPBinding(style = SOAPBinding.Style.DOCUMENT,parameterStyle = SOAPBinding.ParameterStyle.WRAPPED) – Mirko 2014-12-03 09:30:22
好吧,很高興你解決了你的問題。乾杯! – aurelius 2014-12-03 09:35:30