Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
Examine XML of Web Service Response

While working on winning Netflix' million, I came across a need to examine the raw XML returned by a third party web service.  After a couple desk-pounding hours, I finally found a simple solution which works equally well in both Web and Windows apps.

  1. Install Web Services Enhancements (WSE) 3.0
  2. Add a project reference to Microsoft.Web.Services3
  3. Modify the web service proxy to inherit from Microsoft.Web.Services3.WebServicesClientProtocol instead of System.Web.Services.Protocols.SoapHttpClientProtocol.  (This augments the proxy's capabilities.)
  4. The response's raw XML may then be retrieved immediately after the call to Invoke as ResponseSoapContext.Envelope.InnerXml

Optionally, log4net may be employed so as not to interrupt the application while it goes about its business...

  1. Add a project reference to log4net
  2. Add log4net configuration to app.config or web.config.  For example:

    <!-- If you want to turn log4net off completely,
    include threshold="OFF" below
    -->

    <log4net threshold="ON">

        <appender name="LogAllToFile"
            type="log4net.Appender.FileAppender">

            <file value="MyLog.log"/>

            <appendToFile value="false"/>

            <layout type="log4net.Layout.PatternLayout">

                <conversionPattern
                    value="%d [%t] %-5l - %m%n%n"/>

            </layout>

        </appender>

        <root>

            <!-- ALL, DEBUG, INFO, WARN,
            ERROR, FATAL, OFF
    -->

            <priority value="ALL"/>

            <appender-ref ref="LogAllToFile"/>

        </root>

    </log4net>

  3. Initialize log4net when the application starts with a call to XmlConfigurator.Configure();
  4. Add the following code immediately after the call to Invoke in the proxy web service:

    log4net.ILog logger = log4net.LogManager.GetLogger(typeof(MyProxyClassName));

    logger.Info(ResponseSoapContext.Envelope.InnerXml);

With log4net turned on, the raw XML within the web service response will get written out to the log file and the application will not be interrupted.

Billy


Posted 10-09-2006 4:29 PM by Billy McCafferty
Filed under: , ,

[Advertisement]

Comments

getting the response message from web service call | keyongtech wrote getting the response message from web service call | keyongtech
on 01-22-2009 4:06 AM

Pingback from  getting the response message from web service call | keyongtech

Chuck Bevitt wrote re: Examine XML of Web Service Response
on 04-02-2010 3:38 PM

The first method using Microsoft.Web.Services3.WebServicesClientProtocol doesn't work if the call to the web service throws an exception. I'm getting an exception: "Response is not well-formed XML" with an inner exception: "Element 'Envelope' was not found. Line 1, position 2". I want to look at the raw HTTP response, but at this point the ResponseSoapContext object is null. It would seem that somewhere deep in the bowels of Microsoft.Web.Services3 you should be able to get the raw response, but I haven't found it.

free acai berry weight loss pills wrote re: Examine XML of Web Service Response
on 05-07-2010 3:27 AM

Difficult Marry,speak winner draw link add attention stay launch kind proportion church fruit teaching eye failure sure culture security spend where music daughter either aspect recent your believe loss mother answer basic inform role score lawyer idea send incident feel show direct tomorrow clear exercise detail note dress painting deny obviously bring ride play vast prime agent may do few guide train time wonderful confirm tonight unable seriously traffic straight hit occur important friend significance development effect circumstance factory publication following effectively ought victim lay give evidence facility background hold ground as simple

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Subscribe
Google Reader or Homepage

del.icio.us CodeBetter.com Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl CodeBetter.com Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of Devlicio.us
Red-Gate Tools For SQL and .NET

NDepend

SlickEdit
 
SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
LiteAccounting.Com
DevExpress
Fixx
NHibernate Profiler
Unfuddle
Balsamiq Mockups
Scrumy
JetBrains - ReSharper
Umbraco
NServiceBus
RavenDb
Web Sequence Diagrams
Ducksboard<-- NEW Friend!

 



Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers

 

Community Server (Commercial Edition)