为什么 WCF 服务引用在元数据交换后不保留某些设置?
我在 WCF 服务的 app.config
文件中定义了这样的绑定:
<bindings>
<netTcpBinding>
<binding name="Binding1"
closeTimeout="00:01:00"
openTimeout="00:01:00"
receiveTimeout="00:10:00"
sendTimeout="00:01:00"
transactionFlow="false"
transferMode="Buffered"
transactionProtocol="OleTransactions"
hostNameComparisonMode="StrongWildcard"
listenBacklog="10"
maxBufferPoolSize="524288"
maxBufferSize="524288"
maxConnections="10"
maxReceivedMessageSize="524288">
<readerQuotas maxDepth="32"
maxStringContentLength="8192"
maxArrayLength="16384"
maxBytesPerRead="4096"
maxNameTableCharCount="16384" />
<reliableSession ordered="true"
inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
<message clientCredentialType="Windows" algorithmSuite="Default" />
</security>
</binding>
</netTcpBinding>
</bindings>
请注意,我已将 maxBufferSize
和 maxReceivedMessageSize
设置为 524288 字节。在我的客户端项目中,当我单击“添加服务引用”时,我可以发现并添加我的服务。但它会像这样填写我客户端的 app.config
文件
<bindings>
<netTcpBinding>
<binding name="NetTcpBinding_AgileService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
hostNameComparisonMode="StrongWildcard" listenBacklog="10" maxBufferPoolSize="524288"
maxBufferSize="65536" maxConnections="10" maxReceivedMessageSize="65536">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
<message clientCredentialType="Windows" algorithmSuite="Default" />
</security>
</binding>
</netTcpBinding>
</bindings>
我很好奇为什么 maxBufferSize
和 maxReceivedMessageSize
在我的客户端中恢复为默认值app.config
。这些设置是否分别应用于客户端和服务器?换句话说,客户端和服务器可以各自有自己的消息大小限制吗?
我还需要在客户端上做些什么来确保客户端愿意发送 524288 字节的消息吗? (我只关心客户端->服务器通信)
I'm defining a binding like this in my WCF Service's app.config
file:
<bindings>
<netTcpBinding>
<binding name="Binding1"
closeTimeout="00:01:00"
openTimeout="00:01:00"
receiveTimeout="00:10:00"
sendTimeout="00:01:00"
transactionFlow="false"
transferMode="Buffered"
transactionProtocol="OleTransactions"
hostNameComparisonMode="StrongWildcard"
listenBacklog="10"
maxBufferPoolSize="524288"
maxBufferSize="524288"
maxConnections="10"
maxReceivedMessageSize="524288">
<readerQuotas maxDepth="32"
maxStringContentLength="8192"
maxArrayLength="16384"
maxBytesPerRead="4096"
maxNameTableCharCount="16384" />
<reliableSession ordered="true"
inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
<message clientCredentialType="Windows" algorithmSuite="Default" />
</security>
</binding>
</netTcpBinding>
</bindings>
Note that I have set maxBufferSize
and maxReceivedMessageSize
to be 524288 bytes. In my client project, when I click "Add Service Reference" I am able to discover and add my service. But it fills out my client's app.config
file like this
<bindings>
<netTcpBinding>
<binding name="NetTcpBinding_AgileService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
hostNameComparisonMode="StrongWildcard" listenBacklog="10" maxBufferPoolSize="524288"
maxBufferSize="65536" maxConnections="10" maxReceivedMessageSize="65536">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
<message clientCredentialType="Windows" algorithmSuite="Default" />
</security>
</binding>
</netTcpBinding>
</bindings>
I'm curious why maxBufferSize
and maxReceivedMessageSize
have reverted back to their defaults in my client's app.config
. Do these settings apply separately to the client and server? In other words, can the client and server each have their own message size limits?
Is there anything else that I need to do on the client to make sure that the client will be willing to send messages of 524288 bytes? (I only care about client -> server communication)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,这些设置特定于客户端或服务器(取决于您正在处理的配置)。
MaxReceivedMessageSize
仅适用于服务或客户端接收的消息的大小,而不适用于发送的消息的大小。您可能还需要增加 ReaderQuotas 中的 MaxStringContentLength 来处理更大的消息。此外,您还需要确保在服务的配置文件中引用服务端点中的 Binding1 配置(通过
bindingConfiguration
属性),否则您的服务将恢复为 NetTcpBinding 的默认设置。例子:
Yes, the settings are specific to the client or the server (depending on which config you're dealing with).
MaxReceivedMessageSize
applies only to the size of the message being received by the service or the client, not the size of the message being sent.You may neeed to increase
MaxStringContentLength
in theReaderQuotas
as well to handle a larger message. Also, you'll need to make sure you reference your Binding1 configuration in your endpoint on your service (via thebindingConfiguration
attribute) in your service's config file, otherwise your service will revert to the default settings for NetTcpBinding.Example:
请注意 MaxReceivedMessageSize 的名称。它与数据接收者准备接受的数据大小有关。因此,客户端和服务很可能需要不同的值 - 因此这些不是从元数据生成的值的一部分
Notice the name of MaxReceivedMessageSize. Its about the size of the data the receiver of the data is prepared to accept. It is, therefore, likely that the client and service will want different values - so these are not part of the generated values from the metadata