visual-studio “添加服务引用”时,Visual Studio 不会生成 app.config 内容
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2159107/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Visual Studio does not generate app.config content when "add service reference"
提问by SAPNET
When I add a web service by using "add service reference" in the console app, the app.config does not generate the configuration. How do I generate this app.config with a specific wsdl? Thanks!
当我在控制台应用程序中使用“添加服务引用”添加 Web 服务时,app.config 不会生成配置。如何使用特定的 wsdl 生成此 app.config?谢谢!
回答by Carl Onager
When adding the service reference try clicking on the 'Advanced...' button and then uncheck the 'Reuse types in referenced assemblies' checkbox.
添加服务引用时,请尝试单击“高级...”按钮,然后取消选中“在引用的程序集中重用类型”复选框。
I found this out when I had created a simple project to test a third party service which all worked fine. Attempting to add the same reference to the main project resulted in the app.config and reference.vb file not being generated correctly.
我在创建一个简单的项目来测试第三方服务时发现了这一点,该项目一切正常。尝试向主项目添加相同的引用导致无法正确生成 app.config 和 reference.vb 文件。
I think this may have been because there were already other web references in the application or referenced applications, however unchecking 'Reuse types' resulted in the files being generated correctly.
我认为这可能是因为应用程序或引用的应用程序中已经存在其他 Web 引用,但是取消选中“重用类型”会导致文件正确生成。
回答by ewall
(Same answer I gave at Visual Studio 2010: adding a service reference to a 2008 generated wsdl)
(我在Visual Studio 2010 中给出的答案相同:将服务引用添加到 2008 年生成的 wsdl)
I have experienced the same issue with Visual Studio 2008. I find I get different results if I'm using the "Add Service Reference..." command, or digging deeper to "Add Service Reference..." | "Advanced..." | "Add Web Reference...".
我在 Visual Studio 2008 中遇到过同样的问题。我发现如果我使用“添加服务引用...”命令或深入研究“添加服务引用...”,我会得到不同的结果 | “高级...” | “添加 Web 引用...”。
However, the tried-and-true method--and the solution that worked for me--is still via the command line:
然而,久经考验的方法——以及对我有用的解决方案——仍然是通过命令行:
svcutil.exe /language:cs /out:GeneratedProxy.cs /config:app.config http://server/path_to/WebServiceBean?WSDL
That should give you a working app.config. Hope that helps!
这应该会给你一个有效的 app.config。希望有帮助!
回答by ATTA
In my case, following actions resolved
就我而言,以下操作已解决
- Commented
<services>tag in web.config file in WCF Project (from<services>to</services> - Recompiled WCF project
- Hosted it at IIS
- At client application delete old reference and add again WCF reference
<services>WCF 项目中 web.config 文件中的注释标记(从<services>到</services>- 重新编译的 WCF 项目
- 托管在 IIS
- 在客户端应用程序中删除旧引用并再次添加 WCF 引用
and it worked :)
它奏效了:)
回答by startika
You can add a Service Reference as usual (no need for advanced). If the config sections do not appear in app.config, you can click "Configure Service Reference...", and uncheck "Reuse types in referenced assemblies". After that it will correctly generate the sections.
您可以像往常一样添加服务引用(无需高级)。如果 app.config 中没有出现配置部分,您可以单击“配置服务引用...”,并取消选中“在引用的程序集中重用类型”。之后,它将正确生成部分。
回答by thepenguinmaster
This will not automatically generate your settings, but to create the web.config settings without the command line, you can right click on your app.config after adding the service reference and click the "Edit WCF Configuration" button to add the elements you need for your web service.
这不会自动生成您的设置,而是要在没有命令行的情况下创建 web.config 设置,您可以在添加服务引用后右键单击您的 app.config,然后单击“编辑 WCF 配置”按钮添加您需要的元素为您的网络服务。

