Board index » delphi » Compressing and encrypting SOAP messages

Compressing and encrypting SOAP messages


2005-06-30 08:05:07 PM
delphi239
Has anyone had any success with compressing and encrypting the SOAP data
just before it goes down the wire? I understand that one is supposed to
perform this in the BeforeExecute and AfterExecute events but something
seems to stop it.
 
 

Re:Compressing and encrypting SOAP messages

Mischa Simmonds writes:
Quote
Has anyone had any success with compressing and encrypting the SOAP
data just before it goes down the wire? I understand that one is
supposed to perform this in the BeforeExecute and AfterExecute events
but something seems to stop it.
Check out :
www.agnisoft.com/white_papers/advancedws/default.asp
--
Deepak Shenoy (TeamB)
Agni Software (www.agnisoft.com)
Blog: shenoyatwork.blogspot.com
 

Re:Compressing and encrypting SOAP messages

I took a quick look at the article. I don't see where the data is going from
the file to the array... so I am assuming that the array is holding the entire
file. This would be silly for large files and would peg server memory, as well
as client memory.
I recommend another approach.
Build a TStream like interface as a web service, then use a TStream wrapper
around the interface. That way you can download the file in chunks and file
transfers might look something like this:
RemoteFile:= MyWebService.GetFile(FileName);
StreamWrapper:= TStreamWrapper.Create(RemoteFile);
LocalFile:= TFileStream.Create('C:\Temp\BlaBla.xyz', fmCreate);
LocalFile.CopyFrom(StreamWrapper, 0);
-Bill
"Deepak Shenoy (TeamB)" <XXXX@XXXXX.COM>writes
Quote
Mischa Simmonds writes:

>Has anyone had any success with compressing and encrypting the SOAP
>data just before it goes down the wire? I understand that one is
>supposed to perform this in the BeforeExecute and AfterExecute events
>but something seems to stop it.

Check out :
www.agnisoft.com/white_papers/advancedws/default.asp

--
Deepak Shenoy (TeamB)
Agni Software (www.agnisoft.com)
Blog: shenoyatwork.blogspot.com
 

Re:Compressing and encrypting SOAP messages

Deepak Shenoy (TeamB) writes:
Quote
Mischa Simmonds writes:

>as anyone had any success with compressing and encrypting the SOAP
>data just before it goes down the wire? I understand that one is
>supposed to perform this in the BeforeExecute and AfterExecute events
>but something seems to stop it.
>
>

Check out :
www.agnisoft.com/white_papers/advancedws/default.asp

Thanks for that. Actually I had already looked into that one, but the
problem is with BeforeExecute on the client side. It uses WideString,
not TStream, so any NULL in the data is going to be a problem. Any
compressed or encrypted data is bound to have a NULL in there somewhere.
So, I can compress/encrypt from the server to the client, but not the
other way round!!
procedure TForm1.HTTPRIO1BeforeExecute(const MethodName: String; var
SOAPRequest: WideString);
 

Re:Compressing and encrypting SOAP messages

William Egge writes:
Quote
I took a quick look at the article. I don't see where the data is
going from the file to the array... so I am assuming that the array
is holding the entire file. This would be silly for large files and
would peg server memory, as well as client memory.
Ah yes - I was only doing a demo there. You should absolutely save it
to a file or database or whatever.
--
Deepak Shenoy (TeamB)
Agni Software (www.agnisoft.com)
Blog: shenoyatwork.blogspot.com
 

Re:Compressing and encrypting SOAP messages

Ahh..Sorry, I didn't connect your name to being the author of the
article. Thanks for that, it has given me a few ideas. But my comments
still stand. With WideString being utilised in the BeforeExecute on the
client side, the compression/encryption can only be one way.
Deepak Shenoy (TeamB) writes:
Quote
Ah yes - I was only doing a demo there. You should absolutely save it
to a file or database or whatever.

 

Re:Compressing and encrypting SOAP messages

Mischa Simmonds writes:
Quote
Thanks for that. Actually I had already looked into that one, but the
problem is with BeforeExecute on the client side. It uses WideString,
not TStream, so any NULL in the data is going to be a problem. Any
compressed or encrypted data is bound to have a NULL in there
somewhere. So, I can compress/encrypt from the server to the client,
but not the other way round!!

procedure TForm1.HTTPRIO1BeforeExecute(const MethodName: String; var
SOAPRequest: WideString);
Ok, I see what you mean. Here's a way:
1) Write a descendant component from THttpRio (call it THTTPRioEnh)
2) Declare a type like so:
TBeforeExecuteStreamEvent = procedure(const MethodName: string; Request
: TStream) of object;
3) In the THTTPRioEnh class, declare a published variable of type:
property OnBeforeExecuteStream: TBeforeExecuteStreamEvent read
FOnBeforeExecuteStream write FOnBeforeExecuteStream;
Hit Ctrl+Shift+C. The private variable should get declared
automatically.
4) override the DoBeforeExecute procedure and in it put:
procedure DoBeforeExecute(const MethodName: string; Request: TStream);
begin
inherited DoBeforeExecute(MethodName: string; Request: TStream);
if Assigned( FOnBeforeExecuteStream ) then
FOnBeforeExecuteStream( MethodName, Request );
end;
Then register and all that stuff.
You can then assign a handler to OnbeforeExecutestream of this
inherited component.
I am lazy, so I did all this in Rio.Pas and instead of creating a
handler in the IDE I set this up in code instead, something like:
HTTPRio1.OnBeforeExecuteStream := BeforeExecuteStream;
Where I do the modifications to the request stream.
Hope this helps,
--
Deepak Shenoy (TeamB)
Agni Software (www.agnisoft.com)
Blog: shenoyatwork.blogspot.com
 

Re:Compressing and encrypting SOAP messages

Mischa Simmonds writes:
Quote
>Ah yes - I was only doing a demo there. You should absolutely save
>it to a file or database or whatever.
>
Look at my reply to Mischa - I have cracked this by introducing another
kind of response handler.
--
Deepak Shenoy (TeamB)
Agni Software (www.agnisoft.com)
Blog: shenoyatwork.blogspot.com
 

Re:Compressing and encrypting SOAP messages

After reading your article I have used yor method of compressing soap and
it is a fantastic increase in performance when recieving responses thankyou,
however I have been trying to apply the same compression to the request and
I can't seem to Decompress the request on the server side.
I have tried overriding the pascalinvoker.invoke method and pretty much any
method I can find that would appear to be a good place to start but it just
won't work.
Have you or anyone else managed to get round this at all?
thanks again
jim
"Deepak Shenoy (TeamB)" <XXXX@XXXXX.COM>writes
Quote
Mischa Simmonds writes:

>Thanks for that. Actually I had already looked into that one, but the
>problem is with BeforeExecute on the client side. It uses WideString,
>not TStream, so any NULL in the data is going to be a problem. Any
>compressed or encrypted data is bound to have a NULL in there
>somewhere. So, I can compress/encrypt from the server to the client,
>but not the other way round!!
>
>procedure TForm1.HTTPRIO1BeforeExecute(const MethodName: String; var
>SOAPRequest: WideString);

Ok, I see what you mean. Here's a way:
1) Write a descendant component from THttpRio (call it THTTPRioEnh)

2) Declare a type like so:
TBeforeExecuteStreamEvent = procedure(const MethodName: string; Request
: TStream) of object;

3) In the THTTPRioEnh class, declare a published variable of type:
property OnBeforeExecuteStream: TBeforeExecuteStreamEvent read
FOnBeforeExecuteStream write FOnBeforeExecuteStream;

Hit Ctrl+Shift+C. The private variable should get declared
automatically.

4) override the DoBeforeExecute procedure and in it put:

procedure DoBeforeExecute(const MethodName: string; Request: TStream);
begin
inherited DoBeforeExecute(MethodName: string; Request: TStream);

if Assigned( FOnBeforeExecuteStream ) then
FOnBeforeExecuteStream( MethodName, Request );
end;

Then register and all that stuff.

You can then assign a handler to OnbeforeExecutestream of this
inherited component.

I am lazy, so I did all this in Rio.Pas and instead of creating a
handler in the IDE I set this up in code instead, something like:

HTTPRio1.OnBeforeExecuteStream := BeforeExecuteStream;

Where I do the modifications to the request stream.

Hope this helps,

--
Deepak Shenoy (TeamB)
Agni Software (www.agnisoft.com)
Blog: shenoyatwork.blogspot.com
 

Re:Compressing and encrypting SOAP messages

james rimell writes:
Quote
After reading your article I have used yor method of compressing
soap and it is a fantastic increase in performance when recieving
responses thankyou, however I have been trying to apply the same
compression to the request and I can't seem to Decompress the
request on the server side.
I've been able to do this. Let me know where I could mail you and I'll
get my project over...
Cheers,
--
Deepak Shenoy (TeamB)
Blog: shenoyatwork.blogspot.com
 

Re:Compressing and encrypting SOAP messages

That would be great
my email is as follows....
jrimell at vecta dot net
thanks
"Deepak Shenoy (TeamB)" <XXXX@XXXXX.COM>writes
Quote
james rimell writes:

>After reading your article I have used yor method of compressing
>soap and it is a fantastic increase in performance when recieving
>responses thankyou, however I have been trying to apply the same
>compression to the request and I can't seem to Decompress the
>request on the server side.

I've been able to do this. Let me know where I could mail you and I'll
get my project over...

Cheers,

--
Deepak Shenoy (TeamB)
Blog: shenoyatwork.blogspot.com
 

Re:Compressing and encrypting SOAP messages

can i have a copy as well please.
--
please remove _1 from email address.
"After all, what is education but a process by which a person begins to
learn how to learn?" Peter Ustinov Dear Me(1977)
"Deepak Shenoy (TeamB)" <XXXX@XXXXX.COM>writes
Quote
james rimell writes:

>After reading your article I have used yor method of compressing
>soap and it is a fantastic increase in performance when recieving
>responses thankyou, however I have been trying to apply the same
>compression to the request and I can't seem to Decompress the
>request on the server side.

I've been able to do this. Let me know where I could mail you and I'll
get my project over...

Cheers,

--
Deepak Shenoy (TeamB)
Blog: shenoyatwork.blogspot.com
 

Re:Compressing and encrypting SOAP messages

And a copy for me please. can not wait.
PS: I am actually a C++Builder user. So I can only have as much Pascal
as C++Builder can take ;-)
I notice some comments that ZLIB is available for Delphi users, but it
is not available for C++Builder. I have been using it anyway, but when I
read a memory buffer I have avoid a little of the header.
xtcsuk writes:
Quote
can i have a copy as well please.



 

Re:Compressing and encrypting SOAP messages

Sorry, my email adress is mischa at informationdesign dot com dot au
Thanks
xtcsuk writes:
Quote
can i have a copy as well please.



 

Re:Compressing and encrypting SOAP messages

Had a look at this. But I'd have suspected that you would need to
overide "function THTTPReqResp.Send(const S: WideString): Integer;" in
SOAPHTTPTrans.pas which calls HttpSendRequest (wininet.pas), as it is
expecting a WideString as well, as well as the UTF8Encode function.
Deepak Shenoy (TeamB) writes:
Quote
Ok, I see what you mean. Here's a way:
1) Write a descendant component from THttpRio (call it THTTPRioEnh)

2) Declare a type like so:
TBeforeExecuteStreamEvent = procedure(const MethodName: string; Request
: TStream) of object;

3) In the THTTPRioEnh class, declare a published variable of type:
property OnBeforeExecuteStream: TBeforeExecuteStreamEvent read
FOnBeforeExecuteStream write FOnBeforeExecuteStream;

Hit Ctrl+Shift+C. The private variable should get declared
automatically.

4) override the DoBeforeExecute procedure and in it put:

procedure DoBeforeExecute(const MethodName: string; Request: TStream);
begin
inherited DoBeforeExecute(MethodName: string; Request: TStream);

if Assigned( FOnBeforeExecuteStream ) then
FOnBeforeExecuteStream( MethodName, Request );
end;

Then register and all that stuff.

You can then assign a handler to OnbeforeExecutestream of this
inherited component.

I am lazy, so I did all this in Rio.Pas and instead of creating a
handler in the IDE I set this up in code instead, something like:

HTTPRio1.OnBeforeExecuteStream := BeforeExecuteStream;

Where I do the modifications to the request stream.

Hope this helps,