我使用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>
InvRegistry.RegisterInvokeOptions(TypeInfo(WebService1Soap),ioDocument); – Sam