我想在服务器传回一个记录集给客户端,下面是我的程序
我用Delphi6 写的Webservice 服务名:TDPServer
类型定义
type
TDatas=record
id:Integer;
name:String;
addr:String;
end;
type
TMyDatas=array of TDatas;
其中方法:function TransData:TMyDatas;stdcall;
我在客户端Delphi6写的,调用TransData方法,接收TMyDatas时出错,提示ETypeTransException,data type kind Record not expected in this context,好像是record通过Soap传输的问题,不知道怎样解决,请求帮助,等待中
我用Delphi6 写的Webservice 服务名:TDPServer
类型定义
type
TDatas=record
id:Integer;
name:String;
addr:String;
end;
type
TMyDatas=array of TDatas;
其中方法:function TransData:TMyDatas;stdcall;
我在客户端Delphi6写的,调用TransData方法,接收TMyDatas时出错,提示ETypeTransException,data type kind Record not expected in this context,好像是record通过Soap传输的问题,不知道怎样解决,请求帮助,等待中
不过我看Soap可以封装复杂数据类型,例如:Soap中不仅可以封装简单的数据类型,还可以封装更加复杂的数据类型,如Struct(C或C++)、Record (Pascal)等。
这是我在网上看到的资料,不知是否准确,不过我记得用java写Webservice是可以返回结构体数组给客户端的
//类型定义单元
unit UTypes;interface
uses InvokeRegistry;
type
TDatas=record
id:Integer;
name:String;
addr:String;
end;
type
TMyDatas=array of TDatas;implementation
initialization
//RemClassRegistry.RegisterXSClass(TDatas, 'http://www.code6421.com/XMLSchema', 'TDatas', '');
RemTypeRegistry.RegisterXSInfo(TypeInfo(TDatas),'http://www.code6421.com/XMLSchema','TDatas');
RemTypeRegistry.RegisterXSInfo(TypeInfo(TMyDatas),'http://www.code6421.com/XMLSchema','TMyDatas');
finalization
//RemClassRegistry.UnRegisterXSClass(TDatas);
RemTypeRegistry.UnRegisterXSInfo(TypeInfo(TDatas));end.
RemTypeRegistry.UnRegisterXSInfo(TypeInfo(TMyDatas));end.end.//服务接口单元
{ Invokable interface IDPServer }unit DPServerIntf;interfaceuses InvokeRegistry, Types, XSBuiltIns, UTypes;
{type
TDatas=record
id:Integer;
name:String;
addr:String;
end;
type
TMyDatas=array of TDatas;
}
type { Invokable interfaces must derive from IInvokable }
IDPServer = interface(IInvokable)
['{B432271E-72AC-468F-9D22-D073FCCFF76D}']
function SayHello:string; stdcall; //WebService 所提供的Method
function TransData:TMyDatas; stdcall;//Method2 的實作
{ Methods of Invokable interface must not use the default }
{ calling convention; stdcall is recommended }
end;implementationinitialization
{ Invokable interfaces must be registered }
InvRegistry.RegisterInterface(TypeInfo(IDPServer));end.
id:Integer;
name:String;
addr:String;
end;你的 TDatas 这个结构必须为一个继承TRemotetable的类
比如:
TDatas = class(TRemotable)
这样就可以了
TCategory = class;
ArrayofCategory = array of TCategory;
TCategory = class(TRemotable)
private
FId: Integer;
FName: WideString;
FParentId: Integer;
FIndexId: Integer;
FChannels: ArrayofChannel;
published
property Id: Integer read FId write FId;
property Name: WideString read FName write FName;
property ParentId: Integer read FParentId write FParentId;
property IndexId: Integer read FIndexId write FIndexId;
property Channels: ArrayofChannel read FChannels write FChannels;
end;ServiceSoap = interface(IInvokable)
['{77573149-9C57-FA51-F11F-EFD527C91BD9}']
function GetAllCategory: ArrayofCategory; stdcall;
function GetCategoryByParentId(const parentId: Integer): ArrayofCategory; stdcall;
function AddAndUpdateCategory(const category: TCategory): TCategory; stdcall;
function DeleteCategory(const category: TCategory): Integer; stdcall;
end;
Project webClinet.exe raised exception class ERemotalbeException with message'Access violation at address 004BC32B in module'Project1.exe'.Write of address 0000000C'
不知道怎么回事
unit UTypes;interface
uses InvokeRegistry;
type
TDatas=class;
TMyDatas=array of TDatas;
TDatas= class(TRemotable)
private
FId:Integer;
FName:String;
FAddr:String;
published
property Id: Integer read FId write FId;
property Name: String read FName write FName;
property Addr: String read FAddr write FAddr;
end;
{type
TMyDatas=array of TDatas; }implementation
initialization
RemClassRegistry.RegisterXSClass(TDatas, 'http://www.code6421.com/XMLSchema', 'TDatas', '');
//RemTypeRegistry.RegisterXSInfo(TypeInfo(TDatas),'http://www.code6421.com/XMLSchema','TDatas');
RemTypeRegistry.RegisterXSInfo(TypeInfo(TMyDatas),'http://www.code6421.com/XMLSchema','TMyDatas');
finalization
RemClassRegistry.UnRegisterXSClass(TDatas);
//RemTypeRegistry.UnRegisterXSInfo(TypeInfo(TDatas));end.
RemTypeRegistry.UnRegisterXSInfo(TypeInfo(TMyDatas));end.end.
uses InvokeRegistry;
type
TDatas=class;
TMyDatas=array of TDatas;
TDatas= class(TRemotable)
private
FId:Integer;
FName:String;
FAddr:String;
published
property Id: Integer read FId write FId;
property Name: String read FName write FName;
property Addr: String read FAddr write FAddr;
end;
{type
TMyDatas=array of TDatas; }implementationinitialization
RemClassRegistry.RegisterXSClass(TDatas, 'http://www.code6421.com/XMLSchema', 'TDatas', '');
RemClassRegistry.RegisterXSInfo(TypeInfo(TMyDatas),'http://www.code6421.com/XMLSchema','TMyDatas');
finalization
RemClassRegistry.UnRegisterXSClass(TDatas);
RemClassRegistry.UnRegisterXSInfo(TypeInfo(TMyDatas));
end.
Project webClinet.exe raised exception class ERemotalbeException with message'Conversion for Class TList to SOAP is not supported'
好像是TList 不能封装成SOAP传输的类型
代码如下
{ Invokable interface IDPServer }
unit DPServerIntf;
interfaceuses InvokeRegistry, Types, XSBuiltIns;
type
TDatas=class;
TMyDatas=array of TDatas;
TDatas= class(TRemotable)
private
FId:Integer;
FName:WideString;
FAddr:WideString;
published
property Id: Integer read FId write FId;
property Name: WideString read FName write FName;
property Addr: WideString read FAddr write FAddr;
end;
{ Invokable interfaces must derive from IInvokable }
IDPServer = interface(IInvokable)
['{B432271E-72AC-468F-9D22-D073FCCFF76D}']
function SayHello:string; stdcall; //WebService 所提供的Method
function TransData:TMyDatas; stdcall;//Method2 的實作
end;implementationinitialization
{ Invokable interfaces must be registered }
InvRegistry.RegisterInterface(TypeInfo(IDPServer));
RemClassRegistry.RegisterXSClass(TDatas, 'gzxxj-hyy', 'TDatas');
RemClassRegistry.RegisterXSInfo(TypeInfo(TMyDatas), 'gzxxj-hyy', 'TMyDatas');
end.
谢谢大家的帮助
现在,结贴,给分