Web 服务和 Nunit 测试
我创建了一个调用 Web 服务上的方法的控制台应用程序。 我已经访问了 Web 服务并从控制台应用程序获取了我期望的响应。 当我创建一个单独的测试程序集并创建一些以相同方式调用相同方法的 nunit 测试时,我收到以下异常:-
System.InvalidOperationException:无法找到在 ServiceModel 客户端中引用合同“xxxxx.xxx”的默认端点元素配置部分。 这可能是因为找不到应用程序的配置文件,或者因为在客户端元素中找不到与此协定匹配的端点元素。
以前有人经历过这个吗?
I have created a console application that calls a method on a webservice.
I have accessed the webservice and get the response back from the console application that I expect.
When I create a separate test assembly and create some nunit tests which call the same method in the same way i get the following exception:-
System.InvalidOperationException: Could not find default endpoint element that references contract 'xxxxx.xxx' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.
Anyone experienced this before?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,请确保将 app.config 文件添加到单元测试项目中,并将控制台应用程序的配置文件中的相同设置添加到其中。
祝你好运!
Yes, make sure you add an app.config file to the unit test project and add the same settings you have in the console application's config file to it.
Good luck!
我遇到了同样的问题,但是当直接在 NUnit 中打开测试项目 .NET dll 时,测试会成功,但如果我随后将测试保存为 NUnit 中的项目,则会返回上述错误!
对我来说,解决方法是将测试保存为 NUnit 项目,然后从菜单“Project=>Edit...”中选择,在底部选择“General”选项卡,然后在“Configuration File Name:”字段中输入“\Debug”文件夹中生成的“app.Config”文件的全名,即 [dllname].config。
I had the same issue, however when opening the test project .NET dll directly in NUnit, the test(s) would succeed, but if I then saved the test as a project in NUnit, it would then go back to the above error!
The fix for me was to save the test as an NUnit project, then select from the menu 'Project=>Edit...' and at the bottom select the 'General' tab and in the field 'Configuration File Name:' enter the full name of the GENERATED 'app.Config' file in the '\Debug' folder so [dllname].config.