2011-09-24 103 views
0

我使用Visual Studio 2010构建了一个简单的ASMX服务。我使用Delphi 7构建了一个简单的服务客户端应用程序(表单)。我使用WSDLImport创建了一个包含所有类型定义的代理文件和服务操作。这是WebService11.pas文件的代码。Delphi客户端和ASMX服务。数据没有收到操作

unit WebService1; 

interface 

uses InvokeRegistry, SOAPHTTPClient, Types, XSBuiltIns; 

type 

    WebService1Soap = interface(IInvokable) 
    ['{3392229C-09D2-6D56-CE62-6850ABB2629D}'] 
    function Add(const a: Integer): Integer; stdcall; 
    function Subtract(const a: Integer; const b: Integer): Integer; stdcall; 
    end; 

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


implementation 

function GetWebService1Soap(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): WebService1Soap; 
const 
    defWSDL = 'http://localhost/DelphiTest/WebService1.asmx?wsdl'; 
    defURL = 'http://localhost/DelphiTest/WebService1.asmx'; 
    defSvc = 'WebService1'; 
    defPrt = 'WebService1Soap'; 
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 WebService1Soap); 
    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(WebService1Soap), 'http://tempuri.org/', 'utf-8'); 
    InvRegistry.RegisterDefaultSOAPAction(TypeInfo(WebService1Soap), 'http://tempuri.org/%operationName%'); 

end 

以下是包含在Unit1.pas文件中的文件,它是Form的实际代码。

unit Unit1; 

interface 

uses 
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
    Dialogs, StdCtrls, WebService1, InvokeRegistry, Rio, SOAPHTTPClient; 

type 
    TForm1 = class(TForm) 
    Button1: TButton; 
    HTTPRIO1: THTTPRIO; 
    procedure Button1Click(Sender: TObject); 
    private 
    { Private declarations } 
    public 
    { Public declarations } 
    end; 

var 
    Form1: TForm1; 

implementation 

{$R *.dfm} 

procedure TForm1.Button1Click(Sender: TObject); 
var c : integer; 
begin 
    c := GetWebService1Soap(False,'',HTTPRIO1).Add(10); 
    ShowMessage(IntToStr(c)); 
    end; 
end. 

delphi客户端按预期击中ASMX服务。但是,在“添加”操作中,我看不到作为参数发送的数据。我在ASMX服务源代码中进行了一次中断,并检查了参数值,该值为null。

我已经使用提琴手来读取由delphi客户端发送的消息,但我看不到传入的SOAP消息。我可以看到ASMX服务返回的SOAP数据,它是一个整数值。 SOAP客户端未收到此整数值。

我需要了解以下内容:

1)是否有任何其他方式来阅读什么是发送和德尔福客户好评。我知道Delphi中有一个组件HTTPRIO1,但我不知道如何从中获取请求和响应数据。

2)我在这里做错了什么。

*请不要说我不是Delphi 7的专家。我基本上试图让一个德尔福客户对话到一个ASMX服务。我可以使用WCF,但有一定的复杂性,我面对的,因此需要明白,如果我能得到德尔福的客户与对基于SOAP ASMX服务1.1

后来补充: 我莫名其妙地聚集请求并通过提琴手响应SOAP消息2.

请求SOAP消息:

<?xml version="1.0"?> 
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"> 
    <SOAP-ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> 
    <NS1:Add xmlns:NS1="http://tempuri.org/"> 
      <a xsi:type="xsd:int">10</a> 
    </NS1:Add></SOAP-ENV:Body> 
</SOAP-ENV:Envelope> 

响应SOAP消息:

<?xml version="1.0" encoding="utf-8"?> 
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
<soap:Body> 
<AddResponse xmlns="http://tempuri.org/"> 
<AddResult>2</AddResult> 
</AddResponse> 
</soap:Body> 
</soap:Envelope> 

回答

相关问题