如何檢查WebService是否可用或有一個有效的網址?確定WebService是否可用或具有有效的url?
我正在使用Delphi嚮導導入並自動生成必要的WSDL函數。
嚮導爲我創建的函數,如果WSDL或URL錯誤,則不會引發異常,也不返回空對象。只有當我調用返回的WSDL類的函數時,它會引發一個奇怪的異常,即XML-String沒有有效的「text/html」樣式。
這裏是自動生成WSDL功能:
function GetcheckVatPortType(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): checkVatPortType;
const
defWSDL = 'http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl';
defURL = 'http://ec.europa.eu/taxation_customs/vies/services/checkVatService';
defSvc = 'checkVatService';
defPrt = 'checkVatPort';
var
RIO: THTTPRIO;
begin
Result := nil;
if (Addr = '') then
begin
if UseWSDL then
Addr := defWSDL
else
Addr := defURL;
end;
if HTTPRIO = nil then
RIO := THTTPRIO.Create(nil)
else
RIO := HTTPRIO;
try
Result := (RIO as checkVatPortType);
if UseWSDL then
begin
RIO.WSDLLocation := Addr;
RIO.Service := defSvc;
RIO.Port := defPrt;
end else
RIO.URL := Addr;
finally
if (Result = nil) and (HTTPRIO = nil) then
RIO.Free;
end;
end;
// ************************************************************************ //
// Namespace : urn:ec.europa.eu:taxud:vies:services:checkVat
// Transport : http://schemas.xmlsoap.org/soap/http
// Stil : document
// Verwenden von : literal
// Bindung : checkVatBinding
// Service : checkVatService
// Port : checkVatPort
// URL : http://ec.europa.eu/taxation_customs/vies/services/checkVatService
// ************************************************************************ //
checkVatPortType = interface(IInvokable)
['{0F901373-2432-32E2-C99D-95B53AE83C79}']
// Entpacken nicht möglich:
// - Mehrere strenge out-Elemente gefunden
function checkVat(const parameters: checkVat): checkVatResponse; stdcall;
// Entpacken nicht möglich:
// - Mehrere strenge out-Elemente gefunden
function checkVatApprox(const parameters: checkVatApprox): checkVatApproxResponse; stdcall;
end;
如果defWSDL
或defURL
無效或不可用,則返回initiaized checkVatPortType
類/接口。之後在返回的接口上調用一個函數(checkVatPortType.checkVat
),我得到了一個奇怪的異常。
這意味着,如果WebService不可用,則用戶將收到「XML-String沒有有效」文本/ html格式的消息。其中沒有描述問題。
如果會拋出正確的錯誤消息,而不是嘗試將不存在的函數的響應強制轉換爲xml字符串,那將會很不錯。 –
是的,這不是一個有用的錯誤消息,您可以提交更改請求到QC – mjn
剛剛添加到QC#111490 http://qc.embarcadero.com/wc/qcmain.aspx?d=111490 –