Search code examples
.netvb.netweb-servicesunit-testingvisual-studio-debugging

Is it possible to interactively debug a web service while it's being executed in a Unit Test in VS2010?


Basically, I've got a pretty standard web service call, in a DLL project, running under the built debug server.

Looks something like this

<WebInvoke(Method:="POST", BodyStyle:=WebMessageBodyStyle.Bare, UriTemplate:="")>
Public Function POSTOrder(httpPostOrder As Contract.APIOrder) As Contract.Response.Order
    ....
    Return (httpResponse)
End Function

If I RUN the project, I can send XML POST requests to it using fiddler just fine, and if I set a breakpoint in the above function, it gets hit.

Now, I'd like to set up a simple unit test for this function, so I added a test project and this test:

<TestMethod()>
Public Sub TestPostOrder()
    Dim r As String
    Dim w As New Net.WebClient

    W.Headers.Add("Content-Type", "application/xml")
    Dim x =
            <?xml version="1.0"?>
            <order_info>
                <event_id>103153</event_id>
                <id>1</id>
                .....
            </order_info>
    r = w.UploadString("http://localhost:15034/orders/?api_key={sometext}", "POST", x.ToString)
End Sub

I know, not the greatest Unit Test in the world, but that's not the point right now.

So, When I run this test, it DOES run through and it's successful. I can even debug the unit test, step through it, and see that the UPLOADSTRING call does succeed and return valid information.

BUT, if I set a breakpoint in the actual function being tested, it's never hit.

I found this question

Can I debug while running a VS Unit Test?

but I tried that and no dice.

I'm guessing I don't have something configured quite right with the unit test, and so it's not starting the actual DLL in a context that can be debugged, but so far, I've turned up nothing.

Any ideas?


Solution

  • Yes, you can.

    Make sure your debugger is attached to the right process (IIS or Cassini process) that's hosting the actual service, not the Unit Test (which is only a client).

    What I would do is:

    • have a VS instance set to debug the web process
    • use the debugging instance to set any needed breakpoints
    • use another VS instance to run the test