今日 用delphi 调用C#的webserice 时 ,出现个问题。望大家给予帮助,已经研究好几天了,没头绪用delphi的 wsdl importer生成的文件中,asxm 文件中:      <s:complexType name="GInfo">
        <s:sequence>
          <s:element minOccurs="1" maxOccurs="1" name="id" type="s:unsignedInt" />
          <s:element minOccurs="0" maxOccurs="1" name="name" type="s:string" />
          <s:element minOccurs="0" maxOccurs="unbounded" name="selName" type="s:string" />
          <s:element minOccurs="0" maxOccurs="1" name="prevDraw" type="s1:DrawInfo" />
          <s:element minOccurs="0" maxOccurs="1" name="thisDraw" type="s1:DrawInfo" />
          <s:element minOccurs="1" maxOccurs="1" name="jackpot" type="s:unsignedLong" />
        </s:sequence>
      </s:complexType>生成的delphi 的类 如下 :  GInfoL = class(TRemotable)
  private
    Fid: Cardinal;
    Fname: WideString;
    FselName: WideString;
    FprevDraw: DrawInfoL;
    FthisDraw: DrawInfoL;
    Fjackpot: Int64;
  public
    destructor Destroy; override;
  published
    property id: Cardinal read Fid write Fid;
    property name: WideString read Fname write Fname;
    property selName: WideString read FselName write FselName;
    property prevDraw: DrawInfoL read FprevDraw write FprevDraw;
    property thisDraw: DrawInfoL read FthisDraw write FthisDraw;
    property jackpot: Int64 read Fjackpot write Fjackpot;
  end;====
 asmx 文件中 selName 的类型 maxOccurs="unbounded" 是 数组,但是生成的类中 FselName: WideString;却是个字符型。这样得到的 不是数组, 只能接受到第一条 数据,如何解决这个问题啊。急。急 

解决方案 »

  1.   


    呵呵,解决了你才加分,那估计是没戏了,万一帮你解决了你来个突然消失,或者不守信用怎么办?
    成功调用C#的delphi源码我有,主要是实现上传文件的。不知道是不是楼主所需要的?
      

  2.   

    webservice是你写的吗,序列化它,用string输出,delphi接受string,解析xml
      

  3.   

    給你寫了一個測試的demo:
    1.Service代碼如下,// ************************************************************************ //
    // The types declared in this file were generated from data read from the
    // WSDL File described below:
    // WSDL     : http://172.20.100.10/test/service.asmx?wsdl
    //  >Import : http://172.20.100.10/test/service.asmx?wsdl:0
    // Encoding : utf-8
    // Version  : 1.0
    // (2010/6/22 上午 11:31:35 - - $Rev: 10138 $)
    // ************************************************************************ //unit service;interfaceuses InvokeRegistry, SOAPHTTPClient, Types, XSBuiltIns;const
      IS_OPTN = $0001;
      IS_REF  = $0080;
    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"[Gbl]  // ************************************************************************ //
      // Namespace : Kye
      // soapAction: Kye/HelloWorld
      // transport : http://schemas.xmlsoap.org/soap/http
      // style     : document
      // binding   : ServiceSoap
      // service   : Service
      // port      : ServiceSoap
      // URL       : http://172.20.100.10/test/service.asmx
      // ************************************************************************ //
      ServiceSoap = interface(IInvokable)
      ['{B82FAFBA-EAB8-AD5C-2535-FB6046355616}']
        function  HelloWorld(const name_: WideString): WideString; stdcall;
      end;function GetServiceSoap(UseWSDL: Boolean=System.False; Addr: string=''; HTTPRIO: THTTPRIO = nil): ServiceSoap;
    implementation
      uses SysUtils;function GetServiceSoap(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): ServiceSoap;
    const
      defWSDL = 'http://172.20.100.10/test/service.asmx?wsdl';
      defURL  = 'http://172.20.100.10/test/service.asmx';
      defSvc  = 'Service';
      defPrt  = 'ServiceSoap';
    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 ServiceSoap);
        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(ServiceSoap), 'Kye', 'utf-8');
      InvRegistry.RegisterDefaultSOAPAction(TypeInfo(ServiceSoap), 'Kye/HelloWorld');
      InvRegistry.RegisterInvokeOptions(TypeInfo(ServiceSoap), ioDocument);
      InvRegistry.RegisterExternalParamName(TypeInfo(ServiceSoap), 'HelloWorld', 'name_', 'name');end.
      

  4.   

    調用:unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs,service, StdCtrls;type
      TForm1 = class(TForm)
        btn1: TButton;
        edt1: TEdit;
        Label1: TLabel;
        procedure btn1Click(Sender: TObject);
      private
        aa:ServiceSoap;
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.btn1Click(Sender: TObject);
    begin
      aa:=GetServiceSoap(False,'',nil);
      ShowMessage(aa.HelloWorld(edt1.Text));
    end;end.