How to log webservice call

How to log webservice call

  
Hi,

Anyone knows how do I log in a Database a WebService Request and Response in order to resend them if needed?

Thanks
Hi Rodrigo,

Unfortunately, I am not aware of away to access the response natively using the Web Services that the Agile Platform provides.

One way that I can think of to do it would be to consume the Web Services through an extension, and return two extra parameters - the Request and the Response.

Is this feasible in your scenario?

Regards,

Paulo Tavares
Any chance to implement this in EnhancedWebReferences extension?
Hi Rodrigo,

I don't think it is possible to do that using the EnhancedWebReferences.
We were able to log the request and response contents in a project by using a SoapExtension. Basically it is a filter that lies between .Net web services/references and the wire. Attached the extension that registers that SoapExtension and logs it to C:\Windows\Temp\«WebServiceName.log».
This code actually executes on a different context of the request you're doing, so you don't have access to anything else except what is in the webservice message itself. More info about SoapExtensions can be found here: http://msdn.microsoft.com/en-us/library/sd5sk0f5.aspx

But your actual requirement seems to be more complex than that... you'd like to actually resend the request. To do that you would need more than logging the contents...
My suggestion would be to use the XMLRecords component (here) to serialize the request parameters in XML, save them to the database, and if you do need to resend them use the component to deserialize the xml back into records/recordlists that you can use in a second webreference request.
Would that work?

Cheers
Thanks,

I'll try this and take a look at xmlrecords to see if it's enough
Hi Gonçalo,

One quick question: you mentioned that the soap logger extension (which we currently use for debugging purposes) executes "on a different context". What we would like is instead of logging the XML to a file, to actually store it in the database. Is that possible in an easy way (i.e. passing the data back to the eSpace consuming the extension), or does that require us to make the database connection etc. from the extension?

Thanks,


Kilian
Hi Kilian.
I don't think there is... i remember spending a lot of time trying to do that, but the .NET lifecycle of the soap extension was running in a totally different context, so there is no way to do that.
So what you can do is:
1. from the extension invoke a webservice back on the logger espace with the information to be logged (big overhead, for each webservic request, you end up with 2 :) )
2. log it to a file, and have a timer that periodically dumps that infor from the filesystem to the database
3. Use CustomLog (check this) - log it to a message queue, and use the same logic in the logging framework of the platform to pick the logged items in the message queue and bulk log it to the database. This has the highest performance and lower system overhead. It just requires you to understand a little bit how the CustomLog extension works, and copy/pasting some of it's code to the SoapLogger extension

Hope this helps!
I'll check it out, thanks so far.
Hi Gonçalo,

It seems dead simple to log something using CustomLog, the sole code seems to be this line:

RuntimeLogger.Log(new CustomLog(ssrecord));

However, I have no clue how to import a platform database table definition into the extension so that ssrecord has the right definition for the CustomLog to be able to log it. Can you give me any pointers there?

Thanks!
Hey Kilian,

Try the attached example... although it has some caveats in terms of maintainability (need to set the attribute names in the extension), it works :)
I'll tweak the example espace a bit, try to relate Request and Response on a single log detail message, and publish it as a component in the Network.
Meanwhile you might get what you need (just run it through IPP)
cheers
Hi Gonçalo,

I've been busy with some other stuff the past week, but I'll certainly take a look at this!

Thanks for this solution.

Is it possible to have a 5.x and 6.x implementation of this? I have looked at the extension and it works OK, but we have customers on 5.x and 6.x where
we would really like to use this!

regards, Paul
Paul, given that the extension has very little in terms of interface/structures etc., it should be rather easy to create a new extension in 5.x/6.x and copy the C# code over.
I agree, but i just wanted to see if anyone already did this, to save time!


regards, Paul

Well, I did, but afterwards extended it a bit, so I can't share it, sorry :).

We have a version for v6 now :-) and it works like a charm....

@Goncalo : How do we switch it off after a webservice call ?

I only want to use it for specific calls, now it starts logging and never stops ...
Joop Stringer wrote:
We have a version for v6 now :-) and it works like a charm....

@Goncalo : How do we switch it off after a webservice call ?

I only want to use it for specific calls, now it starts logging and never stops ...
 
 Out of my head.. I think you have to

 - Create a new variable/property in the soapextension class, to control whether logging is active or not

- Change the methods that are logging to check that variable

 

 - Create a new extension method that:

- obtains the current instance of the soap extension (check how I do it to check if the soap extension is already registered)

- Set the new property on that instance to True/False

 

Remember that SoapExtensions run outside of a particular request (they are like Singletons in the .Net pipeline). So, if there are 2 concurrent requests, you have no guarantee that once you set it to "off" it will occur or not (if the other request is concurrently setting it to "on")…

Hope it helps

Gonçalo Borrêga wrote:
 
 Out of my head.. I think you have to

 - Create a new variable/property in the soapextension class, to control whether logging is active or not

- Change the methods that are logging to check that variable

 

 - Create a new extension method that:

- obtains the current instance of the soap extension (check how I do it to check if the soap extension is already registered)

- Set the new property on that instance to True/False

 

Remember that SoapExtensions run outside of a particular request (they are like Singletons in the .Net pipeline). So, if there are 2 concurrent requests, you have no guarantee that once you set it to "off" it will occur or not (if the other request is concurrently setting it to "on")…

Hope it helps

 
 Niek created a new version based on this information.
I'll have to test it :-)
Joop Stringer wrote:
 
 Niek created a new version based on this information.
I'll have to test it :-)
 
 This is the new version. It is based on outsystems v6. With this version it is possible to enable and disable the logging. 
Niek created an additional function EnableSoapLogger which takes a boolean as input
That way you can enable/disable the soaplogger

Hi guys,

I've recently started using this to track calls to a third party system and there's a question to which I couldn't find the answer:
  • After you register the SOAPExtension what happens if there's recycle or IIS reset?
  • does you need to register it again or is it somehow stiky?
  • if you do need to register it again, is there a way to trap that event?
Thank you,
Pedro
Hi,
The Register SoapLogger action, as far as I can remember, already checks if the SoapExtension is registered, and won't register it again if it already is. When an IIS recycle occurs, the application will be reset and the SoapExtension will no longer be registered. As such, I think you should always call the RegisterSoapLogger (or check before if it is registered or not) as it is the only way to guarantee it is registered.

If you're using the EnableSoapLogger as well, take into consideration that with an IIS recycle, the value where it stores the enabled/disabled flag will also be lost, and reverted to the default (which I think is Enabled).

Last, I don't think there is an easy way to determine if there was a recycle... probably the simplest way to detect it is to store a static variable in an extension with information if the info you need is initialized. when he pool recycles, these static variables get reset, and you will know...
Is it possible to use this logging for the java stack (and specifically the weblogic stack) ?
Hello guys,
I'm (completely) new to outsystems, and was setting up a webservice call but something seems to go wrong when deserialising (I think), so I would really want to see my request xml... I set up the soaplogger extension, hoping this would do the trick, but I need to specify an object for "CustomLogEntityRecord" in "RegisterSoapLogger". What should I put here?
Thanx!
Kris
Hi Kris, welcome to the community. The "CustomLogEntityRecord" can be left empty, in which case the extension will write the logging to a text file (in the C:\Windows\Temp directory, with a .log extension, the name based on the web service name), which seems to be all you need for debugging.

If you want a more platform-accessible storage, you can store the logging in the database. For this to work you need to create a table (in an eSpace) with the following fields:
  • Type
  • Instant
  • Url
  • Action
  • Contents
Then you need to define a variable of type Record, with Record Definition set to that table, and pass it via the CustomLogEntityRecord parameter (using the built-in ToObject function, e.g. ToObject(myRec)). The extension will then log the web service calls in that database table.
Hey Kilian!
thanx a lot for your reply, it worked like a charm :-)
Great to hear, Kris.