1. 程式人生 > >利用axis呼叫webservice介面

利用axis呼叫webservice介面

一.首先把wsdl檔案放入eclipse中某個專案中的src目錄下

二.右鍵彈出webservice,然後點選webservice選單,選中genernator client ,選擇axis生成Java檔案

三,然後呼叫.

呼叫說明(其中一種的呼叫方式):

DHSFServiceLocator service = new DHSFServiceLocator();
  service.setDH_spcSF_spcIntegration_spcServiceWSDDServiceName("AccountCreate");
  URL url;
  String accountCode="";
  String JsonData = "{\"accountName\":\"D15422312\",\"accountID\":\"0010k00000PtIXV\",\"accountSource\":\"DP\",\"customerProperty\":\"OEM\",\"region\":\"Europe\",\"country\":\"GB\",\"province\":\"Leicester\","
    + "\"city\":\"Leicester\",\"address\":\"BUDAN STREET\",\"owner\":\"13578\",\"industry\":\"Transportation\",\"accountType\":\"Distributor\",\"purchaseTotal\":\"1000\",\"description\":\"test\",\"busCountry\":\"GB\",\"marketScope\":\"GB;AU\",\"AccountCode\":\"\",\"RegistrationNumber\":\"2356123\",\"OverseaDegree\":\"S\", \"BusEntry\":\"Dahua Hongkong; Dahua technology\", \"BringReason\" :\"Leadcovert\",\"ClientTradeNames1\":\"test1\",\"ClientTradeNames2\":\"test2\",\"ValueOEM\":\"Strategy Guide\", \"DegreeOEM\":\"Depth\",\"PurchaseTotalBrand\":\"\","+
    "\"PurchaseTotalOEM\":\"2345\",\"Sharer\":\"24815;29480\",\"UpdateType\":\"0\",\"ChangeID\":\"\",\"AccountLanguage\":\"\",\"accountStatus\":\"0\",\"AttachmentURL\":\"www.baidu.com\"}";
  JSONObject jsonObject =JSONObject.fromObject(JsonData);
  
  StringHolder error_spcCode = new StringHolder("");
  StringHolder error_spcMessage = new StringHolder("");
  
  String accountName = jsonObject.getString("accountName");
  String sFAccountId = jsonObject.getString("accountID");
  String accountSource = jsonObject.getString("accountSource");
  String customerProperty = jsonObject.getString("customerProperty");
  String region = jsonObject.getString("region");
  String country = jsonObject.getString("country");
  String province = jsonObject.getString("province");
  String city = jsonObject.getString("city");
  String address = jsonObject.getString("address");
  String owner = jsonObject.getString("owner");
  String industry = jsonObject.getString("industry");
  String accountType = jsonObject.getString("accountType");
  String purchaseTotal = jsonObject.getString("purchaseTotal");
  String description = jsonObject.getString("description");
  String busCountry = jsonObject.getString("busCountry");
  String marketScope = jsonObject.getString("marketScope");   String AccountCode=jsonObject.getString("AccountCode");
  String RegistrationNumber=jsonObject.getString("RegistrationNumber");
  String OverseaDegree=jsonObject.getString("OverseaDegree");
  String BusEntry=jsonObject.getString("BusEntry");
  String BringReason=jsonObject.getString("BringReason");
  String ClientTradeNames1=jsonObject.getString("ClientTradeNames1");
  String ClientTradeNames2=jsonObject.getString("ClientTradeNames2");
  String ValueOEM=jsonObject.getString("ValueOEM");
  String DegreeOEM=jsonObject.getString("DegreeOEM");
  String PurchaseTotalBrand=jsonObject.getString("PurchaseTotalBrand");
  String PurchaseTotalOEM=jsonObject.getString("PurchaseTotalOEM");
  String Sharer=jsonObject.getString("Sharer");
  String UpdateType=jsonObject.getString("UpdateType");
  String ChangeID=jsonObject.getString("ChangeID");
  String AccountLanguage=jsonObject.getString("AccountLanguage");//客戶語言
  String accountStatus=jsonObject.getString("accountStatus");//客戶狀態
  String AttachmentURL=jsonObject.getString("AttachmentURL");//客戶附件
  
  try {
   //wsdl中的服務地址.(wsdl檔案)
   url = new URL("http://10.1.1.204:7777/eai_chs/start.swe?SWEExtSource=WebService&SWEExtCmd=Execute&Username=SADMIN&Password=Cde32wsx");
   DH_spcSF_spcIntegration_spcServiceStub stub = new DH_spcSF_spcIntegration_spcServiceStub(url,service); //呼叫物件中的方法
   accountCode=stub.accountCreate(accountName, sFAccountId, accountSource,customerProperty, region, country, province, city,address, owner, industry, accountType, purchaseTotal, description,  busCountry, marketScope,AccountCode,RegistrationNumber,OverseaDegree,BusEntry,BringReason,ClientTradeNames1,ClientTradeNames2,ValueOEM,DegreeOEM,PurchaseTotalBrand,PurchaseTotalOEM,Sharer,UpdateType,ChangeID,AccountLanguage,accountStatus,AttachmentURL,error_spcCode, error_spcMessage);       if(null==accountCode||"".equals(accountCode)){
       error_spcCode.value = "fail";
      }else{
       error_spcCode.value = "OK";
      }
  } catch (MalformedURLException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
   error_spcMessage.value = e.getMessage();
  }catch (AxisFault e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
   error_spcCode.value = "AxisFault";
   error_spcMessage.value = e.getMessage();
  } catch (RemoteException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
   error_spcCode.value = "RemoteException";
   error_spcMessage.value = e.getMessage();
  }
  
  System.out.println(accountCode);
  System.out.println(error_spcCode.value);
  System.out.println(error_spcMessage.value);    

 

 

  accountCreate方法:傳引數值過來  ,_call.invoke(new Object[]{"多個引數"}),如傳多個引數,那麼就需要用到_call.setOperation(_operations[2]);設定引數,要跟引數值的名字對應得上