绑定配置与绑定名称
WCF 端点元素中的绑定配置和绑定名称元素到底有什么区别?我问的原因是我正在创建一个使用 basicHttpBinding 和 SSL 的端点。我这样配置 web.config:
<basicHttpBinding>
<binding name="basicHttps">
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
</binding>
<endpoint binding="basicHttpBinding" bindingConfiguration="basicHttps" contract="Hsp.Services.Interface.Catalog.ICatalogService" address="" />
但是,当使用 bindingConfiguration 时,https 不起作用。当我将绑定配置更改为绑定名称时,它按预期工作。那么,两者到底有什么区别呢?
What exactly is the difference between bindingConfiguration and bindingName elements in a WCF endpoint element? The reason that I ask is I am creating an endpoint which uses basicHttpBinding and SSL. I configured the web.config like this:
<basicHttpBinding>
<binding name="basicHttps">
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
</binding>
<endpoint binding="basicHttpBinding" bindingConfiguration="basicHttps" contract="Hsp.Services.Interface.Catalog.ICatalogService" address="" />
However, when using bindingConfiguration then https isn't working. When I change bindingConfiguration to bindingName it works as expected. So, what exactly is the difference between the two?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
binding=
属性仅定义您想要的绑定(协议) -basicHttpBinding
、wsHttpBinding
、netTcpBinding
等。这些绑定都有系统默认值 - 如果您不指定任何绑定配置,则将使用这些系统默认值。
您在配置的
部分中定义的是绑定配置 - 将使用的一组用于您选择的绑定的参数而不是系统默认值。因此
binding=
和bindingConfiguration=
需要匹配 - 您不能定义一个绑定(例如basicHttpBinding
),然后为不同的绑定分配绑定配置。然而,这仍然不能解释为什么你的 https 不起作用 - 那一定是其他问题。您能详细说明一下吗?它怎么不起作用?只是没有响应,或者您是否收到错误(如果是这样:该错误是什么??)
The
binding=
attribute just defines, which binding (protocol) you want -basicHttpBinding
,wsHttpBinding
,netTcpBinding
etc.Those bindings all have system default values - if you don't specify any binding configuration, those system defaults will be used.
What you've defined in your
<bindings>
section of your config is a binding configuration - a set of parameters for your binding of choice that will be used instead of the system defaults.So the
binding=
and thebindingConfiguration=
need to match - you cannot define one binding (e.g.basicHttpBinding
) but then assign a binding configuration for a different binding.That however still doesn't explain why your https doesn't work - that must be some other problem. Can you elaborate a bit more? How does it not work? Just no response, or do you get an error (if so: what is that error??)
来自 MSDN 文档
bindingConfiguration
:一个字符串,指定实例化端点时要使用的绑定的绑定名称。绑定名称必须在定义端点时的范围内。默认为空字符串。该属性与绑定结合使用,以引用配置文件中的特定绑定配置。如果您尝试使用自定义绑定,请设置此属性。否则,可能会引发异常。bindingName
:一个字符串,指定通过 WSDL 导出定义的绑定的唯一限定名称。默认为空字符串。我从未使用过
bindingName
,但它似乎只影响为您的端点生成的 WSDL。如果使用bindingConfiguration="basicHttps"
时某些功能不起作用,那么听起来您的配置错误导致其无法正常工作(如果未指定bindingConfiguration
,将应用默认值,这就是将bindingConfiguration
更改为bindingName
时发生的情况)。我认为
无效,可能的值为 Basic、Certificate、Digest、Windows 或 NTLM。请参阅传输安全概述From the MSDN documentation
bindingConfiguration
: A string that specifies the binding name of the binding to use when the endpoint is instantiated. The binding name must be in scope at the point the endpoint is defined. The default is an empty string. This attribute is used in conjunction with binding to reference a specific binding configuration in the configuration file. Set this attribute if you are attempting to use a custom binding. Otherwise, an exception may be thrown.bindingName
: A string that specifies the unique qualified name of the binding for definition export through WSDL. The default is an empty string.I've never used
bindingName
, but it seems to only affect the WSDL generated for your endpoint. If something isn't working when you usebindingConfiguration="basicHttps"
, then it sounds like you have a misconfiguration that's preventing it from working correctly (if nobindingConfiguration
is specified, the defaults will be applied, which is what's happening when you changebindingConfiguration
tobindingName
). I don't think<transport clientCredentialType="None"/>
is valid, the possible values are Basic, Certificate, Digest, Windows, or NTLM. See Transport Security Overview您的服务配置绑定不正确。因此,当您使用 bindingConfiguration 属性正确引用绑定配置时,您的服务将无法正常工作。当您使用 bindingName 属性(在您的情况下这是一个无效的已使用属性)时,该服务只会启动 basicHttpBinding 而不查看您的自定义配置,这似乎工作正常。
有关两个元素之间的差异,请参见: http://msdn.microsoft.com /en-us/library/ms731320.aspx。
因此,使用绑定配置属性是唯一正确的事情。现在我们仍然需要看看您的绑定配置本身有什么问题:-) 请参阅以下示例以从中提取您的相关信息。
请参阅 http://msdn.microsoft.com/en-us/library/bb398990。 aspx 了解更多详细信息。
Your service configuration binding is incorrect. So when you correctly refer to your binding configuration using the bindingConfiguration attribute, your service is not working. When you use the bindingName attribute, which is an invalid used attribute in your case, the service just starts a basicHttpBinding without looking at your custom configuration, which seems to work correctly.
For the different between the two elements look at: http://msdn.microsoft.com/en-us/library/ms731320.aspx.
So, using the bindingConfiguration attribute is the only correct thing. Now we still need to look at what is wrong with you binding configuration itself :-) See the following example to extract your relevant information from.
See http://msdn.microsoft.com/en-us/library/bb398990.aspx for more details.
绑定配置
一个字符串,指定实例化端点时要使用的绑定的绑定名称。绑定名称必须在定义端点时的范围内。默认为空字符串。
该属性与绑定结合使用,以引用配置文件中的特定绑定配置。如果您尝试使用自定义绑定,请设置此属性。否则,可能会引发异常。
绑定名称
一个字符串,指定通过 WSDL 导出定义的绑定的唯一限定名称。默认为空字符串。
bindingConfiguration
A string that specifies the binding name of the binding to use when the endpoint is instantiated. The binding name must be in scope at the point the endpoint is defined. The default is an empty string.
This attribute is used in conjunction with binding to reference a specific binding configuration in the configuration file. Set this attribute if you are attempting to use a custom binding. Otherwise, an exception may be thrown.
bindingName
A string that specifies the unique qualified name of the binding for definition export through WSDL. The default is an empty string.