I have a built a simple ASMX service using Visual Studio 2010. I am have build a simple service client application (form) using Delphi 7. I have used WSDLImport to create a proxy file that contains all type definitions and service operations. Here is the code for the WebService11.pas file.
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;
i开发者_如何学Pythonf (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
.
Following is the file that is contained in the Unit1.pas file that is the actual code of the 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.
The delphi client is hitting the ASMX service as expected. However, I do not see the data sent as parameter in the "Add" operation. I put a break in the ASMX service source code and inspected the parameter value, which is null.
I have used fiddler to read the message sent by the delphi client, but I cannot see the incoming SOAP message. I can see the SOAP data sent back by the ASMX service, which is an integer value. This integer value is not received by the SOAP client.
I need to understand the following:
1) Is there any other way to read what is sent and received by delphi client. I know that there is a component HTTPRIO1 in Delphi, but I do not know how to I get the request and response data from it.
2) What am I doing wrong here.
*Please not that I am not an expert in Delphi 7 yet. I am basically trying to get a delphi client talk to an ASMX service. I could have used WCF but there is some complexity I am facing, therefore needs to understand if I can get the delphi client talk to a ASMX service based on SOAP 1.1
Added Later: I have somehow gathered the Request and Response SOAP messages through fiddler 2.
Request SOAP message:
<?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>
Response SOAP message:
<?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>
I have fixed the issue. This was basically due to the SOAP format which wasn't compatible with WCF. I converted the SOAP format to 'Document/Literal'. Please read my other thread How to set THTTPRio.Converter.Options to soLiteralParams in OnBeforeExecuteEvent
精彩评论