c# - WCF Web 服务不返回 WSDL

标签 c# wcf wsdl

使用 wsdl.exe/l:CS/serverInterface,我从 WDSL 文档生成了一个 C# 接口(interface)。我已经在 WCF 类上实现了该接口(interface)。生成的服务在本地运行:

http://localhost:51454/TapasSim.svc

这显示了默认站点。当我将 ?wsdl 附加到 URL 时出现问题:

http://localhost:51454/TapasSim.svc?wsdl

enter image description here

与我预期的不同,此链接没有返回 WDSL 文档!相反,它指向您在没有 ?wsdl 的情况下获得的确切网页。因此,我无法引用 Web 服务。如果我运行 svcutil.exe 它给出了这个错误:

If you were trying to generate a client, this could be because the metadata documents did not contain any valid contracts or services or because all contracts/services were discovered to exist in /reference assemblies. Verify that you passed all the metadata documents to the tool.

但我希望该错误与未回复 ?wsdl 的原因相同。

什么会导致 WCF .svc 服务不生成 WSDL?

最佳答案

事实证明,问题在于混合两种技术。 wdsl.exe 属于早于 WCF 的旧版“Web References”。较新的工具 svcutil.exe 用于生成 WCF“服务引用”接口(interface)。

所以发生的事情是 WCF 寻找 [ServiceContract][OperationContract] 属性。当它找不到任何东西时,它默默地什么都不做。

至少可以说,对这种情况的无声抑制是令人讨厌的。像 No service with [ServiceContract] attribute found 这样的错误真的会有帮助。

请注意,您可以手动添加 [ServiceContract],但这会给您留下一半的“服务引用”和一半的“Web 引用”。结果可能行不通。

关于c# - WCF Web 服务不返回 WSDL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14589336/

相关文章:

ruby - 使用 soap4r 访问 SOAP 服务无法访问返回对象的内容

c# - 为什么我不能将 DynamicResource 与 DataGridColumn.CellStyle 一起使用

c# - 无法使用 C# 使用 Selenium WebDriver 以隐身模式启动 Chrome

c# - 从 AuthenticationHandler 返回自定义对象

.net - WCF 和流式处理请求和响应

wcf - 为什么我的 WCF 服务不响应 web.config 中的 baseAddress 设置?

c# - T4 在项目之间复制枚举

wcf - 将基于 RSA 的加密添加到没有证书的 WCF 服务

java - Apache CXF wsdl2java : make service return original WSDL file

ruby-on-rails - 使用 Rails 3 实现 SOAP 1.2 服务器