package its.bgp.service;
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.axis2.AxisFault;
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;
public class Client {
private static String url = "http://webservice.webxml.com.cn/WebServices/WeatherWebService.asmx";
// 端点引用 指接口位置
private static EndpointReference targetEpr = new EndpointReference(url);
// 有抽象OM工厂获取OM工厂,创建request SOAP包
private static OMFactory fac = OMAbstractFactory.getOMFactory();
public static OMElement getOMMethod(String methodStr, String namespace,
String tns, String[] pars, String[] vals) {
// 创建命名空间
OMNamespace nms = fac.createOMNamespace(namespace, tns);
// 创建OMElement方法 元素,并指定其在nms指代的名称空间中
OMElement method = fac.createOMElement(methodStr, nms);
// 添加方法参数名和参数值
for (int i = 0; i < pars.length; i++) {
// 创建方法参数OMElement元素
OMElement param = fac.createOMElement(pars[i], nms);
// 设置键值对 参数值
param.setText(vals[i]);
// 讲方法元素 添加到method方法元素中
method.addChild(param);
}
return method;
}
public static Options getClientOptions(String action) {
// 创建request soap包 请求选项
Options options = new Options();
// 设置options的soapAction
options.setAction(action);
// 设置request soap包的端点引用(接口地址)
options.setTo(targetEpr);
// 如果报错提示Content-Length,请求内容长度
options.setProperty(HTTPConstants.CHUNKED, "false");// 把chunk关掉后,会自动加上Content-Length。
return options;
}
public static OMElement getWeather(String action, String methodStr,
String namespace, String tns, String[] pars, String[] vals) {
OMElement result = null;
try {
ServiceClient client = new ServiceClient();
client.setOptions(getClientOptions(action));
result = client.sendReceive(getOMMethod(methodStr, namespace, tns,
pars, vals));
} catch (AxisFault e) {
e.printStackTrace();
}
return result;
}
public static void main(String[] args) {
String action = "http://WebXml.com.cn/getWeatherbyCityName";
String methodStr = "getWeatherbyCityName";
String namespace = "http://WebXml.com.cn/";
String tns = "xsd";
String[] pars = { "theCityName" };
String[] vals = { "北京" };
OMElement result = null;
result = getWeather(action, methodStr, namespace, tns, pars, vals);
System.out.println(result);
}
}
分享到:
相关推荐
Axis2 webservice 客户端插件 用于集成MyEclipse
axis2-adb-1.5.6.jar axis2-kernel-1.5.6.jar axis2-transport-http-1.6.4.jar axis2-transport-local-1.6.4.jar commons-codec-1.12.jar commons-httpclient-3.1.jar commons-logging-1.2.jar httpcore-4.3.3.jar ...
Java Webservice Axis2 Client(含soapheader验证)
jar包版本axis2-1.7.6 代码可以直接运行。 jar包已经精简到最小了。不用引用那么多没用的jar包. 亲测可用。
资源包含了:axis2-1.7.4-bin.zip、axis2-1.7.4-war.zip、axis2-eclipse-...备注:资源超过了70M 分成了3部分 见axis2方式开发webservice(一)和 axis2方式开发webservice(二)、 axis2方式开发webservice(三)
axis2 webservice client端jar包 -->axis2-kernel-1.6.1.jar -->axis2-adb-1.6.1.jar -->axiom-api-1.2.12.jar -->commons-logging-1.1.1.jar -->wsdl4j-1.6.2.jar -->XmlSchema-1.4.7.jar -->axiom-impl-...
使用axis2生成的webservice客户端经常要用的依赖包,内含14个jar
资源包含了:axis2-1.7.4-bin.zip、axis2-1.7.4-war.zip、axis2-eclipse-...备注:资源超过了70M 分成了2部分 见axis2方式开发webservice(一)和 axis2方式开发webservice(二)、 axis2方式开发webservice(三)
基于axis实现的webservice客户端调用
javas客户端使用axis2调用webservice接口完整demo
axis web service client 源码
资源包含了:axis2-1.7.4-bin.zip、axis2-1.7.4-war.zip、axis2-eclipse-...备注:资源超过了70M 分成了3部分 见axis2方式开发webservice(一)和 axis2方式开发webservice(二)、 axis2方式开发webservice(三)
1)Java用axis发布/调用webservice demo;调用方式为wsdl2java生成本地client代码调用; 2)资源中包含代码和axis1.4安装文件;
axis2 开发webservice需要的完整jar,可以很好与spring进行整合
手写的axis2案例,包括服务端与客户端WebService_client、WebService_server,详细在我的博客中有记录,需要的可以自行下载
NULL 博文链接:https://sunny-java-163-com.iteye.com/blog/484526
webservice-client-call axis
NULL 博文链接:https://songjianyong.iteye.com/blog/1920078
axis-1.6.0.jar,axis-ant.jar,commons-discovery.jar,commons-logging-1.0.4.jar,jaxrpc.jar,wsdl4j-1.5.1.jar
%AXIS2_HOME%\bin\wsdl2java -uri http://localhost/axis2/services/Hello?wsdl -p client -s -o stub 其中-uri参数指定了wsdl文件的路径,可以是本地路径,也可以是网络路径。-p参数指定了生成的Java类的包名,-o...