我需要在项目中使用wsdl Web服务方法
Web服务地址为:https://sep.shaparak.ir/payments/initpayment.asmx?WSDL
我用jaxb2生成了初始代码,现在当我使用相应的方法调用webservice时,我给出了
错误:
org.springframework.ws.InvalidXmlException:无法解析XML。 嵌套的异常是org.xml.sax.SAXParseException; lineNumber:1; columnNumber:406; XML文档结构必须在其中开始和结束 同一实体。
这是我的网络服务调用方法:
ObjectFactory factory = new ObjectFactory();
requestToken requestToken = factory.createRequestToken();
requestToken.setTermID("123456");
requestToken.setTotalAmount(currentInvoice.getFinalPrice().longValueExact());
requestToken.setRedirectUrl("http://localhost/done");
requestToken.setResNum(currentInvoice.getInvoiceCode());
RequestTokenResponse r;
try {
r = (RequestTokenResponse) soapConnector
.callWebService("https://sep.shaparak.ir/payments/initpayment.asmx?WSDL", requestToken);
} catch (Exception e) {
log.debug(e.getMessage());
}
这是我的配置文件:
@Configuration
public class SEPConfig {
@Bean
public Jaxb2Marshaller marshaller() {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
// this is the package name specified in the <generatePackage> specified in
// pom.xml
marshaller.setPackagesToScan("com.sinansoft.golrizan.web.wsdl");
return marshaller;
}
@Bean
public SOAPConnector soapConnector(Jaxb2Marshaller marshaller) {
SOAPConnector client = new SOAPConnector();
client.setDefaultUri("https://sep.shaparak.ir/payments/initpayment.asmx?WSDL");
client.setMarshaller(marshaller);
client.setUnmarshaller(marshaller);
return client;
}
}
和连接器文件
import org.springframework.ws.client.core.support.WebServiceGatewaySupport;
public class SOAPConnector extends WebServiceGatewaySupport {
public Object callWebService(String url, Object request){
return getWebServiceTemplate().marshalSendAndReceive(url, request,webServiceMessage -> {
String s="";
});
}
}
有人可以告诉我我的代码或WSDL有什么问题吗?