over 3 years ago

因專案需求必須以webservice訪問客戶的資料,所以導入使用。

本次採用的是Apache Axis2/Java方式,
官網:http://axis.apache.org/axis2/java/core/index.html
版本:axis2-1.6.0
檔案:http://apache.cdpa.nsysu.edu.tw//axis/axis2/java/core/1.6.0/axis2-1.6.0-bin.zip

導入說明:
先將下載包中以下的jar檔匯入專案中。
axiom-api-1.2.11.jar
axiom-impl-1.2.11.jar
axis2-adb-1.6.0.jar
axis2-kernel-1.6.0.jar
axis2-transport-http-1.6.0.jar
axis2-transport-local-1.6.0.jar
commons-logging-1.1.1.jar
httpcore-4.0.jar
neethi-2.0.5.jar
wsdl4j-1.6.2.jar
XmlSchema-1.4.7.jar

程式說明

try {
    //對方服務的網址

    EndpointReference target_epr = new EndpointReference("http://61.67.74.72:3535/MMWebService/MMDataWs.asmx");
    ServiceClient sender = new ServiceClient();
    Options options = new Options();
    //設定封包Header SOAPAction: "http://tempuri.org/GetMemberCptsWSForEGO"

    //此會在定義檔中找到

    options.setAction("http://tempuri.org/GetMemberCptsWSForEGO");
    options.setTo(target_epr);
    sender.setOptions(options);
    OMElement method = null;
    OMElement paramOP_DepNo = null;
    OMElement paramVip_No = null;
    OMElement paramId_No = null;
    //

    OMFactory factory = OMAbstractFactory.getOMFactory();
    OMNamespace omNs = factory.createOMNamespace("http://tempuri.org/","xsd");
    //建立對方提供的方法

    method = factory.createOMElement("GetMemberCptsWSForEGO", omNs);
    //建立相對應的tag跟值

    paramOP_DepNo = factory.createOMElement("paramOP_DepNo", omNs);
    paramOP_DepNo.addChild(factory.createOMText(paramOP_DepNo, "8802"));
    paramVip_No = factory.createOMElement("paramVip_No", omNs);
    paramVip_No.addChild(factory.createOMText(paramVip_No, "2820101080163"));
    paramId_No = factory.createOMElement("paramId_No", omNs);
    paramId_No.addChild(factory.createOMText(paramId_No, "19790223"));
    //再放入方法內

    method.addChild(paramOP_DepNo);
    method.addChild(paramVip_No);
    method.addChild(paramId_No);
    //這邊呼叫執行

    OMElement result = sender.sendReceive(method);
    System.out.println("sendMessage:"+result.getFirstElement().getText());
    //此為取得結果==>sendMessage:4^~error

} catch (AxisFault e) {
    e.printStackTrace();
}
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
  <soapenv:Body>
    <xsd:GetMemberCptsWSForEGO xmlns:xsd="http://tempuri.org/">
      <xsd:paramOP_DepNo>8802</xsd:paramOP_DepNo>
      <xsd:paramVip_No>2820101080163</xsd:paramVip_No>
      <xsd:paramId_No>19790223</xsd:paramId_No>
    </xsd:GetMemberCptsWSForEGO>
  </soapenv:Body>
</soapenv:Envelope>
← Spring與log4j instanceof-判斷物件繼承關係的小指令 →
 
comments powered by Disqus