JAVA呼叫webService SOAP12
package com.ess.pos.info.impl;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.RequestEntity;
public class HttpWebService{
public static void main(String[] args) throws HttpException, IOException {
// TODO Auto-generated method stub
String soapRequestData = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
+ "<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
+ " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\""
+ " xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\">"
+ " <soap12:Body>"
+ " <GetTax xmlns=\"http://www.galasystec.net.cn/\">"
// + " <GetAPACShippingPackageRequest>"
+ " <sagncode>QDZP001</sagncode>"
+ " <sDate>2018-06-20</sDate>"
//+ " </GetAPACShippingPackageRequest>"
+ " </GetTax>" + "</soap12:Body>"
+ " </soap12:Envelope>";
System.out.println(soapRequestData);
PostMethod postMethod = new PostMethod(
"http://******地址/WDService.asmx");
// 然後把Soap請求資料新增到PostMethod中
byte[] b = soapRequestData.getBytes("utf-8");
InputStream is = new ByteArrayInputStream(b, 0, b.length);
RequestEntity re = new InputStreamRequestEntity(is, b.length,
"application/soap+xml; charset=utf-8");
postMethod.setRequestEntity(re);
// 最後生成一個HttpClient物件,併發出postMethod請求
HttpClient httpClient = new HttpClient();
int statusCode = httpClient.executeMethod(postMethod);
if(statusCode == 200) {
System.out.println("呼叫成功!");
String soapResponseData = postMethod.getResponseBodyAsString();
System.out.println(soapResponseData);
//截取出json資料
int sub = soapResponseData.indexOf("<GetTaxResult>");
soapResponseData = soapResponseData.substring(sub).replace("<GetTaxResult>", "");
sub = soapResponseData.indexOf("</GetTaxResult>");
soapResponseData = soapResponseData.substring(0, sub);
System.out.println(soapResponseData);
}
else {
System.out.println("呼叫失敗!錯誤碼:" + statusCode);
}
}
}
介面原頁
WANDAService
單擊此處,獲取完整的操作列表。
GetTax
餐商逾期
測試
若要使用 HTTP POST 協議對操作進行測試,請單擊“呼叫”按鈕。
引數 | 值 |
sagncode: | |
sDate: | |
SOAP 1.1
以下是 SOAP 1.2 請求和響應示例。所顯示的佔位符需替換為實際值。
POST /WDService.asmx HTTP/1.1 Host: * Content-Type: text/xml; charset=utf-8 Content-Length: length SOAPAction: "http://www.galasystec.net.cn/GetTax" <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <GetTax xmlns="http://www.galasystec.net.cn/"> <sagncode>string</sagncode> <sDate>dateTime</sDate> </GetTax> </soap:Body> </soap:Envelope>
HTTP/1.1 200 OK Content-Type: text/xml; charset=utf-8 Content-Length: length <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <GetTaxResponse xmlns="http://www.galasystec.net.cn/"> <GetTaxResult>string</GetTaxResult> </GetTaxResponse> </soap:Body> </soap:Envelope>
SOAP 1.2
以下是 SOAP 1.2 請求和響應示例。所顯示的佔位符需替換為實際值。
POST /WDService.asmx HTTP/1.1 Host: * Content-Type: application/soap+xml; charset=utf-8 Content-Length: length <?xml version="1.0" encoding="utf-8"?> <soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"> <soap12:Body> <GetTax xmlns="http://www.galasystec.net.cn/"> <sagncode>string</sagncode> <sDate>dateTime</sDate> </GetTax> </soap12:Body> </soap12:Envelope>
HTTP/1.1 200 OK Content-Type: application/soap+xml; charset=utf-8 Content-Length: length <?xml version="1.0" encoding="utf-8"?> <soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"> <soap12:Body> <GetTaxResponse xmlns="http://www.galasystec.net.cn/"> <GetTaxResult>string</GetTaxResult> </GetTaxResponse> </soap12:Body> </soap12:Envelope>
HTTP GET
以下是 HTTP GET 請求和響應示例。所顯示的佔位符需替換為實際值。
GET /WDService.asmx/GetTax?sagncode=string&sDate=string HTTP/1.1 Host: *
HTTP/1.1 200 OK Content-Type: text/xml; charset=utf-8 Content-Length: length <?xml version="1.0" encoding="utf-8"?> <string xmlns="http://www.galasystec.net.cn/">string</string>
HTTP POST
以下是 HTTP POST 請求和響應示例。所顯示的佔位符需替換為實際值。
POST /WDService.asmx/GetTax HTTP/1.1 Host: * Content-Type: application/x-www-form-urlencoded Content-Length: length sagncode=string&sDate=string
HTTP/1.1 200 OK Content-Type: text/xml; charset=utf-8 Content-Length: length <?xml version="1.0" encoding="utf-8"?> <string xmlns="http://www.galasystec.net.cn/">string</string>