微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Axis2 调用 流程

Axis2看了一些资料 自己总结下

客户端调用接口流程:首先是先

 // 创建request SOAP包工厂 fac。 创建 请求soap 包的工厂
    private static OMFactory fac = OMAbstractFactory.getoMFactory();

//先通过fac工厂 创建 sopa的 命名空间,"tns" 有看别人提到过说是服务名,但是"" 或者填任何都可以,只要不和//已经的变量名重复,如果和调用接口 重复会报错,提示已存在

OMNamespace omNs = fac.createOMNamespace("http://WebXml.com.cn/","tns");

  //再通过fac工厂 创建 所需要 请求方法OMElement  对象

String methodName = "getWeatherbyCityName";//调用方法

OMElement  method = fac.createOMElement(methodName,omNs);

//然后 给 方法对象 添加方法参数名称 和请求的参数值

String[] args = new String[]{"theCityName"};

String city = "杭州";

String[] vals = new String[]{"city"};

for(int i=0;i<args.length;i++){

    OMNamespace params = fac.createOMNamespace(args[i],omNs);

     params.setText(vals[i]);

     method.addChild(params);

}

//创建 端点引用 EndpointReference 实例对象。并对EndpointReference设置private static EndpointReference targetEpr = new EndpointReference(url);

url为 String url = "http://webservice.webxml.com.cn/WebServices/WeatherWebService.asmx";  是webservice 接口地址。

//然后创建ServiceClient 客户端对象

ServiceClient  client  = new ServiceClient ();

//创建ServiceClient  对象client  的 Options选项

Options options = new Options();

options.setTo(targetEpr);

//在options中设置SOAP包的Action          SOAPAction

String SOAPAction = "http://WebXml.com.cn/getWeatherbyCityName";

options.setAction(SOAPAction);

//options.setProperty(HTTPConstants.CHUNKED,"false");//设置不受限制.  这个据说是不受限制 至少我没遇到要添加这个

//然后给客户端设置opition选项

client .setoptions(options);

//调用接口方法

OMElement result = client.sendReceive(method);

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐