12,162
社区成员
发帖
与我相关
我的任务
分享
package ws;
import javax.xml.namespace.QName;
import org.apache.axiom.soap.SOAP11Constants;
import org.apache.axiom.soap.SOAP12Constants;
import org.apache.axis2.AxisFault;
import org.apache.axis2.Constants;
import org.apache.axis2.addressing.AddressingConstants;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.addressing.RelatesTo;
import org.apache.axis2.client.Options;
import org.apache.axis2.rpc.client.RPCServiceClient;
public class WebServiceTest {
/**
* @param args
*/
public static void main(String[] args)throws AxisFault {
Object[] opAddEntryArgs = new Object[] {"100000260032","4832"};
// String url="http://r2-sv0038.connecteast.local/ETollingPortal2AbstractionServiceIVR/AccountBalance.svc?wsdl";
String url="http://r2-sv0038.connecteast.local/ETollingPortal2AbstractionServiceIVR/AccountBalance.svc";
//url="http://www.w3.org/2005/08/addressing/anonymous.";
String method="GetAccountBalance1";
WebServiceTest.sendService(opAddEntryArgs,url,method);
}
public static String sendService(Object[] opAddEntryArgs,String url,String method) throws AxisFault{
String xml=null;
RPCServiceClient serviceClient = new RPCServiceClient();
//serviceClient.engageModule(new javax.xml.namespace.QName( org.apache.axis2.Constants.MODULE_ADDRESSING ) );
Options options = serviceClient.getOptions();
//这里设置使用soap1.2,wcf用的是wshttpbinding 使用的也是soap1.2 貌似axis默认使用soap1.1。
//否则会报Exception in thread "main" org.apache.axis2.AxisFault: Transport error: 415 Error:
//Cannot process the message because the content type 'text/xml; charset=UTF-8'
//was not the expected type 'application/soap+xml; charset=utf-8'.的错误
options.setSoapVersionURI(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);//
EndpointReference targetEPR = new EndpointReference(url);
options.setTo(targetEPR);
options.setTimeOutInMilliSeconds((long)600000);
//options.setProperty(Constants.Configuration.ENABLE_SWA, Constants.VALUE_TRUE);
// 在创建QName对象时,QName类的构造方法的第一个参数表示WSDL文件的命名空间名,也就是<wsdl:definitions>元素的targetNamespace属性值
QName opAddEntry = new QName("http://tempuri.org/",method);
// 参数,如果有多个,继续往后面增加即可,不用指定参数的名称
////Object[] opAddEntryArgs = new Object[] {xmlStr};
// 返回参数类型,这个和axis1有点区别
// invokeBlocking方法有三个参数,其中第一个参数的类型是QName对象,表示要调用的方法名;
// 第二个参数表示要调用的WebService方法的参数值,参数类型为Object[];
// 第三个参数表示WebService方法的返回值类型的Class对象,参数类型为Class[]。
// 当方法没有参数时,invokeBlocking方法的第二个参数值不能是null,而要使用new Object[]{}
// 如果被调用的WebService方法没有返回值,应使用RPCServiceClient类的invokeRobust方法,
// 该方法只有两个参数,它们的含义与invokeBlocking方法的前两个参数的含义相同
Class[] classes = new Class[] { String.class };
xml=(String)serviceClient.invokeBlocking(opAddEntry,opAddEntryArgs, classes)[0];
System.out.println(xml);
return xml;
}
}
TripPassServiceStub tpss=new TripPassServiceStub();
tpss._getServiceClient().engageModule("addressing");
tpss._getServiceClient().getOptions().setProperty(AddressingConstants.WS_ADDRESSING_VERSION, org.apache.axis2.addressing.AddressingConstants.Final.WSA_NAMESPACE);
int setWebServiceTimeOutInSeconds=mySession.getVariable(IProjectVariables.SET_WEB_SERVICE_TIME_OUT_IN_SECONDS).getSimpleVariable().getIntValue();
tpss._getServiceClient().getOptions().setTimeOutInMilliSeconds(setWebServiceTimeOutInSeconds*1000);
tpss._getServiceClient().getOptions().setProperty(HTTPConstants.REUSE_HTTP_CLIENT,true);
tpss._getServiceClient().getOptions().setProperty(HTTPConstants.CHUNKED, "false");//设置不受限制.