我使用插件jaxws-maven-plugin从wsdl生成Java类。生成了两个文件-1个接口和一个实现“ Service”的Service类。我已经通过设置适当的URL和凭证为WebServiceTemplate创建了bean。但是,当我调用webServiceTemplate.marshalSendAndReceive(request)时,它将引发错误-
org.springframework.ws.soap.client.SoapFaultClientException:无法从传入请求中获取操作名称
我需要在调用方法的任何地方指定operationName吗?
请帮助我。
//以下2个生成的类
@WebService(name = "ws_card_link", targetNamespace = "http://xxx/xxxx.wsdl")
@SOAPBinding(style = SOAPBinding.Style.RPC)
public interface WsCardLink {
@WebMethod(action = "http://xxxx/xxxx.wsdl/linkCard")
@WebResult(name = "result", partName = "result")
public String linkCard(
@WebParam(name = "pan", partName = "pan")
String pan,
@WebParam(name = "pCusIden", partName = "pCusIden")
String pCusIden,
@WebParam(name = "channel", partName = "channel")
String channel,
@WebParam(name = "userU", partName = "userU")
String userU,
@WebParam(name = "passwordU", partName = "passwordU")
String passwordU);
}
@WebServiceClient(name = "ws_card_link", targetNamespace = "http://xxx/xxx.wsdl", wsdlLocation = "file:/C:/Users/admin/xxxx.wsdl")
public class WsCardLinkService extends Service
{
private static final String WS_CARD_LINK_WSDL_URL = "http://xxxx/xxxx.wsdl";
private static final URL WSCARDLINK_WSDL_LOCATION;
private static final WebServiceException WSCARDLINK_EXCEPTION;
private static final QName WSCARDLINK_QNAME = new QName(WS_CARD_LINK_WSDL_URL, "ws_card_link");
static {
URL url = null;
WebServiceException e = null;
try {
url = new URL("file:/C:/Users/admin/xxx.wsdl");
} catch (MalformedURLException ex) {
e = new WebServiceException(ex);
}
WSCARDLINK_WSDL_LOCATION = url;
WSCARDLINK_EXCEPTION = e;
}
public WsCardLinkService() {
super(getWsdlLocation(), WSCARDLINK_QNAME);
}
public WsCardLinkService(WebServiceFeature... features) {
super(getWsdlLocation(), WSCARDLINK_QNAME, features);
}
public WsCardLinkService(URL wsdlLocation) {
super(wsdlLocation, WSCARDLINK_QNAME);
}
public WsCardLinkService(URL wsdlLocation, WebServiceFeature... features) {
super(wsdlLocation, WSCARDLINK_QNAME, features);
}
public WsCardLinkService(URL wsdlLocation, QName serviceName) {
super(wsdlLocation, serviceName);
}
public WsCardLinkService(URL wsdlLocation, QName serviceName, WebServiceFeature... features) {
super(wsdlLocation, serviceName, features);
}
@WebEndpoint(name = "ws_card_linkPort")
public WsCardLink getWsCardLinkPort() {
return super.getPort(new QName(WS_CARD_LINK_WSDL_URL, "ws_card_linkPort"), WsCardLink.class);
}
@WebEndpoint(name = "ws_card_linkPort")
public WsCardLink getWsCardLinkPort(WebServiceFeature... features) {
return super.getPort(new QName(WS_CARD_LINK_WSDL_URL, "ws_card_linkPort"), WsCardLink.class, features);
}
private static URL getWsdlLocation() {
if (WSCARDLINK_EXCEPTION!= null) {
throw WSCARDLINK_EXCEPTION;
}
return WSCARDLINK_WSDL_LOCATION;
}
}
用户定义的模型类-1个用于请求,1个用于响应
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(namespace = "ws", name = "linkCard")
public class LinkCardRequest {
@XmlElement(name = "pan")
private String pan;
@XmlElement(name = "pCusIden")
private String pCusIden;
@XmlElement(name = "channel")
private String channel;
@XmlElement(name = "userU")
private String userId;
@XmlElement(name = "passwordU")
private String password;
// Getters and setters here
}
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "linkCardResponse")
public class LinkCardResponse {
protected String result;
// Getters and setters
}
呼叫班-
@Service
public class CardLinkImpl implements WsCardLink {
@Autowired
private WebServiceTemplate webServiceTemplate;
@Override
public String linkCard(String pan, String pCusIden, String channel, String userU, String passwordU) {
LinkCardRequest linkCardRequest = new LinkCardRequest();
linkCardRequest.setPan(pan);
linkCardRequest.setpCusIden(pCusIden);
linkCardRequest.setChannel(channel);
linkCardRequest.setUserId(userU);
linkCardRequest.setPassword(passwordU);
LinkCardResponse linkCardResponse = (LinkCardResponse) webServiceTemplate.marshalSendAndReceive(linkCardRequest);
return linkCardResponse.getResult();
}
}