---
title: "通过代理调用webservice服务"
author: "Jophy"
date: "2009-08-06T10:57:26Z"
tags: []
slug: "webservice"
draft: false
lastmod: "2009-08-06T10:58:22Z"
id: 441372
url: "https://jophy.iteye.com/blog/441372"
---

由于最近有客户需通过webservice接入我们这边的系统（Axis21.3），以前给接入包不行，问了客户那边的情况才知道他们那边是内网通过代理访问外网的。
以前的client是通过插件自动生成的，所以直接在生成的stub类里面加上配置代理的参数就ok

```java

/**
     * Constructor that takes in a configContext  and useseperate listner
     */
public MessageTransportServiceStub(org.apache.axis2.context.ConfigurationContext configurationContext,
        java.lang.String targetEndpoint, boolean useSeparateListener)
        throws org.apache.axis2.AxisFault {
         //To populate AxisService
         populateAxisService();
         populateFaults();

        _serviceClient = new org.apache.axis2.client.ServiceClient(configurationContext,_service);
        
	
        configurationContext = _serviceClient.getServiceContext().getConfigurationContext();

        _serviceClient.getOptions().setTo(new org.apache.axis2.addressing.EndpointReference(
                targetEndpoint));
        _serviceClient.getOptions().setUseSeparateListener(useSeparateListener);
//以下为通过配置文件判断是否使用代理，有使用的话设置参数
        Configuration config=new Configuration();
        if (config.getValue("isproxy").equals("true")) {
        	ProxyProperties proxyProperties=new ProxyProperties();
            proxyProperties.setProxyName(config.getValue("host"));
            proxyProperties.setProxyPort(Integer.valueOf(config.getValue("port")));
            proxyProperties.setDomain(config.getValue("domain"));
            
            	proxyProperties.setUserName(config.getValue("username"));
		
         
           proxyProperties.setPassWord(config.getValue("userpassword"));

            _serviceClient.getOptions().setProperty(HTTPConstants.PROXY, proxyProperties);
            _serviceClient.getOptions().setProperty(HTTPConstants.HTTP_PROTOCOL_VERSION, HTTPConstants.HEADER_PROTOCOL_10);
		}
    
    }

```

webservice是通过http端口走的，所以代理应该提供http端口，一开始客户提供了socks5端口，害的测试n久都没通过