import org.apache.cxf.transports.http.configuration.HTTPClientPolicy; //導入方法依賴的package包/類 public <T> T createSoapClient(Class<T> serviceClass, URL endpoint, String namespace) { ClientProxyFactoryBean factory = new ClientProxyFactoryBean(); Bus bus = new ExtensionManagerBus(null, null, Bus.class.getClassLoader()); factory.setBus(bus); factory.setServiceClass(serviceClass); factory.setServiceName(new QName(namespace, serviceClass.getSimpleName())); factory.setAddress(endpoint.toString()); factory.getServiceFactory().getServiceConfigurations().add(0, new XFireCompatabilityConfiguration()); factory.setDataBinding(new AegisDatabinding()); @SuppressWarnings("unchecked") T soapClient = (T) factory.create(); Client client = ClientProxy.getClient(soapClient); client.getRequestContext().put(Message.MAINTAIN_SESSION, true); HTTPClientPolicy policy = new HTTPClientPolicy(); policy.setReceiveTimeout(600000); policy.setAllowChunking(false); HTTPConduit conduit = (HTTPConduit) client.getConduit(); conduit.setClient(policy); return soapClient; }