问题:如何调试 WCF 服务 - 我无法在服务内打断点
使用 VS2012 和 NUnit/TestDriven
只要我在 WcfHostApplication 上的 Ctrl F5 之前启动了服务,我就可以很好地运行我的测试。我在 Visual Studio 中托管。
尝试将 Web.Config 放入 WcfHostConsoleApplication 并将调试设置为 true。
这个示例应用程序来自这里
//hack to get working as we're not using wsdl yet...mimicking what happens in wsdl
[ServiceContract(Namespace = "http://www.programgood.net/examples/2012/09/wcf")]
public interface IHelloWcfService
{
[OperationContract]
string SayHello(string msg);
}
namespace HelloWcfTests
{
[TestFixture]
public class HelloWcfServiceLibrary_Tests
{
[Test]
public void SayHello_GivenHello_ShouldReturn()
{
//in reality add Service Ref.. using another special interface called IMetaDataExchange
IHelloWcfService proxy = ChannelFactory<IHelloWcfService>.CreateChannel(
new NetTcpBinding(),
new EndpointAddress("net.tcp://localhost:9000/HelloWcfEndPoint"));
string msg = "hello";
string result = proxy.SayHello(msg);
StringAssert.StartsWith("You entered: hello", result);
}
}
}