Heim  >  Artikel  >  Datenbank  >  org.apache.axis2.AxisFault: Transport error: 411 Error: Leng

org.apache.axis2.AxisFault: Transport error: 411 Error: Leng

WBOY
WBOYOriginal
2016-06-07 15:27:361359Durchsuche

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会受限制,所以以上注释的地方必需加上,就可以访问了

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn