web service 异常处理问题(200分)

F

figoxie

Unregistered / Unconfirmed
GUEST, unregistred user!
各位大虾,我用下列代码调一个web service
// ************************************************************************ //
// The types declared in this file were generated from data read from the
// WSDL File described below:
// WSDL : http://10.132.142.222:9080/HS/wsdl/shciq/hs/encoding/EncoderImpl.wsdl
// Encoding : UTF-8
// Version : 1.0
// (2006-7-18 15:42:51 - 1.33.2.5)
// ************************************************************************ //

unit EncoderImpl1;

interface

uses InvokeRegistry, SOAPHTTPClient, Types, XSBuiltIns;

type

// ************************************************************************ //
// The following types, referred to in the WSDL document are not being represented
// in this file. They are either aliases[@] of other types represented or were referred
// to but never[!] declared in the document. The types from the latter category
// typically map to predefined/known XML or Borland types; however, they could also
// indicate incorrect WSDL documents that failed to declare or import a schema type.
// ************************************************************************ //
// !:string - "http://www.w3.org/2001/XMLSchema"
// !:int - "http://www.w3.org/2001/XMLSchema"



// ************************************************************************ //
// Namespace : http://encoding.hs.shciq
// transport : http://schemas.xmlsoap.org/soap/http
// style : document
// binding : EncoderImplSoapBinding
// service : EncoderImplService
// port : EncoderImpl
// URL : http://localhost:9080/HS/services/EncoderImpl
// ************************************************************************ //
EncoderImpl = interface(IInvokable)
['{EEC67C93-3F59-5972-F72C-53389B295A98}']
function simpleEncodeWS(const sGoodsName: WideString): WideString; stdcall;
function simpleBitsEncodeWS(const sGoodsName: WideString; const iCodeBits: Integer): WideString; stdcall;
end;

function GetEncoderImpl(UseWSDL: Boolean=System.False; Addr: string=''; HTTPRIO: THTTPRIO = nil): EncoderImpl;


implementation

function GetEncoderImpl(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): EncoderImpl;
const
defWSDL = 'http://10.31.28.210:9080/HS/wsdl/shciq/hs/encoding/EncoderImpl.wsdl';
defURL = 'http://10.31.28.210:9080/HS/services/EncoderImpl';
//defWSDL = 'http://10.132.142.222:9080/HS/wsdl/shciq/hs/encoding/EncoderImpl.wsdl';
//defURL = 'http://10.132.142.222:9080/HS/services/EncoderImpl';
defSvc = 'EncoderImplService';
defPrt = 'EncoderImpl';
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 EncoderImpl);
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;


initialization
InvRegistry.RegisterInterface(TypeInfo(EncoderImpl), 'http://encoding.hs.shciq', 'UTF-8');
InvRegistry.RegisterDefaultSOAPAction(TypeInfo(EncoderImpl), '');
InvRegistry.RegisterInvokeOptions(TypeInfo(EncoderImpl), ioDocument);

end.



调用它的方法如下
function TForm_BillI.GetHSCode(GoodsName_EN:string):string;
var
conn:EncoderImpl;
begin
try
Result:=GetEncoderImpl.simpleEncodeWS(GoodsName_EN);
except
Result:='Not Found';
end;
end;
但是发现如果web service的url设置为一个无法访问的ip,则程序不会捕捉异常,也即不会执行Result:='Not Found'这句并返回, 我想请问下这是什么原因,如何解决呢?
分不多了,但是比较急,200分送上。
 
F

figoxie

Unregistered / Unconfirmed
GUEST, unregistred user!
换个问法吧
就是我目前访问局域网的一个web service是成功的
假如我去访问一个外网的ip,我认为是应该抛出异常并被delphi程序捕捉到的,但是现在似乎是程序会一直去连这个访问不到的ip,导致死掉,为什么呢?
 

Similar threads

I
回复
0
查看
594
import
I
I
回复
0
查看
745
import
I
I
回复
0
查看
923
import
I
I
回复
0
查看
2K
import
I
I
回复
0
查看
2K
import
I
顶部