我想在服务器传回一个记录集给客户端,下面是我的程序
我用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传输的问题,不知道怎样解决,请求帮助,等待中

解决方案 »

  1.   

    web service好像不能传这样格式的数据吧,应该只能是基本类型的
      

  2.   

    谢谢回答
    不过我看Soap可以封装复杂数据类型,例如:Soap中不仅可以封装简单的数据类型,还可以封装更加复杂的数据类型,如Struct(C或C++)、Record (Pascal)等。
    这是我在网上看到的资料,不知是否准确,不过我记得用java写Webservice是可以返回结构体数组给客户端的
      

  3.   

    下面是我服务器端程序
    //类型定义单元
    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.
      

  4.   

    如果这种方式不行,那么一般Webservice是以什么方式返回数据给客户端的呢?如果有例子的,就更好了,万分感谢!
      

  5.   

    TDatas=record
    id:Integer;
    name:String;
    addr:String;
    end;你的 TDatas 这个结构必须为一个继承TRemotetable的类
    比如:
     TDatas = class(TRemotable)
    这样就可以了
      

  6.   

    比如:
      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;
      

  7.   

    Here's an example WSDL file (converted to Pascal/Delphi code) that describes the location and methods that you need to use to access the service:// *************************************************************** //// The types declared in this file were generated from data read from the// WSDL File described below:// WSDL     : http://www.webservicex.net/WeatherForecast.asmx?WSDL// Encoding : utf-8// Version  : 1.0// (10/08/2006 16:26:14 - 1.33.2.5)// *************************************************************** //unit WeatherForecast;interfaceuses 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"  // !:float           - "http://www.w3.org/2001/XMLSchema"  WeatherData          = class;                 { "http://www.webservicex.net" }  WeatherForecasts     = class;                 { "http://www.webservicex.net" }  // *************************************************************** //  // Namespace : http://www.webservicex.net  // ************************************************************** //  WeatherData = class(TRemotable)  private    FDay: WideString;    FWeatherImage: WideString;    FMaxTemperatureF: WideString;    FMinTemperatureF: WideString;    FMaxTemperatureC: WideString;    FMinTemperatureC: WideString;  published    property Day: WideString read FDay write FDay;    property WeatherImage: WideString read FWeatherImage write FWeatherImage;    property MaxTemperatureF: WideString read FMaxTemperatureF write FMaxTemperatureF;    property MinTemperatureF: WideString read FMinTemperatureF write FMinTemperatureF;    property MaxTemperatureC: WideString read FMaxTemperatureC write FMaxTemperatureC;    property MinTemperatureC: WideString read FMinTemperatureC write FMinTemperatureC;  end;  ArrayOfWeatherData = array of WeatherData;    { "http://www.webservicex.net" }  // ************************************************************** //  // Namespace : http://www.webservicex.net  // ************************************************************** //  WeatherForecasts = class(TRemotable)  private    FLatitude: Single;    FLongitude: Single;    FAllocationFactor: Single;    FFipsCode: WideString;    FPlaceName: WideString;    FStateCode: WideString;    FStatus: WideString;    FDetails: ArrayOfWeatherData;  public    destructor Destroy; override;  published    property Latitude: Single read FLatitude write FLatitude;    property Longitude: Single read FLongitude write FLongitude;    property AllocationFactor: Single read FAllocationFactor write FAllocationFactor;    property FipsCode: WideString read FFipsCode write FFipsCode;    property PlaceName: WideString read FPlaceName write FPlaceName;    property StateCode: WideString read FStateCode write FStateCode;    property Status: WideString read FStatus write FStatus;    property Details: ArrayOfWeatherData read FDetails write FDetails;  end;  // *************************************************************** //  // Namespace : http://www.webservicex.net  // soapAction: http://www.webservicex.net/%operationName%  // transport : http://schemas.xmlsoap.org/soap/http  // style     : document  // binding   : WeatherForecastSoap  // service   : WeatherForecast  // port      : WeatherForecastSoap  // URL       : http://www.webservicex.net/WeatherForecast.asmx  // *************************************************************** //  WeatherForecastSoap = interface(IInvokable)  ['{45A46EB0-5550-8C38-49AC-AE13AD113F74}']    function  GetWeatherByZipCode(const ZipCode: WideString): WeatherForecasts; stdcall;    function  GetWeatherByPlaceName(const PlaceName: WideString): WeatherForecasts; stdcall;  end;function GetWeatherForecastSoap(UseWSDL: Boolean=System.False; Addr: string=''; HTTPRIO: THTTPRIO = nil): WeatherForecastSoap;implementationfunction GetWeatherForecastSoap(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): WeatherForecastSoap;const  defWSDL = 'http://www.webservicex.net/WeatherForecast.asmx?WSDL';  defURL  = 'http://www.webservicex.net/WeatherForecast.asmx';  defSvc  = 'WeatherForecast';  defPrt  = 'WeatherForecastSoap';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 WeatherForecastSoap);    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;destructor WeatherForecasts.Destroy;var  I: Integer;begin  for I := 0 to Length(FDetails)-1 do    if Assigned(FDetails[I]) then      FDetails[I].Free;  SetLength(FDetails, 0);  inherited Destroy;end;initialization  InvRegistry.RegisterInterface(TypeInfo(WeatherForecastSoap), 'http://www.webservicex.net', 'utf-8');  InvRegistry.RegisterDefaultSOAPAction(TypeInfo(WeatherForecastSoap), 'http://www.webservicex.net/%operationName%');  InvRegistry.RegisterInvokeOptions(TypeInfo(WeatherForecastSoap), ioDocument);  RemClassRegistry.RegisterXSClass(WeatherData, 'http://www.webservicex.net', 'WeatherData');  RemClassRegistry.RegisterXSInfo(TypeInfo(ArrayOfWeatherData), 'http://www.webservicex.net', 'ArrayOfWeatherData');  RemClassRegistry.RegisterXSClass(WeatherForecasts, 'http://www.webservicex.net', 'WeatherForecasts');end.
      

  8.   

    我修改TDatas 为TRemotable类后报错
    Project webClinet.exe raised exception class ERemotalbeException with message'Access violation at address 004BC32B in module'Project1.exe'.Write of address 0000000C'
    不知道怎么回事
      

  9.   

    代码贴上:
    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.
      

  10.   

    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;   }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.
      

  11.   

    change RemTypeRegistry to RemClassRegistry
      

  12.   

    刚才是数组赋值的时候搞错了,改了后出现问题
    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.
      

  13.   

    奇怪了,我退出Delphi后,重新开启Delphi 再执行,居然没有报错,也得到了想要的结果!郁闷中。
    谢谢大家的帮助
    现在,结贴,给分