1

可能重复:
Delphi SOAP Envelope 和 WCF

我在 C# 上制作了一个自托管的 WCF 应用程序。绑定方法是BasicHttpBinding (SOAP)。然后我制作了使用该服务的客户端 C# 应用程序,我使用 Visual Studio 添加了服务引用,完全没有错误。到这里一切都很好。当我尝试连接 Delphi 7 客户端时出现问题。以下是我执行的步骤:

  1. 创建了一个新的应用程序
  2. 在表单上删除了 HTTPRIO 组件
  3. 使用 WSDL Importer Wizard 导入服务
  4. 第 3 步创建了一个文件,我将其命名为 FRS.pas 并保存。
  5. 将 FRS 添加到主要应用程序“用途”
  6. 运行应用程序并收到错误消息“[Error] FRS.pas(52): Undeclared identifier: 'GetOptions'”和“[Fatal Error] Unit1.pas(7): Could not compile used unit 'FRS.pas'”

这是生成的代码

// ************************************************************************ //
// The types declared in this file were generated from data read from the
// WSDL File described below:
// WSDL     : http://localhost:933/FRS?wsdl
// Encoding : utf-8
// Version  : 1.0
// (29.11.2012 13:16:07 - 1.33.2.5)
// ************************************************************************ //

unit FRS;

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.
  // ************************************************************************ //
  // !:GetOptions      - "http://tempuri.org/"
  // !:GetOptionsResponse - "http://tempuri.org/"
  // !:SetOptions      - "http://tempuri.org/"
  // !:SetOptionsResponse - "http://tempuri.org/"
  // !:Beep            - "http://tempuri.org/"
  // !:BeepResponse    - "http://tempuri.org/"
  // !:GetStatus       - "http://tempuri.org/"
  // !:GetStatusResponse - "http://tempuri.org/"
  // !:RegisterReceipt - "http://tempuri.org/"
  // !:RegisterReceiptResponse - "http://tempuri.org/"
  // !:RegisterBill    - "http://tempuri.org/"
  // !:RegisterBillResponse - "http://tempuri.org/"
  // !:PrintReport     - "http://tempuri.org/"
  // !:PrintReportResponse - "http://tempuri.org/"


  // ************************************************************************ //
  // Namespace : http://tempuri.org/
  // soapAction: http://tempuri.org/IFRS/%operationName%
  // transport : http://schemas.xmlsoap.org/soap/http
  // binding   : BasicHttpBinding_IFRS
  // service   : FRS
  // port      : BasicHttpBinding_IFRS
  // URL       : http://localhost:933/FRS/soap
  // ************************************************************************ //
  IFRS = interface(IInvokable)
  ['{75F3494A-C58E-25D0-475B-CD49AEDABE03}']
    function  GetOptions(const parameters: GetOptions): GetOptionsResponse; stdcall;
    function  SetOptions(const parameters: SetOptions): SetOptionsResponse; stdcall;
    function  Beep(const parameters: Beep): BeepResponse; stdcall;
    function  GetStatus(const parameters: GetStatus): GetStatusResponse; stdcall;
    function  RegisterReceipt(const parameters: RegisterReceipt):     RegisterReceiptResponse; stdcall;
    function  RegisterBill(const parameters: RegisterBill): RegisterBillResponse; stdcall;
    function  PrintReport(const parameters: PrintReport): PrintReportResponse; stdcall;
  end;

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


implementation

function GetIFRS(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): IFRS;
const
  defWSDL = 'http://localhost:933/FRS?wsdl';
  defURL  = 'http://localhost:933/FRS/soap';
  defSvc  = 'FRS';
  defPrt  = 'BasicHttpBinding_IFRS';
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 IFRS);
    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(IFRS), 'http://tempuri.org/', 'utf-8');
  InvRegistry.RegisterDefaultSOAPAction(TypeInfo(IFRS),     'http://tempuri.org/IFRS/%operationName%');
  InvRegistry.RegisterInvokeOptions(TypeInfo(IFRS), ioLiteral);

end.

这是c#服务接口

[ServiceContract]
public interface IFRS
{
    [OperationContract]
    string GetOptions();

    [OperationContract]
    void SetOptions(string xml);

    [OperationContract]
    void Beep();

    [OperationContract]
    string GetStatus();

    [OperationContract]
    void RegisterReceipt(string xml);

    [OperationContract]
    void RegisterBill(string xml);

    [OperationContract]
    void PrintReport(string xml);
}

据我所知,存在一些兼容性问题,因为 c# 客户端工作正常。我不擅长德尔福,但我必须提供一个工作样本。如果有人遇到过这种问题,请帮忙。

4

0 回答 0