Axis调用webservice查看手机信息(固定号码)
2011-07-11 11:10
417 查看
1. 下载axis2. 在myeclipse下建立一个web project 项目
把axis下的lib包导入到项目中的lib中间去。
3. 创建一个javabean TelephoneAxis.java
代码如下:
package com.tools; import org.apache.axiom.om.OMAbstractFactory; import org.apache.axiom.om.OMElement; import org.apache.axiom.om.OMFactory; import org.apache.axiom.om.OMNamespace; import org.apache.axiom.soap.SOAP11Constants; import org.apache.axis2.Constants; import org.apache.axis2.addressing.EndpointReference; import org.apache.axis2.client.Options; import org.apache.axis2.client.ServiceClient; import org.apache.axis2.transport.http.HTTPConstants; import org.apache.axis2.transport.http.HttpTransportProperties.ProxyProperties; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; public class TelephoneAxis { private static EndpointReference targetEPR = new EndpointReference( "http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx"); public void getResult() throws Exception { String s = null; ServiceClient sender = new ServiceClient(); sender.setOptions(buildOptions()); OMElement result = sender.sendReceive(buildParam()); s = result.getFirstElement().getText(); System.out.println(s); } private static OMElement buildParam() { OMFactory fac = OMAbstractFactory.getOMFactory(); OMNamespace omNs = fac.createOMNamespace("http://WebXml.com.cn/", ""); OMElement data = fac.createOMElement("getMobileCodeInfo", omNs); OMElement inner = fac.createOMElement("mobileCode", omNs); inner.setText("15874333***"); data.addChild(inner); return data; } private static Options buildOptions() { Options options = new Options(); options.setSoapVersionURI(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI); options.setAction("http://WebXml.com.cn/getMobileCodeInfo"); options.setTo(targetEPR); //options.setProperty 如果不是通过代理上网,此句可省 //options.setProperty(HTTPConstants.PROXY, buildProxy()); options.setTransportInProtocol(Constants.TRANSPORT_HTTP); return options; } /** * 本机采用代理服务器上网时,需要设置代理 * @return public static ProxyProperties buildProxy() { ProxyProperties proxyProperties = new ProxyProperties(); proxyProperties.setProxyName("代理名称"); proxyProperties.setProxyPort(8080); return proxyProperties; } */ public static void main(String[] args) throws Exception { TelephoneAxis s = new TelephoneAxis(); s.getResult(); } }
4. 大功告成。 如果需要动态输入电话号码 可以加入一个index.jsp 页面 。
5. 待续 。。。。。
相关文章推荐
- Java调用WEBSERVICE接口实现天气预报和获得国内手机号码归属地省份、地区和手机卡类型信息
- Axis调用webservice查看天气情况(固定地区)
- 调用webservice查询手机号码归属地信息
- 调用WebService查看QQ号码状态
- Android手机端调用webservice来获得手机归属地号码
- 4、调用WebService查询手机号码归宿地
- Android手机端调用webservice来获得手机归属地号码
- 在Android中调用WebService查询手机号码归属地。
- 调用WebService查看QQ号码状态
- 调用WebService查看QQ号码状态
- 调用手机号码归属地接口获取手机号码信息
- 调用WebService查看QQ号码状态
- WebService1.5-调用手机号码归属地
- java 用webservice 获取国内手机号码归属地省份、地区和手机卡类型信息
- WebService之获取手机号码信息
- 手机号码界面输入数字查看手机信息
- android---webservice 查询 手机号码信息(四)
- 调用手机在线API获取手机号码归属地信息
- 调用WebService查看QQ号码状态
- Java调用免费的WebService示例【天气预报】【国内手机号码归属地查询】