2012-11-12 40 views
0

我有D7。我已經下載了wsdlImp程序: Borland WSDLIMP版本2.2 - $修訂版:10138 $(隨德爾福2007發貨),似乎 與D7一起使用。從c#.net代碼導入wsdl到delphi不會生成所有字段

我有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; 
    } 
    } 
} 

德爾福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> 
+0

使用類型爲「document/literal wrapped」的WDSL時,根據http://www.ibm,一個條件是:「輸入包裝器元素的名稱必須與WSDL中的Web服務操作名稱相同」。 com/developerworks/webservices/library/ws-usagewsdl/index.html) 也許這就是發生了什麼事。閱讀http://www.ibm.com/developerworks/webservices/library/ws-whichwsdl/瞭解WSDL樣式的討論 –

+0

我已經從服務中添加了wsdl代碼。我都不熟悉soap格式,也不知道如何修復c#wsdl ... – John

+0

此問題是否已被重新使用? – SSE

回答

0

嘗試使你的<wsdl:definitions targetNameSpace ...>匹配您的<xsd:schema targetNamespace ...>。這解決了我的問題。

+0

這應該是:「試着讓你的匹配你的 Morpheus48

+0

我已經修復了這個問題 - 你需要用反引號來逃避你的xml。這裏](http://stackoverflow.com/editing-help)瞭解更多詳情。 –