WebService http://ws365.net/ws/weather.asmx(0分)

  • 主题发起人 主题发起人 linuxping
  • 开始时间 开始时间
L

linuxping

Unregistered / Unconfirmed
GUEST, unregistred user!
WSDL importer生成的代码是:
// ************************************************************************ //
// The types declared in this file were generated from data read from the
// WSDL File described below:
// WSDL : http://ws365.net/ws/weather.asmx?wsdl
// Encoding : utf-8
// Version : 1.0
// (2008-7-6 0:01:40 - 1.33.2.5)
// ************************************************************************ //

unit weather;

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"


ArrayOfString = array of WideString; { "http://www.ws365.net/" }

// ************************************************************************ //
// Namespace : http://www.ws365.net/
// soapAction: http://www.ws365.net/GetWeateherByCity
// transport : http://schemas.xmlsoap.org/soap/http
// binding : weatherSoap
// service : weather
// port : weatherSoap
// URL : http://ws365.net/ws/weather.asmx
// ************************************************************************ //
weatherSoap = interface(IInvokable)
['{BCB3C5C2-4323-F961-7A15-D03077CFD48E}']
function GetWeateherByCity(const city: WideString): ArrayOfString; stdcall;
end;

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


implementation

function GetweatherSoap(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): weatherSoap;
const
defWSDL = 'http://ws365.net/ws/weather.asmx?wsdl';
defURL = 'http://ws365.net/ws/weather.asmx';
defSvc = 'weather';
defPrt = 'weatherSoap';
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 weatherSoap);
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(weatherSoap), 'http://www.ws365.net/', 'utf-8');
InvRegistry.RegisterDefaultSOAPAction(TypeInfo(weatherSoap), 'http://www.ws365.net/GetWeateherByCity');
RemClassRegistry.RegisterXSInfo(TypeInfo(ArrayOfString), 'http://www.ws365.net/', 'ArrayOfString');

end.


DUnit的测试代码是:
unit WeatherTest;

interface

uses TestFramework,weather,TestExtensions,dialogs;

type
TTestWeather=class(TTestCase)
private
Fweather:weatherSoap;
public
procedure SetUp;override;
procedure TearDown;override;

published
procedure TestGetWeateherByCity;
end;
implementation

{ TTestWeather }

procedure TTestWeather.SetUp;
begin
inherited;
Fweather:=GetweatherSoap(true,'',nil)
end;

procedure TTestWeather.TearDown;
begin
Fweather:=nil;
inherited;
end;

procedure TTestWeather.TestGetWeateherByCity;
var
A:ArrayOfString;
I:integer;
begin
A:=Fweather.GetWeateherByCity('武汉');
for I:=0 to length(A)-1 do
showmessage(A);
A:=Fweather.GetWeateherByCity('北京');
for I:=0 to length(A)-1 do
showmessage(A);
end;

initialization
//TestFramework.RegisterTest(TTestCaseFirst.Suite);
TestFramework.RegisterTest(TTestWeather.Suite);
end.

测试结果出现异常
 

Similar threads

I
回复
0
查看
622
import
I
I
回复
0
查看
750
import
I
I
回复
0
查看
489
import
I
I
回复
0
查看
651
import
I
I
回复
0
查看
1K
import
I
后退
顶部