gpt4 book ai didi

c# - 调用 .DLL 的 NUnit 测试调用 WCF Web 服务 (.NET C#)

转载 作者:行者123 更新时间:2023-11-30 19:22:08 26 4
gpt4 key购买 nike

这有点关系到:

InvalidOperationException while creating wcf web service instance

我有一个调用 WCF Web 服务的 .NET C# 类库 (DLL)。似乎任何调用该 .DLL 的 .exe 现在都必须在其 .EXE.config 文件中包含 Web 服务配置。

例如,如果我编写一个 NUnit 测试,那么我是否必须使用 Web 服务参数更新 NUnit.exe.config。这似乎很难管理。我在这里错过了一个重点吗?有捷径吗?如果我有几十个 WCF 服务和几十个 NUnit 测试,我的 NUnit.exe.config 似乎会很可怕。

谢谢,

尼尔·沃尔特斯

最佳答案

不,您没有遗漏任何东西。在 .NET 中,配置默认留给托管应用程序 - 在 ASP.NET 中,Web 运行时及其配置文件 - web.config。

在类库中,托管应用程序使用类库,负责通过它的 app.config(--> 编译后的 YourApp.exe.config)提供配置。

你可以做的是将 WCF 的 web.config 部分外部化到单独的 *.config 文件中,然后再次引用你的 testapp.exe.config 中的那些:

  <system.serviceModel>
<extensions configSource="extensions.config" />
<behaviors configSource="behaviors.config" />
<bindings configSource="bindings.config" />
<client configSource="client.config" />
<services configSource="services.config" />
</system.serviceModel>

不幸的是,您只能外部化配置节,而不能外部化配置节组(并且<system.serviceModel> 是一个配置节组:-(所以您不能全局化它)。

马克

关于c# - 调用 .DLL 的 NUnit 测试调用 WCF Web 服务 (.NET C#),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1711588/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com