热门标签 | HotTags
当前位置:  开发笔记 > 运维 > 正文

org.apache.axis2.AxisFault:Transporterror:411Error:Leng

packageaxiom;importjava.util.Date;importorg.apache.axiom.om.OMAbstractFactory;importorg.apache.axiom.om.OMElement;importorg.apache.axiom.om.OMFactory;importorg.apache.axiom.om.OMNamespace;importorg.apache.axiom.soap.SOAP11Cons

package axiom; import java.util.Date; 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.SOAP11Cons

package axiom;

import java.util.Date;

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.AxisFault;
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;

public class WeatherAxiomClient {

private static EndpointReference targetEPR =
new EndpointReference(
"http://www.webxml.com.cn/WebServices/WeatherWebService.asmx");

private static OMFactory fac = OMAbstractFactory.getOMFactory();

public static void main(String args[]) throws AxisFault{
Date start=new Date();
System.out.println("start:"+start);
ServiceClient sender = new ServiceClient();
sender.setOptions(buildOptions());
OMElement result = sender.sendReceive(buildParam());
System.out.println(result);
Date end=new Date();
System.out.println("end:"+end);
System.out.println("between:"+(end.getTime()-start.getTime()));
}
public static OMElement buildParam() {
OMNamespace omNs = fac.createOMNamespace("http://WebXml.com.cn/", "tns");
OMElement data = fac.createOMElement("getSupportCity", omNs);
OMElement inner = fac.createOMElement("byProvinceName", omNs);
inner.setText("All");
data.addChild(inner);
return data;

}

public static Options buildOptions(){
Options optiOns= new Options();
options.setSoapVersionURI(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
options.setAction("http://WebXml.com.cn/getSupportCity");
options.setTo(targetEPR);
options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
// options.setProperty(HTTPConstants.CHUNKED, "false");//设置不受限制.
options.setProperty(HTTPConstants.PROXY, buildProxy());
return options;

}
public static ProxyProperties buildProxy(){
ProxyProperties proxyProperties=new ProxyProperties();
proxyProperties.setProxyName("172.19.18.22");
proxyProperties.setProxyPort(8080);
return proxyProperties;
}


}
点评:这里有一点要注意的是,当采用axiom进行服务端webservice调用时,http会受限制,所以以上注释的地方必需加上,就可以访问了

推荐阅读
author-avatar
你的美丽来自我的设计
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有