遗留测试因WcfTestClient未启动抛出EndpointNotFoundException问题排查
WCF服务引用集成测试运行失败解决方案
直接在代码中指定端点地址(应急首选)
绕开配置文件和命令行参数的依赖,创建客户端时显式传入绑定与目标端点:var binding = new BasicHttpBinding(); // 根据服务实际绑定类型调整,如WSHttpBinding var endpointAddr = new EndpointAddress("http://localhost:8733/Design_Time_Addresses/XXX"); using (var client = new DesignTime2ServiceReference.XXXClient(binding, endpointAddr)) { // 执行测试逻辑 }修改测试项目配置文件
打开测试项目的app.config,找到<system.serviceModel>下的<client>节点,直接将<endpoint>的address属性设为目标地址:<system.serviceModel> <client> <endpoint address="http://localhost:8733/Design_Time_Addresses/XXX" binding="basicHttpBinding" bindingConfiguration="XXXBinding" contract="DesignTime2ServiceReference.IXXX" name="XXXEndpoint" /> </client> </system.serviceModel>保存后无论调试还是直接运行,客户端都会使用该地址连接服务。
确保直接运行时传递命令行参数(若需保留原逻辑)
直接运行MS Test时,需通过vstest.console.exe执行并携带参数:vstest.console.exe 你的测试项目.dll /client:WcfTestClient.exe更可靠的方式是将端点地址存入配置项,代替命令行参数:
在app.config中添加:<appSettings> <add key="WcfServiceEndpoint" value="http://localhost:8733/Design_Time_Addresses/XXX" /> </appSettings>测试代码中读取并使用:
var endpointUrl = System.Configuration.ConfigurationManager.AppSettings["WcfServiceEndpoint"]; var binding = new BasicHttpBinding(); using (var client = new DesignTime2ServiceReference.XXXClient(binding, new EndpointAddress(endpointUrl))) { // 测试逻辑 }更新服务引用验证配置
右键VS中的DesignTime2ServiceReference服务引用,选择“更新服务引用”,重新生成配置文件,确保端点地址与目标一致,避免旧配置残留导致的问题。
内容的提问来源于stack exchange,提问作者iakob
相关产品推荐
相关产品推荐

