1. 程式人生 > >axis2設置soap1.1或soap1.2協議

axis2設置soap1.1或soap1.2協議

new 報錯 block client 客戶 12c web 設置 請求

現在Axis、Axis2都是同時支持SOAP1.1和SOAP1.2的。即在服務器端發布一個WebService服務之後,客戶端既可以通過SOAP1.1版本來訪問服務器的服務,也可以通過SOAP1.2版本來訪問服務器的服務。
如果客戶端不指定SOAP版本,則無論是用Axis還是Axis2編寫的客戶端,默認使用的都是SOAP1.1版本,如果某個服務端僅支持SOAP1.2的,則在服務的交互過程中會報錯。因此較好的辦法是事先知道服務器端所支持的SOAP版本,或者通過判斷服務器端的SOAP版本,來確定使用哪個版本的SOAP發送請求。
以下將客戶端指定的SOAP協議版本代碼整理一下,以備以後查閱。
Axis:
org.apache.axis.client.Service service = new org.apache.axis.client.Service();
org.apache.axis.client.Call call = service.createCall();
//默認版本為SOAP1.1
//以下設置為SOAP1.2
call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP12_CONSTANTS);
//以下設置為SOAP1.1
call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);
//其他設置和調用代碼
//call.setXXX(...)
//call.invoke(...)
Axis2:
org.apache.axis2.rpc.client.RPCServiceClient serviceClient = new org.apache.axis2.rpc.client.RPCServiceClient();
org.apache.axis2.client.Options options = serviceClient.getOptions();
//默認版本為SOAP1.1
//以下設置為SOAP1.2
options.setSoapVersionURI(org.apache.axiom.soap.SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
//以下設置為SOAP1.1
options.setSoapVersionURI(org.apache.axiom.soap.SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
//其他設置和調用代碼
//options.setXXX(...)
//serviceClient.invokeBlocking(...)

通過wsdl2java 命令 生成的stub客戶端 設置soap協議
//以下設置為SOAP1.2
options.setSoapVersionURI(org.apache.axiom.soap.SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
xxxStub._getServiceClient().getOptions().setSoapVersionURI(org.apache.axiom.soap.SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
//以下設置為SOAP1.1
xxxStub._getServiceClient().getOptions().setSoapVersionURI(org.apache.axiom.soap.SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);

axis2設置soap1.1或soap1.2協議