我之前从 WSDL 生成了 Metro/JAXB 客户端,并且 Java 类与 SOAP/XML 之间的编组/解组工作没有任何问题。我已经生成了一个新客户端,似乎存在解组问题,我不知道为什么。WSDL 非常大(> 27,000 行),我不得不使用 -B-XautoNameResolution,因为除了大小写之外,某些元素名称是相同的。
我正在尝试执行此方法/操作:
@WebService(name = "servicePortType", targetNamespace = "urn:service")
@XmlSeeAlso({
ObjectFactory.class
})
public interface ServicePortType {
/**
* Service definition of function unsp__GetSubscriberList
*
* @param result
* @param totalSubsFound
* @param getSubListReq
* @param paginatedInfo
* @param getSubscriberListData
*/
@WebMethod(operationName = "GetSubscriberList")
@RequestWrapper(localName = "GetSubscriberList", targetNamespace = "urn:service", className = "service.GetSubscriberList")
@ResponseWrapper(localName = "GetSubscriberListResult", targetNamespace = "urn:service", className = "service.GetSubscriberListResult")
public void getSubscriberList(
@WebParam(name = "GetSubListReq", targetNamespace = "")
GetSubscriberListRequest getSubListReq,
@WebParam(name = "Result", targetNamespace = "", mode = WebParam.Mode.OUT)
Holder<ResultCodeStruct> result,
@WebParam(name = "PaginatedInfo", targetNamespace = "", mode = WebParam.Mode.OUT)
Holder<PaginatedInfo> paginatedInfo,
@WebParam(name = "TotalSubsFound", targetNamespace = "", mode = WebParam.Mode.OUT)
Holder<Integer> totalSubsFound,
@WebParam(name = "GetSubscriberListData", targetNamespace = "", mode = WebParam.Mode.OUT)
Holder<GetSubscriberListData> getSubscriberListData);
}
此方法将返回订阅者数据以及订阅者总数。我的电话看起来像这样:
public int getTotalSubscriptions()
throws Exception
{
GetSubscriberListRequest subscriberListRequest = factory.createGetSubscriberListRequest();
Holder<ResultCodeStruct> result = null;
Holder<PaginatedInfo> paginatedInfo = null;
Holder<Integer> totalSubsFound = null;
Holder<GetSubscriberListData> subscriberListData = null;
subscriberListRequest.setMaxSubscribers(factory.createGetSubscriberListRequestMaxSubscribers(1));
port.getSubscriberList(subscriberListRequest,
result,
paginatedInfo,
totalSubsFound,
subscriberListData);
if (result.value.getResultCode() != CODE_SUCCESS)
{
throw new Exception("Failed call");
}
return totalSubsFound.value.intValue();
}
我在结果对象上得到一个 NullPointerException。我已经跟踪了 SOAP 调用,并且返回的 XML 与预期的一样,包括一个 Result 元素。
我以前从未遇到过 WebParam.Mode.OUT。在我拨打电话之前应该初始化 Holder<> 实例吗?到什么?
这些元素被包装在 SOAP 中的 GetSubscriberListResult 元素中,但由于接口方法在@ResponseWrapper 中定义了该元素,因此我希望将它们解组到传入的对象中。也许我需要做些别的事情?
非常感谢任何建议/帮助!