Java动态调用WebService方法

突然之间.WSDL2JAVA不能认Delphi写的WebSerice生成的WSDL了.于是才开始看看如何动态调用, 其实这里的代码都是从JBuilderX的WSDL2JAVA中自动生成的stub作参考的.

    OperationDesc opd  =   new  OperationDesc();
    opd.setName(
" AttemperFiberPairChannel " );
    opd.addParameter(
new  QName( " aStartID " ), XMLType.XSD_INT,  int . class ,
        ParameterDesc.IN, 
false false );
    opd.addParameter(
new  QName( " aStartType " ), XMLType.XSD_STRING, String. class ,
        ParameterDesc.IN, 
false false );
    opd.addParameter(
new  QName( " aEndID " ), XMLType.XSD_INT,  int . class ,
        ParameterDesc.IN, 
false false );
    opd.addParameter(
new  QName( " aEndType " ), XMLType.XSD_STRING, String. class ,
        ParameterDesc.IN, 
false false );
    opd.setReturnType(
new  QName( " string " ));
    opd.setReturnClass(String.
class );
    opd.setReturnQName(
new  QName( "" " return " ));

    Service service 
=   new  Service();
    Call call 
=  (Call) service.createCall();
    call.setOperation(opd);
    call
        .setTargetEndpointAddress(
" http://localhost/WebService/NormalResourceAttemperok/SOAP/INormalResourceAttemper " );
    call.setOperationName(
new  QName(
        
" urn:NormalResourceAttemperIntf-INormalResourceAttemper " ,
        
" AttemperFiberChannel " ));
    call
        .setSOAPActionURI(
" urn:NormalResourceAttemperIntf-INormalResourceAttemper#AttemperFiberChannel " );
    Object rsl 
=  call.invoke( new  Object[] {调用的参数});

  if (rsl instanceof RemoteException) {
       throw (RemoteException) rsl;
  } else {
     将其转化为你要的对象.这里就是String对象.
  }


里面的urn部分可以从wsdl里得到, 返回的对象可能是远程异常哦.

你可能感兴趣的:(java,webservice,String,service,Class,Delphi)