java的webservice实现有多种方式,可用的工具也有一些。之前对这块的只是比较缺乏,以至于一上来就一直看spring webservice.花费了几天后发现和要用的功能不符,就···
当前学习的需求是webservice client。因此整篇文章用来说明java webserviceclient的创建过程。
首先使用java自带的soapconnection实现。那首先具体的client访问流程为
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
SOAPConnection connection = null ; try {
SOAPConnectionFactory sfc = SOAPConnectionFactory.newInstance(); connection = sfc.createConnection(); SOAPMessage soapMessage = ObjectToSoapXml(object, nsMethod, nsName); URL endpoint = new URL( new URL(url), "" , new URLStreamHandler() {
@Override protected URLConnection openConnection(URL url) throws IOException {
URL target = new URL(url.toString()); URLConnection connection = target.openConnection(); // Connection settings connection.setConnectTimeout( 120000 ); // 2 min connection.setReadTimeout( 60000 ); // 1 min return (connection); } }); SOAPMessage response = connection.call(soapMessage, endpoint); |