2

Using Fiddler I want to trace a call to an external webservice made in the body of an ASP.NET MVC action method.

When I run this code as a console application or Nunit test I can see the request/response to the external server using Fiddler;

[Test]
public void TestWebservice() 
{   
    MyWebService checker = new MyWebService();
    i = checker.GetAge("bob");
    Assert.True(i >= 0); 
}

When I call the webservice from an ASP.MVC action method I can't see the underlying request to the external server, although I can see the request to the action method from my browser;

public ActionResult MakeTheCall(string name)
{
    MyWebService checker = new MyWebService();
    i = checker.GetAge(name);
    return View();
}

Is there a way for Fiddler to show the request/response to a third party webservice made in the body of an ASP.NET MVC action method?

politus
  • 5,996
  • 1
  • 33
  • 42
  • Is the third party webservice hosted on localhost or a remote host? – sandyiit Jul 05 '11 at 10:22
  • One question, if the network fails to respond when you're testing your Web Service, are you expecting your test to unit test to fail? What happens if it's simply a network problem and your unit tests start failing? Is that what you intend? – Jamie Dixon Jul 05 '11 at 10:23
  • @sandyiit - the third party webservice is on a remote host. @JamieDixon yes, if the network is down the test will fail. Don't worry about this - This code is just to illustrate calling the webservice another way, I could equally have put this as a console app. – politus Jul 05 '11 at 10:35
  • 1
    Can you try setting Fiddler as a proxy, and use the Fiddler proxy when you call the webservice – sandyiit Jul 05 '11 at 10:47
  • 1
    details about how to set it up at http://www.fiddler2.com/fiddler/help/hookup.asp – sandyiit Jul 05 '11 at 10:48
  • GlobalProxySelection.Select = new WebProxy("127.0.0.1", 8888); added to the Application_Start method in a ASP.NET MVC web application works, thanks @sandyiit. – politus Jul 05 '11 at 13:01

2 Answers2

2

Moving the answer from comments to Answer section:

Can you try setting Fiddler as a proxy, and use the Fiddler proxy when you call the webservice

details about how to set it up at http://fiddler2.com/fiddler/help/hookup.asp

sandyiit
  • 1,597
  • 3
  • 17
  • 23
  • 1
    GlobalProxySelection.Select = new WebProxy("127.0.0.1", 8888); added to the Application_Start method in a ASP.NET MVC web application works – politus Jul 06 '11 at 14:10
  • 1
    GlobalProxySelection is now deprecated - use `WebRequest.DefaultWebProxy = new WebProxy("127.0.0.1", 8888);` instead – phuzi Nov 21 '13 at 11:15
1

You can set up Fiddler as a reverse proxy and have it forward local calls on a given port to a remote server on a different port. So, you configure your app to call localhost:8888 and Fiddler forwards to remote:80.

http://www.fiddler2.com/fiddler/help/reverseproxy.asp

Another option is Charles which has easier configuration for this setup.

http://www.charlesproxy.com/

Samuel Neff
  • 73,278
  • 17
  • 138
  • 182