Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7858853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:37:55+00:00 2026-06-02T21:37:55+00:00

We are about to begin architecting a service oriented framework (SOA) which will certainly

  • 0

We are about to begin architecting a service oriented framework (SOA) which will certainly involve a high number of of granular web services (REST in WCF). We’ve been quite disciplined in unit testing our client and server-side code base, however we don’t have much of any experience in unit testing web services. We’re really looking for guidance as to where the tests should be written and recommendations on what approach to use when unit testing our services.

Should we write tests that make http requests and assert that the responses are what they should be? Should we focus on just testing the internal logic of the service methods themselves and not worry about testing the actual requests? Or should we do both? Are there any other recommendations for what we should be testing?

We’re really looking for some explanation and guidance and would truly appreciate any advice we can get.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T21:37:57+00:00Added an answer on June 2, 2026 at 9:37 pm

    I have found testing web services, specifically WCF client and server, useful on top of regular unit testing in the following scenarios:

    1. Acceptance testing where you want to black box test your whole service and poke things in at the extremities.
    2. Testing a specific WCF wire up, extension, behavior, etc.
    3. Testing that your interface and your data members are setup correctly.

    Most of the time I try to use a very basic setup with basic http and wire everything up in the code. Unless I am Integration or Acceptance testing I don’t test the client against the server, instead I mock one of them so that I can test the other in isolation. Below are examples of how I test WCF clients and services:

    public static ServiceHost CreateServiceHost<TServiceToHost>(TServiceToHost serviceToHost, Uri baseAddress, string endpointAddress)
    {
        var serviceHost = new ServiceHost(serviceToHost, new[] { baseAddress });
    
        serviceHost.Description.Behaviors.Find<ServiceDebugBehavior>().IncludeExceptionDetailInFaults = true;
        serviceHost.Description.Behaviors.Find<ServiceBehaviorAttribute>().InstanceContextMode = InstanceContextMode.Single;
    
        serviceHost.AddServiceEndpoint(typeof(TServiceToHost), new BasicHttpBinding(), endpointAddress);
    
        return serviceHost;
    }
    
    //Testing Service
    
    [TestFixture]
    class TestService
    {
        private ServiceHost myServiceUnderTestHost;
        private ChannelFactory<IMyServiceUnderTest> myServiceUnderTestProxyFactory;
        [SetUp]
        public void SetUp()
        {
            IMyServiceUnderTest myServiceUnderTest = new MyServiceUnderTest();
            myServiceUnderTestHost = CreateServiceHost<IMyServiceUnderTest>(myServiceUnderTest, new Uri("http://localhost:12345"), "ServiceEndPoint");
            myServiceUnderTestHost.Open();
    
            myServiceUnderTestProxyFactory = new ChannelFactory<IMyServiceUnderTest>(new BasicHttpBinding(), new EndpointAddress("http://localhost:12345/ServiceEndPoint")); 
        }
    
        [TearDown]
        public void TearDown()
        {
            myServiceUnderTestProxyFactory.Close();
            myServiceUnderTestHost.Close();
        }
    
        [Test]
        public void SomeTest() 
        {
            IMyServiceUnderTest serviceProxy = myServiceUnderTestProxyFactory.CreateChannel();
    
            serviceProxy.SomeMethodCall();
        }
    }
    
    //Testing Client
    
    [TestFixture]
    class TestService
    {
        private ServiceHost myMockedServiceUnderTestHost;
        private IMyServiceUnderTest myMockedServiceUnderTest;
    
        [SetUp]
        public void SetUp()
        {
            myMockedServiceUnderTest = Substitute.For<IMyServiceUnderTest>(); //Using nsubstitute
            myServiceUnderTestHost = CreateServiceHost<IMyServiceUnderTest>(myMockedServiceUnderTest, new Uri("http://localhost:12345"), "ServiceEndPoint");
            myServiceUnderTestHost.Open();
        }
    
        [TearDown]
        public void TearDown()
        {
            myServiceUnderTestHost.Close();
        }
    
        [Test]
        public void SomeTest() 
        {
            //Create client and invoke methods that will call service
            //Will need some way of configuring the binding
            var client = new myClientUnderTest();
    
            client.DoWork();
    
            //Assert that method was called on the server
            myMockedServiceUnderTest.Recieved().SomeMethodCall();
        }
    }
    

    NOTE

    I had forgot to mention that if you want to mock a WCF service using anything that uses castles dynamic proxy then you will need to prevent the ServiceContractAttribute from being copied to the mock. I have a blog post on this but basically you register the attribute as one to prevent from replication before you create the mock.

    Castle.DynamicProxy.Generators.AttributesToAvoidReplicating
      .Add<ServiceContractAttribute>();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My team is about to begin a web project using the Symfony2 framework. We
My question concerns Google Web Toolkit (GWT). I'm about to begin development for a
We are about to begin work on an application that will eventually be deployed
I am about to begin writing a Rails application that will allow clients to
We are about to begin a project where we will be working with a
I've been thinking about the web app I'm about to begin developing and wondering
I'm a developer who's about to begin building a relatively complex web application. I
I am about to begin a web application. Before I begin, I would like
I am about to begin development of a web app in New Zealand for
I'm about to begin building a website using the ASP.NET MVC framework and I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.