[英]How do I set maxReceivedMessageSize on Self Hosted WCF Service?
I have an issue where I am giving my Self Hosted WCF service more data than it can handle. 我遇到了一个问题,我为自己的WCF服务提供的数据量超出了其处理能力。 I have set the maxReceivedMessageSize on my client, but in this case the client is passing the data to the server, so I need to set MaxReceivedMessageSize on the server. 我已经在客户端上设置了maxReceivedMessageSize,但是在这种情况下,客户端会将数据传递给服务器,因此我需要在服务器上设置MaxReceivedMessageSize。 I am not using any config files, and I am not sure how to get it set within my current config... 我没有使用任何配置文件,也不确定如何在当前配置中进行设置...
Client: 客户:
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_Iplutocomm"
receiveTimeout="00:05:00" sendTimeout="00:05:00" maxReceivedMessageSize ="210242880">
<readerQuotas maxStringContentLength="2147483647" maxArrayLength="2147483647"/>
</binding>
</basicHttpBinding>
Self Hosted Service 自助服务
Dim myServiceAddress As New Uri("http://" & LocalIpAddress & ":" & tcp_port & "/" & servicename)
myservicehost = New ServiceHost(GetType(plutocomm), myServiceAddress)
'Enable metadata publishing
Dim smb As New ServiceMetadataBehavior()
smb.HttpGetEnabled = True
smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15
myservicehost.Description.Behaviors.Add(smb)
myservicehost.Open()
New Changes / Update 新变化/更新
Doing it like this, will that override the default basichhtp binding that I assume the framework setup because I did not initially specifically create a binding? 这样做,是否会覆盖默认的basichhtp绑定,因为我最初没有专门创建绑定,所以我假设使用默认的basichhtp绑定?
I short, will the below code, running on my service, allow my current client config to "plug in" to the new binding? 简而言之,下面的代码可以在我的服务上运行,允许我当前的客户端配置“插入”到新的绑定中吗? Will I now still have only one binding a sbefore, but my created one, replacing the default one? 我现在仍将只有一个绑定到sbefore,但是我创建的绑定取代了默认的吗?
Dim myServiceAddress As New Uri("http://" & LocalIpAddress & ":" & tcp_port & "/" & servicename)
myservicehost = New ServiceHost(GetType(plutocomm), myServiceAddress)
'*******NEW CHANGES
Dim BasicBinding As New BasicHttpBinding
BasicBinding.MaxReceivedMessageSize = 2147483647
myservicehost.AddServiceEndpoint(GetType(plutocomm), BasicBinding, myServiceAddress)
'/*******NEW CHANGES
' Enable metadata publishing.
Dim smb As New ServiceMetadataBehavior()
smb.HttpGetEnabled = True
smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15
myservicehost.Description.Behaviors.Add(smb)
myservicehost.Open()
Use ServiceHost.AddServiceEndpoint() , passing in the binding of your choice. 使用ServiceHost.AddServiceEndpoint() ,传入您选择的绑定。
In your case this is the basicHttpBinding with maxReceivedMessageSize set. 在您的情况下,这是设置了maxReceivedMessageSize的basicHttpBinding。
This method has 5 overloads so you can just choose the one you want. 此方法有5个重载,因此您可以选择所需的重载。
Something like this: 像这样:
Dim myBinding As New BasicHttpBinding() With { _
Key .MaxReceivedMessageSize = 210242880 _
}
myservicehost.AddServiceEndpoint(GetType(plutocomm), myBinding, myServiceAddress)
Update: 更新:
Your bindings need to be "Coherent", they don't need to be the same.(if your client config have a 60 seconds timeout, a server with 30 seconds timeout would work but would be incoherent, same goes with message Size) 您的绑定必须是“一致的”,它们不必相同。(如果您的客户端配置有60秒的超时,则服务器可以工作30秒的超时,但不连贯,消息大小也一样)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.