WireMock.net stubbing WCF service calls

Viewed 563

I have a WCF service that runs on say http://localhost:8072/MyWCFService and need to setup a wiremock stub for a integration test. I have the following code as an initial attempt:

var server = WireMockServer.Start();
            server
                .Given(
                    Request.Create().WithPath("http://localhost:8072/").UsingPost()
                )
                .RespondWith(
                    Response.Create()
                        .WithStatusCode(200)
                        .WithHeader("Content-Type", "text/xml")
                        .WithBody("Hello world!")
                );

But this fails (the calling code just times out). Is Wiremock able to mock WCF SOAP calls ? If so, what setup is needed ? I'm guessing it's more complicated than my above naive attempt.

1 Answers

Mocking a service using WireMock.Net needs these steps:

  1. Start a WireMock.Net server using var server = WireMockServer.Start();.
  2. Get the URL where this WireMock.Net server is running with var url = server.Urls[0];
  3. Change you (client) code to use that url instead of the real url.
  4. Now when your real client code does a WCF call, this call is send to WireMock.Net and if this request is matched, your response is returned.

Another thing, in your example, you don't need a path like "http://localhost:8072/". In your case you can skip the WithPath or make WireMock.Net react on a path like /ThisIsMyApi

For more details, see the WIKI.

Related