(转)axis2连接属性设置

原文: http://www.blogjava.net/fuyujianxia/archive/2008/05/13/147870.html

前些天做了一个小系统用到webservice, 只有客户端  (外网的servcice),  公司的网络环境是采用代理上网.

走了好多弯路才调通,    现在分享一下,  希望能对在这方面感到困惑的朋友有一点帮助.

我采用的框架是axis2.


 //options用来包容客户端的各种设置

 Options options = new Options();

//设置地址
        options.setTo(
                new EndpointReference(address));

//设置服务端认证.  , 开始的时候没有设host和domain,   认证通不过,  生成的http header 中也没有认证信息.  搞了好半天才发现必须设置主机和域名(服务器端的)
        HttpTransportProperties.Authenticator auth=new HttpTransportProperties.Authenticator();
        auth.setUsername("Administrator");
        auth.setPassword("2222");
        auth.setHost("test.xxx.com");
        auth.setDomain("test.xxxx.com");

        options.setProperty(HTTPConstants.AUTHENTICATE, auth);
 
        options.setAction("Execute");
        
//必须设置http version为1.0,  这样客户端的代理属性才起作用.
        options.setProperty(HTTPConstants.HTTP_PROTOCOL_VERSION,
           HTTPConstants.HEADER_PROTOCOL_10);

        //proxy settings
        ProxyProperties proxyProperties=new ProxyProperties();
        proxyProperties.setProxyName("PROXYSERVER");
        proxyProperties.setProxyPort(8080);
        proxyProperties.setUserName("luyanbo");
        proxyProperties.setPassWord("sand");
        proxyProperties.setDomain("sand.cn");
       
        options.setProperty(HTTPConstants.PROXY, proxyProperties);
    
        ServiceClient servicClient = new ServiceClient();
        servicClient.setOptions(options);
        
//发送并接收
        OMElement result = servicClient.sendReceive(getAuthXml());

用的过程中, 发现axis2的文档实在太粗略了, 很多不该省略的地方也省了,  像代理属性设置里面,  http版本的设置就没有提到. 可能他们也是发扬风格. 怎么省事怎么来的吧

猜你喜欢

转载自cjb.iteye.com/blog/1539523