locked
Using SoapExtension on client proxy generated by "Add service reference" RRS feed

  • Question

  • Hi,
    I'd like to log SOAP messages sended via the web service. I'm using .NET 3.5 and that's why in Visual Studio there is only possibility to "Add service reference" and not "Add web reference". When I create the proxy, it works ok, no problem, but the SoapExtension doesn't work. If I add the <MySoapExtension()> attribute to the proxy method, nothing happens. If I switch to .NET 2.0 and reference the web service using "Add web reference", it works perfectly. Could you please tell me, how to use SoapExtension in the proxy class generated using "Add service reference", if it's possible ?

    Thanks a lot

    Filip
    Wednesday, November 18, 2009 2:53 PM

Answers

  • Hi,

    You can use messageinspector to log the soap messages alone. Please find below a sample that logs the messages to console application. You add some DAL code there to log it to your database.

    http://cid-05c2e50f2c5140c1.skydrive.live.com/self.aspx/.Public/CustomBehavior.rar

    Or you can write your won custom trace listener.
    http://www.15seconds.com/issue/020910.htm
    Please mark the response as answers if it solves your question or vote as helpful if you find it helpful. http://thoughtorientedarchitecture.blogspot.com/
    • Proposed as answer by Haripraghash Thursday, November 19, 2009 1:10 AM
    • Marked as answer by Filip Mateasko Thursday, November 19, 2009 11:26 AM
    Thursday, November 19, 2009 1:10 AM

All replies

  • Hi,
    Soap extensions were for ASMX services and for WCF services you have lots of extensibility points. Can you please tell us what exactly you are looking to do. To log soap messages you can use wcf configuration editor and use message logging.
    Please mark the response as answers if it solves your question or vote as helpful if you find it helpful. http://thoughtorientedarchitecture.blogspot.com/
    Wednesday, November 18, 2009 3:08 PM
  • Hi,
    thanks for the response. I'd like to log the incomming and ountgoing soap messages. I have found already the WCF message logging too, however, I'm not able to find how to configure it to log only the sended and received messages.

    And second - I'd like to store these logs into database, so I think I should create some custom listener, however don't know how to do that.
    These were the SoapExtension methods I used (copied from some tutorial on web) - they were used into txt file and I'd like to do something similar, but into database

        ' Write the SOAP message out to a file.

        Public Sub WriteOutput(ByVal message As SoapMessage)

            newStream.Position = 0

            Dim fs As New FileStream(_filename, FileMode.Append, FileAccess.Write)

            Dim w As New StreamWriter(fs)

            w.WriteLine("-----Response at " + DateTime.Now.ToString())

            w.Flush()

            Copy(newStream, fs)

            w.Close()

            newStream.Position = 0

            Copy(newStream, oldStream)

        End Sub

     

        ' Write the SOAP message out to a file.

        Public Sub WriteInput(ByVal message As SoapMessage)

            Copy(oldStream, newStream)

            Dim fs As New FileStream(_filename, FileMode.Append, _

                                     FileAccess.Write)

            Dim w As New StreamWriter(fs)

     

            w.WriteLine("----- Request at " + DateTime.Now.ToString())

            w.Flush()

            newStream.Position = 0

            Copy(newStream, fs)

            w.Close()

            newStream.Position = 0

        End Sub

    Filip

    Wednesday, November 18, 2009 4:32 PM
  • Hi,

    You can use messageinspector to log the soap messages alone. Please find below a sample that logs the messages to console application. You add some DAL code there to log it to your database.

    http://cid-05c2e50f2c5140c1.skydrive.live.com/self.aspx/.Public/CustomBehavior.rar

    Or you can write your won custom trace listener.
    http://www.15seconds.com/issue/020910.htm
    Please mark the response as answers if it solves your question or vote as helpful if you find it helpful. http://thoughtorientedarchitecture.blogspot.com/
    • Proposed as answer by Haripraghash Thursday, November 19, 2009 1:10 AM
    • Marked as answer by Filip Mateasko Thursday, November 19, 2009 11:26 AM
    Thursday, November 19, 2009 1:10 AM
  • Thanks - message inspector was what I was looking for. Thanks for your example. I found a good sample also here. http://weblogs.asp.net/paolopia/archive/2007/08/23/writing-a-wcf-message-inspector.aspx

    Filip
    Thursday, November 19, 2009 11:26 AM