If you need to test the service logic, you can write simple unit tests, as shown below:
public class Service1 : IService1 { public string GetData(int value) { return string.Format("You entered: {0}", value); } }
And if you want to test all the integration, you can write the following integration tests. In a nutshell, you need to run your service as a standalone and use _proxy to execute the service methods. Such tests are useful when you need to test extensibility points, such as a custom message inspector, error handlers, etc.
private ITestService _proxy; private ServiceHost _host; [SetUp] public void Initialize() { const string baseAddress = "net.pipe://localhost/TestService"; _host = new ServiceHost(typeof(TestService), new Uri(baseAddress)); var factory = new ChannelFactory<ITestService>(new NetNamedPipeBinding(), new EndpointAddress(baseAddress)); _host.Open(); _proxy = factory.CreateChannel(); }
References:
Integration Testing WCF Services
source share