0

我有D7。我已经下载了 wsdlImp 程序:Borland WSDLIMP 版本 2.2 - $Rev: 10138 $(随 delphi 2007 提供),它似乎适用于 D7。

我的c#接口如下:

using System;
using System.ServiceModel;

[ServiceContract]
public interface ITransferService
{
  [OperationContract]
  RemoteFileInfo DownloadFile(DownloadRequest request);

  [OperationContract]
  void UploadFile(RemoteFileInfo request);
}
[MessageContract]
public class DownloadRequest
{
  [MessageBodyMember]
  public string FileName;
}

[MessageContract]
public class RemoteFileInfo : IDisposable
{
  [MessageHeader(MustUnderstand = true)]
  public string FileName;

  [MessageHeader(MustUnderstand = true)]
  public long Length;

  [MessageBodyMember(Order = 1)]
  public System.IO.Stream FileByteStream;

  public void Dispose()
  {
    if (FileByteStream != null)
    {
      FileByteStream.Close();
      FileByteStream = null;
    }
  }
}

Delphi wsdl 导入生成:

unit TransferService;

interface

uses InvokeRegistry, SOAPHTTPClient, Types, XSBuiltIns;

const
  IS_OPTN = $0001;
  IS_NLBL = $0004;
  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.
  // ************************************************************************ //
  // !:base64Binary    - "http://www.w3.org/2001/XMLSchema"[Gbl]
  // !:string          - "http://www.w3.org/2001/XMLSchema"[Gbl]
  // !:long            - "http://www.w3.org/2001/XMLSchema"[Gbl]

  DownloadRequest      = class;                 { "http://tempuri.org/"[Lit][GblElm] }
  RemoteFileInfo       = class;                 { "http://tempuri.org/"[Lit][GblElm] }
  FileName             = class;                 { "http://tempuri.org/"[Hdr][Alias] }
  Length               = class;                 { "http://tempuri.org/"[Hdr][Alias] }

  StreamBody      =  TByteDynArray;      { "http://schemas.microsoft.com/Message"[GblSmpl] }


  // ************************************************************************ //
  // XML       : DownloadRequest, global, <element>
  // Namespace : http://tempuri.org/
  // Serializtn: [xoLiteralParam]
  // Info      : Wrapper
  // ************************************************************************ //
  DownloadRequest = class(TRemotable)
  private
    FFileName: WideString;
    FFileName_Specified: boolean;
    procedure SetFileName(Index: Integer; const AWideString: WideString);
    function  FileName_Specified(Index: Integer): boolean;
  public
    constructor Create; override;
  published
    property FileName: WideString  Index (IS_OPTN or IS_NLBL) read FFileName write SetFileName stored FileName_Specified;
  end;



  // ************************************************************************ //
  // XML       : RemoteFileInfo, global, <element>
  // Namespace : http://tempuri.org/
  // Serializtn: [xoLiteralParam]
  // Info      : Wrapper
  // ************************************************************************ //
  RemoteFileInfo = class(TRemotable)
  private
    FFileByteStream: StreamBody;
  public
    constructor Create; override;
  published
    property FileByteStream: StreamBody  read FFileByteStream write FFileByteStream;
  end;



  // ************************************************************************ //
  // XML       : FileName, alias
  // Namespace : http://tempuri.org/
  // Serializtn: [xoSimpleTypeWrapper]
  // Info      : Header
  // ************************************************************************ //
  FileName = class(TSOAPHeader)
  private
    FValue: WideString;
  published
    property Value: WideString  read FValue write FValue;
  end;



  // ************************************************************************ //
  // XML       : Length, alias
  // Namespace : http://tempuri.org/
  // Serializtn: [xoSimpleTypeWrapper]
  // Info      : Header
  // ************************************************************************ //
  Length = class(TSOAPHeader)
  private
    FValue: Int64;
  published
    property Value: Int64  read FValue write FValue;
  end;


  // ************************************************************************ //
  // Namespace : http://tempuri.org/
  // soapAction: http://tempuri.org/ITransferService/%operationName%
  // transport : http://schemas.xmlsoap.org/soap/http
  // style     : document
  // binding   : BasicHttpBinding_ITransferService
  // service   : TransferService
  // port      : BasicHttpBinding_ITransferService
  // URL       : http://localhost:1875/TransferService.svc
  // ************************************************************************ //
  ITransferService = interface(IInvokable)
  ['{8D28E73C-15D9-7F1E-9D04-A024598C5EA2}']

    // Cannot unwrap: 
    //     - Input element wrapper name does not match operation's name
    // Headers: FileName:pOut, Length:pOut
    function  DownloadFile(const parameters: DownloadRequest): RemoteFileInfo; stdcall;

    // Cannot unwrap: 
    //     - Input element wrapper name does not match operation's name
    // Headers: FileName:pIn, Length:pIn
    procedure UploadFile(const parameters: RemoteFileInfo); stdcall;
  end;

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


implementation
  uses SysUtils;

function GetITransferService(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): ITransferService;
const
  defWSDL = 'http://localhost:1875/TransferService.svc?wsdl';
  defURL  = 'http://localhost:1875/TransferService.svc';
  defSvc  = 'TransferService';
  defPrt  = 'BasicHttpBinding_ITransferService';
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 ITransferService);
    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;


constructor DownloadRequest.Create;
begin
  inherited Create;
  FSerializationOptions := [xoLiteralParam];
end;

procedure DownloadRequest.SetFileName(Index: Integer; const AWideString: WideString);
begin
  FFileName := AWideString;
  FFileName_Specified := True;
end;

function DownloadRequest.FileName_Specified(Index: Integer): boolean;
begin
  Result := FFileName_Specified;
end;

constructor RemoteFileInfo.Create;
begin
  inherited Create;
  FSerializationOptions := [xoLiteralParam];
end;

initialization
  InvRegistry.RegisterInterface(TypeInfo(ITransferService), 'http://tempuri.org/', 'utf-8');
  InvRegistry.RegisterDefaultSOAPAction(TypeInfo(ITransferService), 'http://tempuri.org/ITransferService/%operationName%');
  InvRegistry.RegisterInvokeOptions(TypeInfo(ITransferService), ioDocument);
  InvRegistry.RegisterInvokeOptions(TypeInfo(ITransferService), ioLiteral);
  InvRegistry.RegisterHeaderClass(TypeInfo(ITransferService), FileName, 'FileName', 'http://tempuri.org/');
  InvRegistry.RegisterHeaderClass(TypeInfo(ITransferService), Length, 'Length', 'http://tempuri.org/');
  InvRegistry.RegisterExternalParamName(TypeInfo(ITransferService), 'DownloadFile', 'parameters1', 'parameters');
  RemClassRegistry.RegisterXSInfo(TypeInfo(StreamBody), 'http://schemas.microsoft.com/Message', 'StreamBody');
  RemClassRegistry.RegisterXSClass(DownloadRequest, 'http://tempuri.org/', 'DownloadRequest');
  RemClassRegistry.RegisterSerializeOptions(DownloadRequest, [xoLiteralParam]);
  RemClassRegistry.RegisterXSClass(RemoteFileInfo, 'http://tempuri.org/', 'RemoteFileInfo');
  RemClassRegistry.RegisterSerializeOptions(RemoteFileInfo, [xoLiteralParam]);
  RemClassRegistry.RegisterXSClass(FileName, 'http://tempuri.org/', 'FileName');
  RemClassRegistry.RegisterSerializeOptions(FileName, [xoSimpleTypeWrapper]);
  RemClassRegistry.RegisterXSClass(Length, 'http://tempuri.org/', 'Length');
  RemClassRegistry.RegisterSerializeOptions(Length, [xoSimpleTypeWrapper]);

end.

问题在于这里的代码:

ITransferService = interface(IInvokable)
  ['{8D28E73C-15D9-7F1E-9D04-A024598C5EA2}']

    // Cannot unwrap: 
    //     - Input element wrapper name does not match operation's name
    // Headers: FileName:pOut, Length:pOut
    function  DownloadFile(const parameters: DownloadRequest): RemoteFileInfo; stdcall;

    // Cannot unwrap: 
    //     - Input element wrapper name does not match operation's name
    // Headers: FileName:pIn, Length:pIn
    procedure UploadFile(const parameters: RemoteFileInfo); stdcall;
  end;

我该如何解决这个问题?解包错误的原因是什么?


这是wsdl代码:

<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:tns="http://tempuri.org/" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" name="TransferService" targetNamespace="http://tempuri.org/">
<wsdl:types>
<xsd:schema targetNamespace="http://tempuri.org/Imports">
<xsd:import schemaLocation="http://localhost:1875/TransferService.svc?xsd=xsd0" namespace="http://tempuri.org/"/>
<xsd:import schemaLocation="http://localhost:1875/TransferService.svc?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/"/>
<xsd:import schemaLocation="http://localhost:1875/TransferService.svc?xsd=xsd2" namespace="http://schemas.microsoft.com/Message"/>
</xsd:schema>
</wsdl:types>
<wsdl:message name="DownloadRequest">
<wsdl:part name="parameters" element="tns:DownloadRequest"/>
</wsdl:message>
<wsdl:message name="RemoteFileInfo">
<wsdl:part name="parameters" element="tns:RemoteFileInfo"/>
</wsdl:message>
<wsdl:message name="RemoteFileInfo_Headers">
<wsdl:part name="FileName" element="tns:FileName"/>
<wsdl:part name="Length" element="tns:Length"/>
</wsdl:message>
<wsdl:message name="ITransferService_UploadFile_OutputMessage"/>
<wsdl:portType name="ITransferService">
<wsdl:operation name="DownloadFile">
<wsdl:input wsaw:Action="http://tempuri.org/ITransferService/DownloadFile" name="DownloadRequest" message="tns:DownloadRequest"/>
<wsdl:output wsaw:Action="http://tempuri.org/ITransferService/DownloadFileResponse" name="RemoteFileInfo" message="tns:RemoteFileInfo"/>
</wsdl:operation>
<wsdl:operation name="UploadFile">
<wsdl:input wsaw:Action="http://tempuri.org/ITransferService/UploadFile" name="RemoteFileInfo" message="tns:RemoteFileInfo"/>
<wsdl:output wsaw:Action="http://tempuri.org/ITransferService/UploadFileResponse" message="tns:ITransferService_UploadFile_OutputMessage"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="BasicHttpBinding_ITransferService" type="tns:ITransferService">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="DownloadFile">
<soap:operation soapAction="http://tempuri.org/ITransferService/DownloadFile" style="document"/>
<wsdl:input name="DownloadRequest">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="RemoteFileInfo">
<soap:header message="tns:RemoteFileInfo_Headers" part="FileName" use="literal"/>
<soap:header message="tns:RemoteFileInfo_Headers" part="Length" use="literal"/>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="UploadFile">
<soap:operation soapAction="http://tempuri.org/ITransferService/UploadFile" style="document"/>
<wsdl:input name="RemoteFileInfo">
<soap:header message="tns:RemoteFileInfo_Headers" part="FileName" use="literal"/>
<soap:header message="tns:RemoteFileInfo_Headers" part="Length" use="literal"/>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="TransferService">
<wsdl:port name="BasicHttpBinding_ITransferService" binding="tns:BasicHttpBinding_ITransferService">
<soap:address location="http://localhost:1875/TransferService.svc"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
4

2 回答 2

0

尝试使您的<wsdl:definitions targetNameSpace ...>匹配成为您的<xsd:schema targetNamespace ...>. 这解决了我的问题。

于 2015-08-13T00:35:25.450 回答
0

您可以尝试另一件事,而不是:

<xsd:import schemaLocation="http://localhost:1875/TransferService.svc?xsd=xsd0" namespace="http://tempuri.org/"/>

使 XSD 成为本地文件。例如“c:\temp\file0.xsd”

在某些情况下——主要是当 http url 实际上是 https url,或者端口无效时——delphi 不会很好地响应重定向,只是将函数标记为“无法解包”。

我知道如果您正在为其他人制作 WSDL,这对您没有帮助,但如果您只是尝试导入 WSDL 以在 delphi 中使用,它可能会帮助一些读者。

于 2021-05-04T14:37:56.227 回答