How to use Fiddler to monitor WCF service

前端 未结 10 554
情话喂你
情话喂你 2020-11-27 10:20

I have a WCF service that accepts a complex type and returns some data. I want to use Fiddler to see what the incoming requests to the service looks like. The client is .ne

相关标签:
10条回答
  • 2020-11-27 10:25

    This is straightforward if you have control over the client that is sending the communications. All you need to do is set the HttpProxy on the client-side service class.

    I did this, for example, to trace a web service client running on a smartphone. I set the proxy on that client-side connection to the IP/port of Fiddler, which was running on a PC on the network. The smartphone app then sent all of its outgoing communication to the web service, through Fiddler.

    This worked perfectly.

    If your client is a WCF client, then see this Q&A for how to set the proxy.

    Even if you don't have the ability to modify the code of the client-side app, you may be able to set the proxy administratively, depending on the webservices stack your client uses.

    0 讨论(0)
  • 2020-11-27 10:31

    Standard WCF Tracing/Diagnostics

    If for some reason you are unable to get Fiddler to work, or would rather log the requests another way, another option is to use the standard WCF tracing functionality. This will produce a file that has a nice viewer.

    Docs

    See https://docs.microsoft.com/en-us/dotnet/framework/wcf/samples/tracing-and-message-logging

    Configuration

    Add the following to your config, make sure c:\logs exists, rebuild, and make requests:

      <system.serviceModel>
        <diagnostics>
          <!-- Enable Message Logging here. -->
          <!-- log all messages received or sent at the transport or service model levels -->
          <messageLogging logEntireMessage="true"
                          maxMessagesToLog="300"
                          logMessagesAtServiceLevel="true"
                          logMalformedMessages="true"
                          logMessagesAtTransportLevel="true" />
        </diagnostics>
      </system.serviceModel>
    
      <system.diagnostics>
        <sources>
          <source name="System.ServiceModel" switchValue="Information,ActivityTracing"
            propagateActivity="true">
            <listeners>
              <add name="xml" />
            </listeners>
          </source>
          <source name="System.ServiceModel.MessageLogging">
            <listeners>
              <add name="xml" />
            </listeners>
          </source>
        </sources>
        <sharedListeners>
          <add initializeData="C:\logs\TracingAndLogging-client.svclog" type="System.Diagnostics.XmlWriterTraceListener"
            name="xml" />
        </sharedListeners>
        <trace autoflush="true" />
      </system.diagnostics>
    
    0 讨论(0)
  • 2020-11-27 10:32

    Consolidating the caveats mentioned in comments/answers for several use cases.

    Mostly, see http://docs.telerik.com/fiddler/Configure-Fiddler/Tasks/ConfigureDotNETApp

    • Start Fiddler before your app
    • In a console app, you might not need to specify the proxyaddress:

      <proxy bypassonlocal="False" usesystemdefault="True" />
      
    • In a web application / something hosted in IIS, you need to add the proxyaddress:

      <proxy bypassonlocal="False" usesystemdefault="True" proxyaddress="http://127.0.0.1:8888" />
      
    • When .NET makes a request (through a service client or HttpWebRequest, etc) it will always bypass the Fiddler proxy for URLs containing localhost, so you must use an alias like the machine name or make up something in your 'hosts' file (which is why something like localhost.fiddler or http://HOSTNAME works)
    • If you specify the proxyaddress, you must remove it from your config if Fiddler isn't on, or any requests your app makes will throw an exception like:

      No connection could be made because the target machine actively refused it 127.0.0.1:8888

    • Don't forget to use config transformations to remove the proxy section in production
    0 讨论(0)
  • 2020-11-27 10:32

    You can use the Free version of HTTP Debugger.

    It is not a proxy and you needn't make any changes in web.config.

    Also, it can show both; incoming and outgoing HTTP requests. HTTP Debugger Free

    0 讨论(0)
  • 2020-11-27 10:36

    You need to add this in your web.config

    <system.net>
      <defaultProxy>
        <proxy bypassonlocal="False" usesystemdefault="True" proxyaddress="http://127.0.0.1:8888" />
      </defaultProxy>
    </system.net>
    
    1. then Start Fiddler on the WEBSERVER machine.
    2. Click Tools | Fiddler Options => Connections => adjust the port as 8888.(allow remote if you need that)
    3. Ok, then from file menu, capture the traffic.

    That's all, but don't forget to remove the web.config lines after closing the fiddler, because if you don't it will make an error.

    Reference : http://fiddler2.com/documentation/Configure-Fiddler/Tasks/UseFiddlerAsReverseProxy

    0 讨论(0)
  • 2020-11-27 10:37

    Fiddler listens to outbound requests rather than inbound requests so you're not going to be able to monitor all the requests coming in to your service by using Fiddler.

    The best you're going to get with Fiddler is the ability to see all of the requests as they are generated by your Console App (assuming that the app generates web requests rather than using some other pipeline).

    If you want a tool that is more powerful (but more difficult to use) that will allow you to monitor ALL incoming requests, you should check out WireShark.

    Edit

    I stand corrected. Thanks to Eric Law for posting the directions to configuring Fiddler to be a reverse proxy!

    0 讨论(0)
提交回复
热议问题