itri tts@ web logo

 

Web Service API

應用特色

使用SOAP通訊協定傳輸 直接 TTS download程式碼 不需要
操控自由度 Domain name 不需要
合成音檔下載處理 自行處理 License Code 不需要

簡介

本服務使用UTF-8之格式,提供SOAP(Simple Object Access Protocol)協議的TTS Web Service Servers,並提供合成音檔下載網址,供使用自行下載。

Web Service API提供函式(ConvertSimple, ConvertText, ConvertAdvancedText)的傳回值皆為String型態,其回傳值格式為resultCode&resultString&result,以〝&〞區隔開來,唯有resultCode等於0(Success)時,才會有result(Convert ID)的值產生。下方表格(表一)為執行狀況代碼 (resultCode)與說明(resultString)之對照值。

另外,在GetConvertStatus函式中,提供TTS合成的狀態,其格式為 resultCode&resultString&statusCode&status &result,以〝&〞區隔開來,當statusCode為2(completed)時,result的值為download音檔的位置;當statusCode為1(processing)時,result的值為waiting X Sec(X等於等待的秒數);當statusCode為0(queued)時,代表程式尚未處理到這筆資料,請稍待片刻再來詢問目前合成的狀態。下方表格(表二)為狀態代碼(statusCode)與說明(status)之對照值。

下方表格(表三)中,為系統提供的所有語音合成聲音,必需使用ConvertText或者ConvertAdvancedText函式,才能設定不同的TTS Speaker。中英統合是指,使用單一語者聲音,即可針對含有中英文語句進行語音合成,而中英切換則是使用雙語者聲音來進行語音合成。

(表一)

resultCode resultString
0 Success
-1 No matched speaker
-2 Voice setting fail
-3 Output file setting fail
-4 invalid login
-5 invalid TTS Font Format
-6 out of service space
-7 account incative
-8 possword incative
-9 incative TTSSpeaker
-10 incative Volume
-11 incative Speed
-12 invalid Text
-13 content size is too large
-14 inactive ConvertID
-15 inactive outputType
-16 inactive PitchModify

(表二)

statusCode status
0 queued
1 processing
2 completed
3+ No matched speaker

(表三)

TTSSpeaker explain
Bruce 中英切換男生語音(default)
Theresa 中英切換女生語音
Angela 中英切換小女孩語音
MCHEN_Bruce 中英統合男生語音
MCHEN_Joddess 中英統合女生語音
ENG_Bob 英文男生語音
ENG_Alice 英文女生語音
ENG_Tracy 英文小男孩語音
TW_LIT_AKoan 台語女生語音(文讀台)
TW_SPK_AKoan 台語女生語音(白話台)

Web Service API 架構示意圖

應用教學

Step1. 取得帳號/密碼

請先註冊成為會員取得帳號/密碼

 

Step2. 取得SOAP協議的TTS Web Service Servers位置

本服務使用UTF-8之格式,提供SOAP(Simple Object Access Protocol)協議的TTS Web Service Servers 其位置為 http://tts.itri.org.tw/TTSService/Soap_1_3.php?wsdl

 

Step3. 提供函式(ConvertSimple, ConvertText, ConvertAdvancedText)

 

可選擇任一函式輸入預合成文字與合成參數設定,輸出合成編號(Convert ID),並分別介紹如下:

 

ConvertSimple

不需額外選擇,直接提供固定語者(預設為Bruce)、固定音量(預設為100)與固定語音速度(預設為0)。

輸入參數:

  • Account(String)–輸入您申請的帳號
  • Password(String)–輸入您申請的密碼
  • TTSText(String)–輸入欲合成的TTS文字

函式範例:

  • ConvertSimple("ITRI","ITRI Password","歡迎使用文字轉語音合成技術")

回傳參數:

  • Result(String)–resultCode&resultString&result
    • resultCode–回傳執行狀況代碼(參考表一)
    • resultString–回傳執行狀況說明(參考表一)
    • result–當resultCode為0、resultString為Success時,回傳檔案之Convert ID。

函式執行結果範例:

  • 0&Success&20

Example:PHP 程式碼-使用Soap請求(UTF-8編碼格式)

//Setup Web Service
$client = new SoapClient("http://tts.itri.org.tw/TTSService/Soap_1_3.php?wsdl");
// Invoke Call to ConvertSimple
$result=$client->ConvertSimple("Account","Password","合成文字位置");
// Iterate through the returned string array
$resultArray=explode("&",$result);
list($resultCode, $resultString, $resultConvertID) = $resultArray;
echo "resultCode:".$resultCode."<br/>";
echo "resultString:".$resultString."<br/>";
echo "resultConvertID:".$resultConvertID."<br/>";

Example:ASP 程式碼-使用Soap請求

'Setup Web Service
Set objSoapClient = Server.CreateObject("MSSoap.SoapClient")
objSoapClient.ClientProperty("ServerHTTPRequest") = true
objSoapClient.MSSoapInit ("http://tts.itri.org.tw/TTSService/Soap_1_3.php?wsdl")
'Invoke Call to ConvertSimple
dim result
result = objSoapClient.ConvertSimple("Account","Password","合成文字位置")
'Iterate through the returned string array
resultArray = Split(result,"&")
dim resultArray
dim resultNameArray(3)
resultNameArray(0) = "resultCode:"
resultNameArray(1) = "resultString:"
resultNameArray(2) = "resultConvertID:"
for i=0 to UBound(resultArray)
response.write resultNameArray(i)+resultArray(i)+"<br/>"
next
Set objSoapClient = Nothing

Example:Android 程式碼-使用Soap請求

String methodName = "ConvertSimple";
String nameSpace = "http://tts.itri.org.tw/TTSService/";
String soapAction = nameSpace+methodName;
SoapObject rpc = new SoapObject(nameSpace, methodName);
rpc.addProperty("accountID", "Account");
rpc.addProperty("password", "Password");
rpc.addProperty("TTStext", "合成文字位置");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.bodyOut = rpc;
envelope.dotNet = true;
envelope.setOutputSoapObject(rpc);
HttpTransportSE transport = new HttpTransportSE(endPoint);
transport.debug = true;
Object obj = null;
try {
transport.call(soapAction, envelope);
obj = envelope.getResponse();
result = obj.toString();
Log.i("shiaukai","result:"+obj.toString());
//resultTV.setText(result);
String[] retAry = result.split("&");
String status = retAry[0];
Log.i("shiaukai", status);
if(status.equals("0")){
convertID = Integer.valueOf(retAry[2]);
}
Message msg =new Message();
msg.what=SoapExActivity.RESULT;
SoapExActivity.this.handler.sendMessage(msg);
//return obj.toString();
} catch (Exception e) {
e.printStackTrace();
}

Example:IOS 程式碼-使用Soap請求

NSString *accountID =@"Account";
NSString *password =@"Password";
NSString *TTStext =@"合成文字位置";
//建立 SOAP Message
NSString *soapMessage = [NSString stringWithFormat:
@"<?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>"
"<ConvertSimple xmlns=\"http://tts.itri.org.tw/\">"
"<accountID>%@</accountID>"
"<password>%@</password>"
"<TTStext>%@</TTStext>"
"</ConvertSimple>"
"</soap12:Body>"
"</soap12:Envelope>",accountID,password,TTStext];
//建立URL Request時需要的 NSERL參數
NSURL *url = [NSURL URLWithString:@"http://tts.itri.org.tw/TTSService/Soap_1_3.php?wsdl"];
//建立 URL Resquest
NSMutableURLRequest *urlRequest=[NSMutableURLRequest requestWithURL:url];
//SOAP Message長度,web service需要
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
[urlRequest addValue: @"application/soap+xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];//內容形態
[urlRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];//SOAP message長度
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
conn = [[NSURLConnection alloc] initWithRequest:urlRequest delegate:self];
if (conn) {
webData = [NSMutableData data];
}
 
ConvertText

提供選擇不同語者(speaker)之聲音、並可進行音量調整與語音速度調整。

輸入參數:

  • Account(String)–輸入您申請的帳號
  • Password(String)–輸入您申請的密碼
  • TTSText(String)–輸入欲合成的TTS文字
  • TTSSpeaker(String)–可選擇語者(參考表三)
  • Volume(Integer)–其音量大小可調整範圍為0~100
  • Speed(Integer)–其語音速度可調整範圍為-10~10
  • outType(String) –輸入聲音輸出之格式(wav、flv)

函式範例:

  • ConvertText("ITRI","ITRI Password","歡迎使用文字轉語音合成技術","Angela",50,5, "wav")

回傳參數:

  • Result(String)–resultCode&resultString&result
    • resultCode–回傳執行狀況代碼(參考表一)
    • resultString–回傳執行狀況說明(參考表一)
    • result–當resultCode為0、resultString為Success時,回傳檔案之Convert ID。

函式執行結果範例:

  • 0&Success&21

Example:PHP 程式碼-使用Soap請求(UTF-8編碼格式)

<?php
//Setup Web Service
$client = new SoapClient("http://tts.itri.org.tw/TTSService/Soap_1_3.php?wsdl");
// Invoke Call to ConvertText
$result=$client->ConvertText("Account","Password","合成文字位置","Theresa",100, 0, "flv");
// Iterate through the returned string array
$resultArray= explode("&",$result);
list($resultCode, $resultString, $resultConvertID) = $resultArray;
echo "resultCode:".$resultCode."<br/>";
echo "resultString:".$resultString."<br/>";
echo "resultConvertID:".$resultConvertID."<br/>";
?>

Example:ASP 程式碼-使用Soap請求

<%
'Setup Web Service
Set objSoapClient = Server.CreateObject("MSSoap.SoapClient")
objSoapClient.ClientProperty("ServerHTTPRequest") = true
objSoapClient.MSSoapInit ("http://tts.itri.org.tw/TTSService/Soap_1_3.php?wsdl")
'Invoke Call to ConvertText
dim result
result = objSoapClient.ConvertText("Account","Password","合成文字位置","Theresa",100,0, "flv")
'Iterate through the returned string array
resultArray = Split(result,"&")
dim resultArray
dim resultNameArray(3)
resultNameArray(0) = "resultCode:"
resultNameArray(1) = "resultString:"
resultNameArray(2) = "resultConvertID:"
for i=0 to UBound(resultArray)
response.write resultNameArray(i)+resultArray(i)+"<br/>"
next
Set objSoapClient = Nothing
%>

Example:Android 程式碼-使用Soap請求

String methodName = "ConvertText";
String nameSpace = "http://tts.itri.org.tw/TTSService/";
String soapAction = nameSpace+methodName;
Log.i("shiaukai", soapAction);
SoapObject rpc = new SoapObject(nameSpace, methodName);
rpc.addProperty("accountID", "Account");
rpc.addProperty("password", "Password");
rpc.addProperty("TTStext", "TTSText");
rpc.addProperty("TTSSpeaker", "TTSSpeaker");
rpc.addProperty("volume", "Volume");
rpc.addProperty("speed", "Speed");
rpc.addProperty("outType", "OutputType");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.bodyOut = rpc;
envelope.dotNet = true;
envelope.setOutputSoapObject(rpc);
HttpTransportSE transport = new HttpTransportSE(endPoint);
transport.debug = true;
Object obj = null;
try {
transport.call(soapAction, envelope);
obj = envelope.getResponse();
result = obj.toString();
Log.i("shiaukai","result:"+obj.toString());
String[] retAry = result.split("&");
String status = retAry[0];
Log.i("shiaukai", status);
if(status.equals("0")){
convertID = Integer.valueOf(retAry[2]);
}
Message msg =new Message();
msg.what=SoapExActivity.RESULT;
SoapExActivity.this.handler.sendMessage(msg);
} catch (Exception e) {
e.printStackTrace();
}

Example:IOS 程式碼-使用Soap請求

NSString *accountID =@"Account";
NSString *password =@"Password";
NSString *TTStext =@"合成文字位置";
NSString *TTSSpeaker=@"Angela";
int volume =100; //Range 0~100 default=100
int speed =0; //Range -10~10 default=0
NSString *outType =@"wav";// or flv
//建立 SOAP Message
NSString *soapMessage = [NSString stringWithFormat:
@"<?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>"
"<ConvertText xmlns=\"http://tts.itri.org.tw/\">"
"<accountID>%@</accountID>"
"<password>%@</password>"
"<TTStext>%@</TTStext>"
"<TTSSpeaker>%@</TTSSpeaker>"
"<volume>%i</volume>"
"<speed>%i</speed>"
"<outType>%@</outType>"
"</ConvertText>"
"</soap12:Body>"
"</soap12:Envelope>",accountID,password,TTStext,TTSSpeaker,volume,speed,outType];
NSLog(@"%@",soapMessage);
//建立URL Request時需要的 NSERL參數
NSURL *url = [NSURL URLWithString:@"http://tts.itri.org.tw/TTSService/Soap_1_3.php?wsdl"];
//建立 URL Resquest
NSMutableURLRequest *urlRequest=[NSMutableURLRequest requestWithURL:url];
//SOAP Message長度,web service需要
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
[urlRequest addValue: @"application/soap+xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];//內容形態
[urlRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];//SOAP message長度
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
conn = [[NSURLConnection alloc] initWithRequest:urlRequest delegate:self];
if (conn) {
webData = [NSMutableData data];
}
 
ConvertAdvancedText

提供選擇不同語者(speaker)之聲音、並可進行音量調整、語音速度調整與韻律調整。

輸入參數:

  • Account(String)–輸入您申請的帳號
  • Password(String)–輸入您申請的密碼
  • TTSText(String)–輸入欲合成的TTS文字
  • TTSSpeaker(String)–可選擇語者(參考表三)
  • Volume(Integer)–其音量大小可調整範圍為0~100,預設值為100
  • Speed(Integer)–其語音速度可調整範圍為-10~10,預設值為0
  • outType(String) –輸入聲音輸出之格式(wav、flv)
  • PitchLevel(Integer) –韻律調整:值越大則音高越高;反之則音高越低,可調整範圍-10~10,預設值為0
  • PitchSign(Integer) –韻律調整:0=正常、1=像機器人、2=像外國人說中文,預設值為0
  • PitchScale(Integer) –韻律調整:值越大則抑揚頓挫越明顯;反之則越趨平版,可調整範圍0~20,預設值為5

函式範例:

  • ConvertAdvancedText("ITRI","ITRI Password","歡迎使用文字轉語音合成技術","Angela",50,5, "wav",5,1,10)

回傳參數:

  • Result(String)–resultCode&resultString&result
    • resultCode–回傳執行狀況代碼(參考表一)
    • resultString–回傳執行狀況說明(參考表一)
    • result–當resultCode為0、resultString為Success時,回傳檔案之Convert ID

函式執行結果範例:

  • 0&Success&21

Example:PHP 程式碼-使用Soap請求(UTF-8編碼格式)

<?php
//Setup Web Service
$client = new SoapClient("http://tts.itri.org.tw/TTSService/Soap_1_3.php?wsdl");
// Invoke Call to ConvertText
$result=$client->ConvertAdvancedText("Account","Password","合成文字位置","Theresa",100, 0, "flv",5,1,10);
// Iterate through the returned string array
$resultArray=explode("&",$result);
list($resultCode, $resultString, $resultConvertID) = $resultArray;
echo "resultCode:".$resultCode."<br/>";
echo "resultString:".$resultString."<br/>";
echo "resultConvertID:".$resultConvertID."<br/>";
?>

Example:ASP 程式碼-使用Soap請求

<%
'Setup Web Service
Set objSoapClient = Server.CreateObject("MSSoap.SoapClient")
objSoapClient.ClientProperty("ServerHTTPRequest") = true
objSoapClient.MSSoapInit ("http://tts.itri.org.tw/TTSService/Soap_1_3.php?wsdl")
'Invoke Call to ConvertText
dim result
result = objSoapClient.ConvertAdvancedText("Account","Password","合成文字位置","Theresa",100,0, "flv",5,1,10)
'Iterate through the returned string array
resultArray = Split(result,"&")
dim resultArray
dim resultNameArray(3)
resultNameArray(0) = "resultCode:"
resultNameArray(1) = "resultString:"
resultNameArray(2) = "resultConvertID:"
for i=0 to UBound(resultArray)
response.write resultNameArray(i)+resultArray(i)+"<br/>"
next
Set objSoapClient = Nothing
%>

Example:Android 程式碼-使用Soap請求

String methodName = "ConvertAdvancedText";
String soapAction = nameSpace+methodName;
SoapObject rpc = new SoapObject(nameSpace, methodName);
rpc.addProperty("accountID", "Account");
rpc.addProperty("password", "Password");
rpc.addProperty("TTStext", "TTSText");
rpc.addProperty("TTSSpeaker", "TTSSpeaker");
rpc.addProperty("volume", "Volume");
rpc.addProperty("speed", "Speed");
rpc.addProperty("outType", "OutputType");
rpc.addProperty("PitchLevel", "PitchLevel);
rpc.addProperty("PitchSign", "PitchSign);
rpc.addProperty("PitchScale", "PitchScale);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.bodyOut = rpc;
envelope.dotNet = true;
envelope.setOutputSoapObject(rpc);
HttpTransportSE transport = new HttpTransportSE(endPoint);
transport.debug = true;
Object obj = null;
try {
transport.call(soapAction, envelope);
obj = envelope.getResponse();
result = obj.toString();
Log.i("shiaukai","result:"+obj.toString());
String[] retAry = result.split("&");
String status = retAry[0];
Log.i("shiaukai", status);
if(status.equals("0")){
convertID = Integer.valueOf(retAry[2]);
}
Message msg =new Message();
msg.what=SoapExActivity.RESULT;
SoapExActivity.this.handler.sendMessage(msg);
} catch (Exception e) {
e.printStackTrace();
}

Example:IOS 程式碼-使用Soap請求

NSString *accountID =@"Account";
NSString *password =@"Password";
NSString *TTStext =@"合成文字位置";
NSString *TTSSpeaker=@"Angela";
int volume =100; //Range 0~100 default=100
int speed =0; //Range -10~10 default=0
NSString *outType =@"wav";// or flv
NSString *PitchLevel=@"0";//Range -10~10 default=0
NSString *PitchSign =@"1";//0,1,2 default=0
NSString *PitchScale=@"5";//Range 0~20 default=5
//建立 SOAP Message
NSString *soapMessage = [NSString stringWithFormat:
@"<?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>"
"<ConvertAdvancedText xmlns=\"http://tts.itri.org.tw/\">"
"<accountID>%@</accountID>"
"<password>%@</password>"
"<TTStext>%@</TTStext>"
"<TTSSpeaker>%@</TTSSpeaker>"
"<volume>%i</volume>"
"<speed>%i</speed>"
"<outType>%@</outType>"
"<PitchLevel>%@</PitchLevel>"
"<PitchSign>%@</PitchSign>"
"<PitchScale>%@</PitchScale>"
"</ConvertAdvancedText>"
"</soap12:Body>"
"</soap12:Envelope>",accountID,password,TTStext,TTSSpeaker,volume,speed,outType,PitchLevel,PitchSign,PitchScale];
NSLog(@"%@",soapMessage);
//建立URL Request時需要的 NSERL參數
NSURL *url = [NSURL URLWithString:@"http://tts.itri.org.tw/TTSService/Soap_1_3.php?wsdl"];
//建立 URL Resquest
NSMutableURLRequest *urlRequest=[NSMutableURLRequest requestWithURL:url];
//SOAP Message長度,web service需要
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
[urlRequest addValue: @"application/soap+xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];//內容形態
[urlRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];//SOAP message長度
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
conn = [[NSURLConnection alloc] initWithRequest:urlRequest delegate:self];
if (conn) {
webData = [NSMutableData data];
}
 
Step4. 提供函式(GetConvertStatus)並提供合成音檔下載網址:

該函式可輸入合成編號(Convert ID),輸出目前合成的狀態,若狀態為合成完畢,將提供合成音檔下載網址。

提供詢問目前TTS合成之進度,其狀態表可參考表二之內容。

輸入參數:

  • Account(String)–輸入您申請的帳號
  • Password(String)–輸入您申請的密碼
  • ConvertID(int)–輸入欲查詢之Convert ID

函式範例:

  • GetConvertStatus("Account"," Password",13321)

回傳參數:

  • Result(String)–resultCode&resultString&statusCode&status&result
    • resultCode–回傳執行狀況代碼(參考表一)
    • resultString–回傳執行狀況說明(參考表一)
    • statusCode–回傳TTS合成進度代碼(參考表二)
    • status–回傳TTS合成進度說明(參考表二)
    • result–當resultCode為0(Success)時,且statusCode為2(completed),回傳檔案之下載位置(resultUrl),statusCode為1(processing),回傳waiting X Sec後將會完成(completed)。

函式執行結果範例:

  • 0&Success&2&completed&http://tts.itri.org.tw/TTSService/download/Account/1111.wav

Example:PHP 程式碼-使用Soap請求(UTF-8編碼格式)

<?php
//Setup Web Service
$client = new SoapClient("http://tts.itri.org.tw/TTSService/Soap_1_3.php?wsdl");
// Invoke Call to ConvertText
$result=$client->GetConvertStatus("Account"," Password",ConvertID);
// Iterate through the returned string array
$resultArray= explode("&",$result);
list($resultCode, $resultString, $statusCode, $status, $resultUrl) = $resultArray;
echo "resultCode:".$resultCode."<br/>";
echo "resultString:".$resultString."<br/>";
echo "statusCode:".$statusCode."<br/>";
echo "status:".$status."<br/>";
echo "resultUrl:".$resultUrl."<br/>";
?>

Example:ASP 程式碼-使用Soap請求

<%
'Setup Web Service
Set objSoapClient = Server.CreateObject("MSSoap.SoapClient")
objSoapClient.ClientProperty("ServerHTTPRequest") = true
objSoapClient.MSSoapInit ("http://tts.itri.org.tw/TTSService/Soap_1_3.php?wsdl")
'Invoke Call to ConvertText
dim result
result=objSoapClient.GetConvertStatus("Account","Password",ConvertID)
'Iterate through the returned string array
resultArray = Split(result,"&")
dim resultArray
dim resultNameArray(5)
resultNameArray(0) = "resultCode:"
resultNameArray(1) = "resultString:"
resultNameArray(2) = "statusCode:"
resultNameArray(3) = "status:"
resultNameArray(4) = "resultUrl:"
for i=0 to UBound(resultArray)
response.write resultNameArray(i)+resultArray(i)+"<br/>"
next
Set objSoapClient = Nothing
%>

 

Example:Android 程式碼-使用Soap請求

String methodName = "GetConvertStatus";
String soapAction = nameSpace+methodName;
SoapObject rpc = new SoapObject(nameSpace, methodName);
rpc.addProperty("accountID", "Account");
rpc.addProperty("password", "Password");
rpc.addProperty("convertID", id);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.bodyOut = rpc;
envelope.dotNet = true;
envelope.setOutputSoapObject(rpc);
HttpTransportSE transport = new HttpTransportSE(endPoint);
transport.debug = true;
Object obj = null;
try {
transport.call(soapAction, envelope);
obj = envelope.getResponse();
result = obj.toString();
Log.i("shiaukai","result:"+obj.toString());
Message msg =new Message();
msg.what=SoapExActivity.RESULT_STATUS;
SoapExActivity.this.handler.sendMessage(msg);
} catch (Exception e) {
e.printStackTrace();
}

Example:IOS 程式碼-使用Soap請求

NSString *accountID =@"Account";
NSString *password =@"Password";
int convertID =[txt_ConvertID.text intValue];
//建立 SOAP Message
NSString *soapMessage = [NSString stringWithFormat:
@"<?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>"
"<GetConvertStatus xmlns=\"http://tts.itri.org.tw/\">"
"<accountID>%@</accountID>"
"<password>%@</password>"
"<convertID>%i</convertID>"
"</GetConvertStatus>"
"</soap12:Body>"
"</soap12:Envelope>",accountID,password,convertID];
NSLog(@"%@",soapMessage);
//建立URL Request時需要的 NSERL參數
NSURL *url = [NSURL URLWithString:@"http://tts.itri.org.tw/TTSService/Soap_1_3.php?wsdl"];
//建立 URL Resquest
NSMutableURLRequest *urlRequest=[NSMutableURLRequest requestWithURL:url];
//SOAP Message長度,web service需要
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
[urlRequest addValue: @"application/soap+xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];//內容形態
[urlRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];//SOAP message長度
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
conn = [[NSURLConnection alloc] initWithRequest:urlRequest delegate:self];
if (conn) {
webData = [NSMutableData data];
}