This shows you the differences between two versions of the page.
public:howto:synapsesoap [2007/11/30 09:36] geby created |
public:howto:synapsesoap [2009/04/03 09:23] (current) tibard |
||
---|---|---|---|
Line 2: | Line 2: | ||
- | From: Stig Johansen (stig.johansen@udvikling.it) | + | From: Stig Johansen (stig.johansen@udvikling.it) |
- | Subject: Re: Cannot run two SOAP-threads ? | + | Subject: Re: Cannot run two SOAP-threads ? |
- | Newsgroups: borland.public.kylix.internet.web | + | Newsgroups: borland.public.kylix.internet.web |
- | Date: 2002-05-06 21:01:50 PST | + | Date: 2002-05-06 21:01:50 PST |
Jochen Staerk wrote: | Jochen Staerk wrote: | ||
Line 17: | Line 17: | ||
solution: | solution: | ||
- | * In oxmldom.pas, the handling of GlobalOXDOM is not threadsafe. I changes | + | * In oxmldom.pas, the handling of GlobalOXDOM is not threadsafe. I changes the declaration to threadvar instead of var. |
- | the declaration to threadvar instead of var. | + | * The indy components. In my project, when using small packets, the first request is ok, the second inserts extra crlf in the header, the third crashes. I dont have the time to debug indy, so I replaced it with Synapse. |
- | * The indy components. In my project, when using small packets, the first | + | |
- | request is ok, the second inserts extra crlf in the header, the third | + | |
- | crashes. I dont have the time to debug indy, so I replaced it with Synapse. | + | |
- | See: | + | |
+ | See: | ||
From my previous post: | From my previous post: | ||
Line 76: | Line 73: | ||
{$ENDIF} | {$ENDIF} | ||
</code> | </code> | ||
+ | |||
+ | ===================== Delphi 7 =================== | ||
+ | --- //[[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. | ||
+ | |||
+ | define USE_SYNA: | ||
+ | |||
+ | <code delphi> | ||
+ | {$IFDEF LINUX} | ||
+ | //{$DEFINE USE_INDY} | ||
+ | {$DEFINE USE_SYNA} | ||
+ | {$ENDIF} | ||
+ | {$IFDEF MSWINDOWS} | ||
+ | //{$DEFINE USE_INDY} | ||
+ | {$DEFINE USE_SYNA} | ||
+ | {$ENDIF} | ||
+ | </code> | ||
+ | |||
+ | in uses: | ||
+ | <code delphi> | ||
+ | uses ... , | ||
+ | {$IFDEF USE_SYNA} | ||
+ | HTTPSend, synautil; | ||
+ | {$ELSE} | ||
+ | {$IFDEF USE_INDY} | ||
+ | ...; | ||
+ | {$ELSE} | ||
+ | ...; | ||
+ | {$ENDIF} | ||
+ | {$ENDIF} | ||
+ | </code> | ||
+ | Search for USE_INDY | ||
+ | and add {$IFNDEF USE_SYNA} as for {$IFNDEF USE_INDY} | ||
+ | e.g: | ||
+ | <code delphi> | ||
+ | {$IFNDEF USE_SYNA} | ||
+ | {$IFNDEF USE_INDY} | ||
+ | ... | ||
+ | ... | ||
+ | {$ELSE} | ||
+ | ... | ||
+ | {$ENDIF} | ||
+ | {$ENDIF} | ||
+ | </code> | ||
+ | |||
+ | in THTTPReqResp.Execute add: | ||
+ | <code delphi> | ||
+ | {$IFDEF USE_SYNA} | ||
+ | procedure SetupSyna(SynaHttp: THTTPSend); | ||
+ | var | ||
+ | Protocol, Host, Path, Port, Para, pUser, pPass: string; | ||
+ | begin | ||
+ | |||
+ | if FBindingType = btMIME then | ||
+ | begin | ||
+ | SynaHttp.MimeType := Format(ContentHeaderMIME, [FMimeBoundary]); | ||
+ | SynaHttp.Headers.Add(MimeVersion); | ||
+ | end | ||
+ | else { Assume btSOAP } | ||
+ | begin | ||
+ | SynaHttp.MimeType := sTextXML; | ||
+ | SynaHttp.Headers.Add(GetSOAPActionHeader); | ||
+ | end; | ||
+ | |||
+ | SynaHttp.UserName := FUserName; | ||
+ | SynaHttp.Password := FPassword; | ||
+ | |||
+ | if FProxy <> '' then | ||
+ | begin | ||
+ | ParseURL(FProxy, Protocol, pUser, pPass, Host, Port, Path, Para); | ||
+ | SynaHttp.ProxyHost := Host; | ||
+ | SynaHttp.ProxyPort := Port; | ||
+ | SynaHttp.ProxyUser := pUser; | ||
+ | SynaHttp.ProxyPass := pPass; | ||
+ | end; | ||
+ | |||
+ | SynaHttp.Protocol := '1.0'; | ||
+ | SynaHttp.UserAgent := 'CustomSoap'; | ||
+ | end; | ||
+ | |||
+ | procedure PostData(const Request: TStream; Response: TStream); | ||
+ | var | ||
+ | SynaHTTP: THTTPSend; | ||
+ | begin | ||
+ | SynaHTTP := THTTPSend.Create; | ||
+ | try | ||
+ | SetupSyna(SynaHttp); | ||
+ | |||
+ | Request.Position := 0; | ||
+ | SynaHTTP.Document.LoadFromStream(Request); | ||
+ | SynaHTTP.Document.Position := 0; | ||
+ | |||
+ | if SynaHTTP.HTTPMethod('POST', FURL) then | ||
+ | begin | ||
+ | Response.CopyFrom(SynaHTTP.Document, 0); | ||
+ | |||
+ | FContentType := SynaHTTP.Headers.Values[SContentType]; | ||
+ | FMimeBoundary := GetMimeBoundaryFromType(FContentType); | ||
+ | |||
+ | CheckContentType; | ||
+ | end | ||
+ | else | ||
+ | raise ESOAPHTTPException.Create(SInvalidHTTPResponse); | ||
+ | |||
+ | finally | ||
+ | FreeAndNil(SynaHTTP); | ||
+ | end; | ||
+ | end; | ||
+ | {$ENDIF} | ||
+ | </code> | ||
+ | |||
+ | then change: | ||
+ | <code delphi> | ||
+ | {$IFDEF USE_INDY} | ||
+ | PostData(Request, Response); | ||
+ | {$ELSE} | ||
+ | ... | ||
+ | {$ENDIF} | ||
+ | </code> | ||
+ | |||
+ | with | ||
+ | |||
+ | <code delphi> | ||
+ | {$IFDEF USE_SYNA} | ||
+ | PostData(Request, Response); | ||
+ | {$ELSE} | ||
+ | {$IFDEF USE_INDY} | ||
+ | PostData(Request, Response); | ||
+ | {$ELSE} | ||
+ | ... | ||
+ | {$ENDIF} | ||
+ | {$ENDIF} | ||
+ | </code> | ||
+ | |||
+ | Enjoy | ||