WebService客户端,接收数据解析存入数据库

WebService客户端,实现的功能是接收数据,按格式解析数据,最后存入相应数据库。

需求:

同步设备信息接口

url::54059/Service1.asmx

函数名:GetDevConfigInfo

参数:无

返回值:string

返回值格式:

设备编号,设备名称,设备类型,设备IP,设备端口号,设备位置,安装时间;设备编号,设备名称,,设备类型,设备IP,设备端口号,设备位置,安装时间;

思路分析:通过WSDL文件生成客户端Client,通过客户端Client得到数据流。Dao层实现对数据流的解析和把数据插入数据库的功能。Servive层调用Client和Dao实现把接收的数据解析存入数据库的功能。Controller层做了一个按钮触发,点击按钮执行Service。

导入WSDL文件

File—New—Other—Web Service Client

两种方式导入WSDL文件。如果有.wsdl源文件可以通过WSDL File选取源文件路径;或者选取WSDL URL。

点击Next—-再点击Finish

WSDL文件

<?xml version="1.0" encoding="utf-8"?><wsdl:definitions xmlns:soap="" xmlns:tm="" xmlns:soapenc="" xmlns:mime="" xmlns:tns="itarge-park" xmlns:s="" xmlns:soap12="" xmlns:http="" targetNamespace="itarge-park" xmlns:wsdl=""> <wsdl:types><s:schema elementFormDefault="qualified" targetNamespace="itarge-park"><s:element name="GetDevConfigInfo"><s:complexType /></s:element><s:element name="GetDevConfigInfoResponse"><s:complexType><s:sequence><s:element minOccurs="0" maxOccurs="1" name="GetDevConfigInfoResult" type="s:string" /></s:sequence></s:complexType></s:element></s:schema> </wsdl:types> <wsdl:message name="GetDevConfigInfoSoapIn"><wsdl:part name="parameters" element="tns:GetDevConfigInfo" /> </wsdl:message> <wsdl:message name="GetDevConfigInfoSoapOut"><wsdl:part name="parameters" element="tns:GetDevConfigInfoResponse" /> </wsdl:message> <wsdl:portType name="Service1Soap"><wsdl:operation name="GetDevConfigInfo"><wsdl:documentation xmlns:wsdl="">This method get all dev config from databases;</wsdl:documentation><wsdl:input message="tns:GetDevConfigInfoSoapIn" /><wsdl:output message="tns:GetDevConfigInfoSoapOut" /></wsdl:operation> </wsdl:portType> <wsdl:binding name="Service1Soap" type="tns:Service1Soap"><soap:binding transport="" /><wsdl:operation name="GetDevConfigInfo"><soap:operation soapAction="itarge-park/GetDevConfigInfo" style="document" /><wsdl:input><soap:body use="literal" /></wsdl:input><wsdl:output><soap:body use="literal" /></wsdl:output></wsdl:operation> </wsdl:binding> <wsdl:binding name="Service1Soap12" type="tns:Service1Soap"><soap12:binding transport="" /><wsdl:operation name="GetDevConfigInfo"><soap12:operation soapAction="itarge-park/GetDevConfigInfo" style="document" /><wsdl:input><soap12:body use="literal" /></wsdl:input><wsdl:output><soap12:body use="literal" /></wsdl:output></wsdl:operation> </wsdl:binding> <wsdl:service name="Service1"><wsdl:port name="Service1Soap" binding="tns:Service1Soap"><soap:address location=":54059/Service1.asmx" /></wsdl:port><wsdl:port name="Service1Soap12" binding="tns:Service1Soap12"><soap12:address location=":54059/Service1.asmx" /></wsdl:port> </wsdl:service></wsdl:definitions>

客户端 GetDevConfigClient.java

package com.cnc.park.client;import itarge_park.Service1Soap;import org.apache.cxf.interceptor.LoggingInInterceptor;import org.apache.cxf.interceptor.LoggingOutInterceptor;import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;import org.springframework.beans.factory.annotation.Autowired;import com.cnc.park.service.DeviceClientService;/** * author:zhangxuan*/public class GetDevConfigClient {@Autowiredprivate DeviceClientService deviceClientService;public static String get() {JaxWsProxyFactoryBean factoryBean=new JaxWsProxyFactoryBean();factoryBean.getInInterceptors().add(new LoggingInInterceptor());factoryBean.getOutInterceptors().add(new LoggingOutInterceptor());factoryBean.setServiceClass(Service1Soap.class);factoryBean.setAddress(":54059/Service1.asmx");Service1Soap impl=(Service1Soap) factoryBean.create();String result = impl.getDevConfigInfo();// String result = "0001,测试1,1,10.1.1.1,1111,1,2015-03-23 11:11:11;0002,测试2,2,10.2.2.2,2222,2,2015-03-23 22:22:22;";测试用return result;}}上天完全是为了坚强你的意志,才在道路上设下重重的障碍。

WebService客户端,接收数据解析存入数据库

相关文章:

你感兴趣的文章:

标签云: