.net 如果我设置 HttpGetEnabled = false 会发生什么
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5671885/
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
What happens if I set HttpGetEnabled = false
提问by Anil Purswani
I am confused with Metadata publish concept.
我对元数据发布概念感到困惑。
If in a WCF Service config file I had written :
如果在我写的 WCF 服务配置文件中:
<serviceMetadata httpGetEnabled="false"/>
No matter it is true or false. When I tried to give service reference in a client application using "Add Service Reference..." and clicked on "Discover", I am able to retrieve Service Reference.
不管是真是假。当我尝试使用“添加服务引用...”在客户端应用程序中提供服务引用并单击“发现”时,我能够检索服务引用。
But when removed the following two lines: -
但是当删除以下两行时: -
<endpoint address="mex" binding="mexBasicHttpBinding" contract="IMetadataExchange"/>
<serviceMetadata httpGetEnabled="false"/>
Now after that when I tried to give reference in a client application using "Add Service Reference...." and clicked on "Discover", I am NOTable to retrieve Service Reference....
如今后,当我试图给使用客户端应用程序引用“添加服务引用...”,并点击“查看”,我不能够检索服务参考。
Now can anyone tell me what exactly it means. Why after setting it False it is still allowing to set reference. And why after removing those lines it is not allowing to set reference.
现在谁能告诉我它到底是什么意思。为什么在将其设置为 False 后它仍然允许设置参考。以及为什么在删除这些行后不允许设置参考。
-Anil
-阿尼尔
回答by Cornelius
MEX and WSDL are two different schemes to tell potential clients about the structure of your service. So you can choose to either make your service contracts public as "metadata exchance format" (MEX) or in the "web service description language" (WSDL) -- the latter being accessible via HTTP(s).
MEX 和 WSDL 是两种不同的方案,用于告诉潜在客户您的服务结构。因此,您可以选择将您的服务合同公开为“元数据交换格式”(MEX) 或“ Web 服务描述语言”(WSDL)——后者可通过 HTTP(s) 访问。
Thus in order to generate proxies, you need meta data information. When you remove the serviceMetadata-line you say you are not providing meta data in WSDL format.
因此,为了生成代理,您需要元数据信息。当您删除 serviceMetadata 行时,您说您没有提供 WSDL 格式的元数据。
But the line before, publishing your metadata in MEX, is still active, thus you can generate a proxy from those metadata.
但是之前在 MEX 中发布元数据的那一行仍然处于活动状态,因此您可以从这些元数据生成代理。
From those follows naturally that when you provide neither WSDL nor MEX formatted information, you cannot generate a proxy.
自然而然地,当您既不提供 WSDL 也不提供 MEX 格式的信息时,您将无法生成代理。
As Joel C correctly pointed out, the bindings are a(n almost) orthogonal concept. Whether you allow clients to talk to you via basic HTTP, ws HTTP, net named pipes or crystal balls is quite not dependent on how you publish your services.
正如 Joel C 正确指出的那样,绑定是一个(n 几乎)正交概念。您是否允许客户端通过基本 HTTP、ws HTTP、网络命名管道或水晶球与您交谈,并不完全取决于您发布服务的方式。
The WCF security guidance projectand / or MS "practises and patterns" for WCF securitymight provide deeper insight.
WCF 安全指南项目和/或 MS的WCF 安全“实践和模式”可能会提供更深入的见解。
回答by Joel C
You're adding a service reference, which generates a proxy based on Metadata Exchange (mex). The httpGetEnabled configuration lets you set an http endpoint that would allow a non-mex proxy to be generated using WSDL, such as a legacy .NET webservice proxy. They are different protocols, controlled by different settings. I believe if you were to have <serviceMetadata httpGetEnabled="true" httpGetUrl="http://localhost:8080/SampleService?wsdl"/>you could add a web service reference from .NET 2.0, which you would be unable to do using the configuration <serviceMetadata httpGetEnabled="false"/>.
您正在添加一个服务引用,它基于元数据交换 (mex) 生成一个代理。httpGetEnabled 配置允许您设置一个 http 端点,该端点将允许使用 WSDL 生成非 mex 代理,例如旧版 .NET Web 服务代理。它们是不同的协议,由不同的设置控制。我相信,如果您要<serviceMetadata httpGetEnabled="true" httpGetUrl="http://localhost:8080/SampleService?wsdl"/>添加一个来自 .NET 2.0 的 Web 服务引用,您将无法使用 configuration 来做到这一点<serviceMetadata httpGetEnabled="false"/>。

