利用idea生成webservice客户端超详解步骤(wsdl文件的使用)

  import org.apache.axiom.om.OMAbstractFactory;

  import org.apache.axiom.om.OMElement;

  import org.apache.axiom.om.OMFactory;

  import org.apache.axiom.om.OMNamespace;

  import org.apache.axis2.AxisFault;

  import org.apache.axis2.addressing.EndpointReference;

  import org.apache.axis2.client.Options;

  import org.apache.axis2.rpc.client.RPCServiceClient;

  public class Test {

  public static void test() {

  String userId = "123";

  String bindAccount = "123";

  RPCServiceClient serviceClient = null;

  OMFactory factory = OMAbstractFactory.getOMFactory();

  OMNamespace omDiag = factory.createOMNamespace("http://diagnosis.interfaces.axis2.osf.nort hbound.neal.cpehg.ums.zte.com", "diag");

  OMNamespace omXSD = factory.createOMNamespace("http://model.common.northbound.neal.cpehg. ums.zte.com/xsd", "xsd");

  try {

  serviceClient = new RPCServiceClient();

  Options options = serviceClient.getOptions();

  // 指定调用WebService的URL

  EndpointReference targetEPR = new EndpointReference("http://10.46.60.200:9094/axis2/services/Cpe112Diag nosisWebServices?wsdl");

  options.setTo(targetEPR);

  options.setTimeOutInMilliSeconds(30000);

  options.setManageSession(true);

  // 指定方法的参数值

  OMElement paramRequest = factory.createOMElement("request", omDiag);

  OMElement paramUserId = factory.createOMElement("userID", omXSD);

  paramUserId.setText(userId);

  OMElement paramBindAccount = factory.createOMElement("bindAccount", omXSD);

  paramBindAccount.setText(bindAccount);

  paramRequest.addChild(paramBindAccount);

  paramRequest.addChild(paramUserId);

  OMElement paramItemName = factory.createOMElement("itemName", omDiag);

  paramItemName.setText("cpehg.diagnosis.CpeBasicInfo");

  String method = "getParameterValuesFromDbAndCpeByItemName";

  OMElement data = factory.createOMElement(method, omXSD);

  data.setNamespace(omDiag);

  data.addChild(paramRequest);

  data.addChild(paramItemName);

  OMElement re = serviceClient.sendReceive(data);

  // 处理返回数据

  } catch (AxisFault e) {

  // 异常处理

  e.printStackTrace();

  } finally {

  try {

  if (serviceClient != null) serviceClient.cleanupTransport();

  } catch (AxisFault e) {

  }

  }

  }

  }