在eclipse中用Axis1.4的插件生成的代碼默認(rèn)使用HTTP/1.0版本,并且在請求頭中不包含Connection:keep-Alive
每次通信前都要新建連接,通信結(jié)束后關(guān)閉連接
當(dāng)請求量很大時,將頻繁的創(chuàng)建、關(guān)閉連接,十分消耗性能,所以考慮使用HTTP長連接
HTTP/1.1默認(rèn)使用持久連接(HTTP/1.1逐漸停止了對Keep-Alive的支持,用一種名為持久連接的改進(jìn)型設(shè)計(jì)取代了它,持久連接與Keep-Alive的目的相同,但工作機(jī)制更優(yōu)),并且只修改HTTP版本比較簡單,所以只需將HTTP的版本從1.0升級至1.1即可
原代碼(自動生成的Proxy代理類):
- private void _initSPSSubscriberProvisioningServiceProxy() {
- try {
- sPSSubscriberProvisioningService_PortType = new SPSSubscriberProvisioningService_ServiceLocator()
- .getSPSSubscriberProvisioningService();
- if (sPSSubscriberProvisioningService_PortType != null) {
- if (_endpoint != null)
修改后的代碼:
- private void _initSPSSubscriberProvisioningServiceProxy() {
- try {
- EngineConfiguration defaultConfig = EngineConfigurationFactoryFinder.newFactory().getClientEngineConfig();
- SimpleProvider config = new SimpleProvider(defaultConfig);
- config.deployTransport(HTTPTransport.DEFAULT_TRANSPORT_NAME,new CommonsHTTPSender());
- serviceLocator = new SPSSubscriberProvisioningService_ServiceLocator(config);
- sPSSubscriberProvisioningService_PortType = serviceLocator.getSPSSubscriberProvisioningService();
使用CommonsHTTPSender代理默認(rèn)的HTTPSender,該類包含在axis-1.4.jar中,不需要添加額外的jar包
可以看到HTTP的版本已經(jīng)變?yōu)?.1,并且在每次通信結(jié)束后,并不會關(guān)閉連接