This shows you the differences between two versions of the page.
public:howto:synapsesoap [2009/03/30 13:22] tibard |
public:howto:synapsesoap [2009/04/03 09:23] (current) tibard |
||
---|---|---|---|
Line 75: | Line 75: | ||
===================== Delphi 7 =================== | ===================== Delphi 7 =================== | ||
- | Changes to do in SOAPHTTPTrans in order to use synapase | + | --- //[[tiberiua@yahoo.com|Tiberiu Ardeleanu]] 2009/03/30 13:32// |
+ | |||
+ | Remember to include $(DELPHI)\Source\SOAP in your client project search path, so that these changes will be compiled into your application. | ||
+ | |||
+ | Changes to do in SOAPHTTPTrans in order to use synapase: | ||
You should add synapse in the same way Indy is used. | You should add synapse in the same way Indy is used. | ||
- | -- define USE_SYNA: | + | define USE_SYNA: |
+ | <code delphi> | ||
{$IFDEF LINUX} | {$IFDEF LINUX} | ||
//{$DEFINE USE_INDY} | //{$DEFINE USE_INDY} | ||
Line 89: | Line 94: | ||
{$DEFINE USE_SYNA} | {$DEFINE USE_SYNA} | ||
{$ENDIF} | {$ENDIF} | ||
+ | </code> | ||
- | -- in uses: | + | in uses: |
+ | <code delphi> | ||
uses ... , | uses ... , | ||
{$IFDEF USE_SYNA} | {$IFDEF USE_SYNA} | ||
Line 101: | Line 108: | ||
{$ENDIF} | {$ENDIF} | ||
{$ENDIF} | {$ENDIF} | ||
- | + | </code> | |
- | -- Search for USE_INDY | + | Search for USE_INDY |
and add {$IFNDEF USE_SYNA} as for {$IFNDEF USE_INDY} | and add {$IFNDEF USE_SYNA} as for {$IFNDEF USE_INDY} | ||
e.g: | e.g: | ||
+ | <code delphi> | ||
{$IFNDEF USE_SYNA} | {$IFNDEF USE_SYNA} | ||
{$IFNDEF USE_INDY} | {$IFNDEF USE_INDY} | ||
Line 113: | Line 121: | ||
{$ENDIF} | {$ENDIF} | ||
{$ENDIF} | {$ENDIF} | ||
+ | </code> | ||
- | + | in THTTPReqResp.Execute add: | |
- | -- in THTTPReqResp.Execute add: | + | <code delphi> |
{$IFDEF USE_SYNA} | {$IFDEF USE_SYNA} | ||
procedure SetupSyna(SynaHttp: THTTPSend); | procedure SetupSyna(SynaHttp: THTTPSend); | ||
var | var | ||
- | ActionHeader: string; | ||
Protocol, Host, Path, Port, Para, pUser, pPass: string; | Protocol, Host, Path, Port, Para, pUser, pPass: string; | ||
begin | begin | ||
- | if (soNoValueForEmptySOAPAction in FInvokeOptions) and (SoapAction = '') then | + | |
- | ActionHeader := SHTTPSoapAction + ':' | + | if FBindingType = btMIME then |
- | else if SoapAction = '""' then | + | begin |
- | ActionHeader := SHTTPSoapAction + ': ""' | + | SynaHttp.MimeType := Format(ContentHeaderMIME, [FMimeBoundary]); |
- | else | + | SynaHttp.Headers.Add(MimeVersion); |
- | ActionHeader := SHTTPSoapAction + ': ' + '"' + FSoapAction + '"'; | + | end |
+ | else { Assume btSOAP } | ||
+ | begin | ||
+ | SynaHttp.MimeType := sTextXML; | ||
+ | SynaHttp.Headers.Add(GetSOAPActionHeader); | ||
+ | end; | ||
SynaHttp.UserName := FUserName; | SynaHttp.UserName := FUserName; | ||
SynaHttp.Password := FPassword; | SynaHttp.Password := FPassword; | ||
- | + | ||
if FProxy <> '' then | if FProxy <> '' then | ||
begin | begin | ||
Line 141: | Line 153: | ||
SynaHttp.ProxyPass := pPass; | SynaHttp.ProxyPass := pPass; | ||
end; | end; | ||
- | SynaHttp.Headers.Add(ActionHeader); | ||
- | SynaHttp.MimeType := 'text/xml'; { do not localize } | ||
- | SynaHttp.Protocol := '1.0' ; | ||
- | SynaHttp.UserAgent := Self.FAgent; | ||
- | end; | ||
+ | SynaHttp.Protocol := '1.0'; | ||
+ | SynaHttp.UserAgent := 'CustomSoap'; | ||
+ | end; | ||
procedure PostData(const Request: TStream; Response: TStream); | procedure PostData(const Request: TStream; Response: TStream); | ||
Line 155: | Line 165: | ||
try | try | ||
SetupSyna(SynaHttp); | SetupSyna(SynaHttp); | ||
+ | |||
Request.Position := 0; | Request.Position := 0; | ||
SynaHTTP.Document.LoadFromStream(Request); | SynaHTTP.Document.LoadFromStream(Request); | ||
SynaHTTP.Document.Position := 0; | SynaHTTP.Document.Position := 0; | ||
- | try | + | |
- | if SynaHTTP.HTTPMethod('POST', FURL) then | + | if SynaHTTP.HTTPMethod('POST', FURL) then |
- | Response.CopyFrom(SynaHTTP.Document, 0) | + | begin |
- | else | + | Response.CopyFrom(SynaHTTP.Document, 0); |
- | raise ESOAPHTTPException.Create(SInvalidHTTPResponse); | + | |
- | finally | + | FContentType := SynaHTTP.Headers.Values[SContentType]; |
- | end; | + | FMimeBoundary := GetMimeBoundaryFromType(FContentType); |
+ | |||
+ | CheckContentType; | ||
+ | end | ||
+ | else | ||
+ | raise ESOAPHTTPException.Create(SInvalidHTTPResponse); | ||
+ | |||
finally | finally | ||
FreeAndNil(SynaHTTP); | FreeAndNil(SynaHTTP); | ||
Line 171: | Line 187: | ||
end; | end; | ||
{$ENDIF} | {$ENDIF} | ||
+ | </code> | ||
- | -- then change: | + | then change: |
+ | <code delphi> | ||
{$IFDEF USE_INDY} | {$IFDEF USE_INDY} | ||
PostData(Request, Response); | PostData(Request, Response); | ||
Line 179: | Line 196: | ||
... | ... | ||
{$ENDIF} | {$ENDIF} | ||
+ | </code> | ||
- | -- with | + | with |
+ | <code delphi> | ||
{$IFDEF USE_SYNA} | {$IFDEF USE_SYNA} | ||
PostData(Request, Response); | PostData(Request, Response); | ||
Line 191: | Line 210: | ||
{$ENDIF} | {$ENDIF} | ||
{$ENDIF} | {$ENDIF} | ||
+ | </code> | ||
+ | |||
+ | Enjoy | ||
- | ============================== |