赞
踩
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web-services</artifactId>
</dependency>
-新建webservice接口
@Component
@WebService(name = "InvoiceWebService", targetNamespace = WsConst.INVOICE_NAMESPACE_URI)
public interface InvoiceWebService {
/**
* @param invData 参数
* @return 返回处理数据
*/
@WebMethod(action = WsConst.INVOICE_NAMESPACE_URI + "/PaperOutputInvoice", operationName = "PaperOutputInvoice")
@WebResult(name = "PaperOutputInvoiceResult", targetNamespace = WsConst.INVOICE_NAMESPACE_URI)
public String PaperOutputInvoice(@WebParam(name = "invData", targetNamespace =
WsConst.INVOICE_NAMESPACE_URI) String invData) throws ServiceException, MalformedURLException, RemoteException;
}
@Configuration @WebService( // 与接口中指定的name一致 serviceName = "InvoiceWebService", // 与接口中的命名空间一致,一般是接口的包名倒 targetNamespace = WsConst.INVOICE_NAMESPACE_URI , // 接口地址 endpointInterface = "com.juneyaoair.soapserver.service.InvoiceWebService" ) public class InvoiceWebServiceImpl implements InvoiceWebService { private static final Logger logger = LoggerFactory.getLogger(InvoiceWebServiceImpl.class); @Value("${sop.invoice.web.service.endpoint}") private String endpoint; @Override public String PaperOutputInvoice(@WebParam(name = "invData", targetNamespace = WsConst.INVOICE_NAMESPACE_URI) String invData) throws ServiceException, MalformedURLException, RemoteException { logger.info("入参参数invData==========>:" + invData); } }
@Configuration public class WebConfig { @Autowired private Bus bus; @Autowired InvoiceWebService invoiceWebService; /** * 接口发布 * @return 返回 */ @Bean public Endpoint invoiceEndpoint() { EndpointImpl endpoint = new EndpointImpl(bus, invoiceWebService); System.out.println("---------------------------接口发布开始---------------------------------------"); endpoint.publish("/InvoiceWebService"); System.out.println("---------------------------接口发布成功---------------------------------------"); return endpoint; } }
http://localhost:8000/services


// 调用过程
Service service = new Service();
Call call = (Call) service.createCall();
// 设置接口地址
call.setTargetEndpointAddress(new URL(endpoint));
// 设置方法名称
call.setOperationName(new QName( "http://tempuri.org/","PaperOutputInvoice"));
// 操作的参数
call.addParameter(new QName("http://tempuri.org/","invData"), XMLType.XSD_STRING, ParameterMode.IN);
// 设置返回类型
call.setReturnType(XMLType.XSD_STRING);
call.setUseSOAPAction(true);
// 给方法传递参数,并且调用方法
Object[] obj = new Object[] {"{\"InvInfoList\":"+json2 + "}"};
String result = (String) call.invoke(obj);
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。