aardio 文档

aardio 范例: SOAP WebService

使用 dotNet 库调用 WebService

/*
web.soapClient 是 WebService 精简接口,
如果需要更完整的 WebService 支持请参考以下链接。
使用 dotNet 库调用 WebService: https://www.aardio.com/zh-cn/docs/examples/Languages/dotNet/Advanced/WebService.html
*/

import console;
import web.soapClient;

console.showLoading("正在连接 calculator 服务...");
var calcClient,err = web.soapClient("http://www.dneonline.com/calculator.asmx");
console.assert(calcClient,err);

var result,err = calcClient.Add(15, 25);
if(result){
    console.success("计算 15+25 的结果:", result); // 预期输出: 40
}
else {
    console.fail("调用失败:", err);
} 


console.showLoading("正在连接 CountryInfoService...");
var countryClient,err = web.soapClient("http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso");
console.assert(countryClient,err);

var isoCode = "CN"; // 中国的 ISO 代码

// 1. 查询首都
console.log("正在查询首都, 代码:", isoCode);
var capital = countryClient.CapitalCity(isoCode);
console.log("中国首都:", capital); // 预期输出: Beijing

// 2. 查询电话区号
console.log("正在查询电话区号...");
var phoneCode = countryClient.CountryIntPhoneCode(isoCode);
console.log("电话区号:", phoneCode); // 预期输出: 86

// 3. 查询货币名称
var currency = countryClient.CountryCurrency(isoCode); 
console.dumpJson(currency)

console.showLoading("正在连接 CountryInfoService..."); 
var client,err = web.soapClient("http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso");
console.assert(client,err);

console.log("正在获取国家列表...");
var countries = client.ListOfCountryNamesByName();

//测试数组
console.status(countries,"打印首个返回值")
console.dumpJson(countries[1])
console.status(table.isArray(countries),"table.isArray")

console.showLoading("正在连接 numberconversion 服务...");
//参数指定服务网址,不需要 ?WSDL 后缀(aardio 自动添加)。
var seviceClient,err = web.soapClient("https://www.dataaccess.com/webservicesserver/numberconversion.wso")  

//低版本操作系统可能无法连廊接这个网址,可以改用 dotNet.createWebService 调用这个接口
console.assert(seviceClient,err);

var ret,err = seviceClient.NumberToWords(123);  
console.status(!err,"将数字 123 转换为英文单词:",ret,err);

console.pause();
Markdown 格式