If you need to test logic behind services you can write simple unit tests like shown below:
public class Service1 : IService1
{
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}
}
//Tests
[TestFixture]
public class MyService_Test
{
[Test]
public void GetData_should_return_entered_string()
{
Service1 service = new Service1();
Assert.AreEqual("You entered: 1", service.GetData(1));
}
}
And if you want to test whole integration you can write the following integration tests. In a nutshell you need to run your service as self-hosted and use _proxy to execute service methods. Such tests are useful when you need to test extensibility points like 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();
}
Links:
Integration Testing WCF Services