下載 Axis下載地址?http://axis.apache.org/axis2/java/core/download.html
?配置環(huán)境變量:?AXIS2_HOME?D:\axis2-1.7.9
???????????????????????????????????????????path?%AXIS2_HOME%\bin
下載后解壓:視圖
第二步:
如圖二所示:
?輸入:?WSDL2Java -uri?zco_out_to_sap.wsdl?-p?com.crm.sap.webservice.feedback?-o feedback? 命令
解釋:zco_out_to_sap.wsdl? 文件名?com.crm.sap.webservice.feedback 生成的bin目錄下的文件夾
如圖:
然后再看:文件夾
自動生成2個文件-導入項目中

調用方式:
packagetest;
importcom.alibaba.fastjson.JSONArray;
importcom.alibaba.fastjson.JSONObject;
importorg.apache.axis2.transport.http.HTTPConstants;
importorg.apache.axis2.transport.http.HttpTransportProperties;
importjava.text.SimpleDateFormat;
importjava.util.Date;
importjava.util.Random;
publicclassTestToSap{
publicstaticvoidmain(String[] args){
try{
SimpleDateFormat df =newSimpleDateFormat("yyyyMMdd");
String dateStr = df.format(newDate());
ZCO_OUT_TO_SAPStub service =newZCO_OUT_TO_SAPStub();
HttpTransportProperties.Authenticator auth =newHttpTransportProperties.Authenticator();
auth.setUsername("sap賬號");
auth.setPassword("sap密碼");
? ? ? ? ? ? ? ? service._getServiceClient().getOptions().setProperty(HTTPConstants.AUTHENTICATE, auth);
ZCO_OUT_TO_SAPStub.ZdataToSapSync async =newZCO_OUT_TO_SAPStub.ZdataToSapSync();
ZCO_OUT_TO_SAPStub.String strJson =newZCO_OUT_TO_SAPStub.String();
JSONObject head=newJSONObject();
String sap_navl ="D1"+newDate().getTime()+""+newRandom().nextInt(5);
SendSapHead sheadr =newSendSapHead("OUT_TO_SAP_CRM_MATNR",//sap約定標識
? ? ? ? ? ? ? ? ? ? sap_navl,
"",
"",
"crmrequest",//標識(所以標識約定都是sap那邊接口提供的)
? ? ? ? ? ? ? ? ? ? DateUtils.getDataString(DateUtils.yyyyMMdd),
DateUtils.getDate("HHmmss"),
"json",dateStr);
head.put("CONTROL", JSONObject.parse(JsonUtil.bean2json(sheadr)));
JSONObject object =newJSONObject();
JSONArray array =newJSONArray();
object.put("VKORG","1000");//傳入?yún)?shù)
object.put("VTWEG","00");
object.put("STYPE","ZFD");
? ? ? ? ? ? array.add(object);
head.put("DATA", array);
strJson.setString(head !=null? head.toJSONString():"");
? ? ? ? ? ? async.setInJson(strJson);
? ? ? ? ? ? ZCO_OUT_TO_SAPStub.ZdataToSapSyncResponse zdataToSapSyncResponse = service.zdataToSapSync(async);
? ? ? ? ? ? System.out.print(zdataToSapSyncResponse.getOutJson().toString());
}catch(Exception ex){
? ? ? ? ? ? ? ? ex.printStackTrace();
? ? ? ? }
? ? }
}
最后附上所需要的 pom文件
? ? ? ? ? ? ? ? <dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-kernel</artifactId>
1.6.1
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-codegen</artifactId>
1.6.1
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-adb</artifactId>
1.6.1
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-transport-local</artifactId>
1.6.1
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-transport-http</artifactId>
1.6.1
</dependency>
<dependency>
<groupId>wsdl4j</groupId>
<artifactId>wsdl4j</artifactId>
1.4
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
4.12
</dependency>