无法弄清楚如何在 WebService 中使用参数 MaxReceivedMessageSize
Can't figure out how to use the parameter MaxReceivedMessageSize in WebService
我需要向网络服务添加参数,但它不允许。
这是我的 App.Config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
<system.serviceModel>
<bindings>
<customBinding>
<binding name="tripAndTimeReportingServiceSoapBinding">
<mtomMessageEncoding messageVersion="Soap12" />
<httpsTransport />
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="https://soap.webfleet.com/v1.53/tripAndTimeReportingService"
binding="customBinding" bindingConfiguration="tripAndTimeReportingServiceSoapBinding"
contract="TripAndTimeReportingService.tripAndTimeReporting"
name="tripAndTimeReportingPort" />
</client>
</system.serviceModel>
</configuration>
发送消息时可以正常工作,但有时会出现此错误
The maximum message size quota for incoming messages (65536) has been
exceeded. To increase the quota, use the MaxReceivedMessageSize
property on the appropriate binding element.
所以我尝试按照错误告诉我的去做,但是 c# 说不。
到目前为止我尝试了什么
这会产生设计时错误“无效的子元素”
<binding name="tripAndTimeReportingServiceSoapBinding">
<mtomMessageEncoding messageVersion="Soap12" />
<httpsTransport />
<maxReceivedMessageSize maxReceivedMessageSize="20000000" />
</binding>
这会产生设计时错误“缺少必需的空格”
<binding name="tripAndTimeReportingServiceSoapBinding">
<mtomMessageEncoding messageVersion="Soap12" />
<httpsTransport />
<maxReceivedMessageSize="20000000" />
</binding>
这会产生运行时错误“无法识别的属性”,当我尝试使用大写 (MaxReceivedMessageSize) 时也是如此
<endpoint address="https://soap.webfleet.com/v1.53/tripAndTimeReportingService"
binding="customBinding" bindingConfiguration="tripAndTimeReportingServiceSoapBinding"
contract="TripAndTimeReportingService.tripAndTimeReporting"
maxReceivedMessageSize="20000000"
name="tripAndTimeReportingPort" />
我读过的其他链接
Figuring out the required MaxReceivedMessageSize in WCF with NetTcpBinding
WCF - How to Increase Message Size Quota
The max message size quota for incoming messages (65536) ....To increase the quota, use the MaxReceivedMessageSize property
我的问题
有没有人能帮我举例说明如何做到这一点?
当我看到这里的很多答案都这样做时,为什么我会得到这个?
编辑
我按照@steeeeeve
的建议改变了我的绑定
<binding name="tripAndTimeReportingServiceSoapBinding">
<mtomMessageEncoding messageVersion="Soap12" />
<httpsTransport maxBufferSize="20000000" maxReceivedMessageSize="20000000" />
</binding>
有了这个 VS 最终接受了这个,但是在运行时我仍然会收到一些消息的这个错误。所以实际上似乎没有任何改变。
执行:
ex {"Error creating a reader for the MTOM message"} System.Exception
{System.ServiceModel.CommunicationException}
内部异常:
InnerException {"The maximum buffer size (65536) has been exceeded
while reading MTOM data. This quota may be increased by changing the
maxBufferSize setting used when creating the MTOM
reader."} System.Exception {System.Xml.XmlException}
堆栈跟踪:
StackTrace " at
System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage
reqMsg, IMessage retMsg)\r\n at
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&
msgData, Int32 type)\r\n at
gttWebfleet.TripAndTimeReportingService.tripAndTimeReporting.showTracks(showTracks
request)\r\n at
gttWebfleet.TripAndTimeReportingService.tripAndTimeReportingClient.gttWebfleet.TripAndTimeReportingService.tripAndTimeReporting.showTracks(showTracks
request) in C:\Development\Palm\gttWebFleet\gttWebfleet\Connected
Services\TripAndTimeReportingService\Reference.cs:line 20349\r\n
at
gttWebfleet.TripAndTimeReportingService.tripAndTimeReportingClient.showTracks(AuthenticationParameters
aParm, GeneralParameters gParm, ShowTracksParameter showTracksParam)
in C:\Development\Palm\gttWebFleet\gttWebfleet\Connected
Services\TripAndTimeReportingService\Reference.cs:line 20357\r\n
at
gttWebfleet.WebFleetAPI.apiTripAndTimeReportingService.ShowTracks(DateTime
startDay, DateTime endDay, String truckNumber, List`1& results) in
C:\Development\Palm\gttWebFleet\gttWebfleet\WebFleetAPI\apiTripAndTimeReportingService.cs:line
204" string
您应该在您的绑定上添加该参数,并且需要在服务器端和客户端都添加它。这里的例子:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding maxBufferSize="64000000" maxReceivedMessageSize="64000000" />
</basicHttpBinding>
</bindings>
</system.serviceModel>
在@Steeeve 的一些提示和大量尝试和错误之后,我发现了一些有用的东西。
诀窍确实是增加绑定的大小,就像这样
<customBinding>
<binding name="tripAndTimeReportingServiceSoapBinding">
<mtomMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16" messageVersion="Soap12" writeEncoding="utf-8">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</mtomMessageEncoding>
<httpsTransport maxBufferSize="64000000" maxReceivedMessageSize="64000000" />
</binding>
还要为端点禁用 mtom。
<endpoint address="https://soap.webfleet.com/v1.53/tripAndTimeReportingService/disable-mtom"
binding="customBinding" bindingConfiguration="tripAndTimeReportingServiceSoapBinding"
contract="TripAndTimeReportingService.tripAndTimeReporting"
name="tripAndTimeReportingPort" />
出于某种原因,他们使用 mtom
作为默认传输,我不知道这是否是一个稳定的配置,但现在它似乎终于可以工作了。
我仍然愿意接受更好的建议。
我需要向网络服务添加参数,但它不允许。
这是我的 App.Config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
<system.serviceModel>
<bindings>
<customBinding>
<binding name="tripAndTimeReportingServiceSoapBinding">
<mtomMessageEncoding messageVersion="Soap12" />
<httpsTransport />
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="https://soap.webfleet.com/v1.53/tripAndTimeReportingService"
binding="customBinding" bindingConfiguration="tripAndTimeReportingServiceSoapBinding"
contract="TripAndTimeReportingService.tripAndTimeReporting"
name="tripAndTimeReportingPort" />
</client>
</system.serviceModel>
</configuration>
发送消息时可以正常工作,但有时会出现此错误
The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element.
所以我尝试按照错误告诉我的去做,但是 c# 说不。
到目前为止我尝试了什么
这会产生设计时错误“无效的子元素”
<binding name="tripAndTimeReportingServiceSoapBinding">
<mtomMessageEncoding messageVersion="Soap12" />
<httpsTransport />
<maxReceivedMessageSize maxReceivedMessageSize="20000000" />
</binding>
这会产生设计时错误“缺少必需的空格”
<binding name="tripAndTimeReportingServiceSoapBinding">
<mtomMessageEncoding messageVersion="Soap12" />
<httpsTransport />
<maxReceivedMessageSize="20000000" />
</binding>
这会产生运行时错误“无法识别的属性”,当我尝试使用大写 (MaxReceivedMessageSize) 时也是如此
<endpoint address="https://soap.webfleet.com/v1.53/tripAndTimeReportingService"
binding="customBinding" bindingConfiguration="tripAndTimeReportingServiceSoapBinding"
contract="TripAndTimeReportingService.tripAndTimeReporting"
maxReceivedMessageSize="20000000"
name="tripAndTimeReportingPort" />
我读过的其他链接
Figuring out the required MaxReceivedMessageSize in WCF with NetTcpBinding
WCF - How to Increase Message Size Quota
The max message size quota for incoming messages (65536) ....To increase the quota, use the MaxReceivedMessageSize property
我的问题
有没有人能帮我举例说明如何做到这一点?
当我看到这里的很多答案都这样做时,为什么我会得到这个?
编辑
我按照@steeeeeve
的建议改变了我的绑定<binding name="tripAndTimeReportingServiceSoapBinding">
<mtomMessageEncoding messageVersion="Soap12" />
<httpsTransport maxBufferSize="20000000" maxReceivedMessageSize="20000000" />
</binding>
有了这个 VS 最终接受了这个,但是在运行时我仍然会收到一些消息的这个错误。所以实际上似乎没有任何改变。
执行:
ex {"Error creating a reader for the MTOM message"} System.Exception {System.ServiceModel.CommunicationException}
内部异常:
InnerException {"The maximum buffer size (65536) has been exceeded while reading MTOM data. This quota may be increased by changing the maxBufferSize setting used when creating the MTOM reader."} System.Exception {System.Xml.XmlException}
堆栈跟踪:
StackTrace " at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)\r\n at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)\r\n at gttWebfleet.TripAndTimeReportingService.tripAndTimeReporting.showTracks(showTracks request)\r\n at gttWebfleet.TripAndTimeReportingService.tripAndTimeReportingClient.gttWebfleet.TripAndTimeReportingService.tripAndTimeReporting.showTracks(showTracks request) in C:\Development\Palm\gttWebFleet\gttWebfleet\Connected Services\TripAndTimeReportingService\Reference.cs:line 20349\r\n
at gttWebfleet.TripAndTimeReportingService.tripAndTimeReportingClient.showTracks(AuthenticationParameters aParm, GeneralParameters gParm, ShowTracksParameter showTracksParam) in C:\Development\Palm\gttWebFleet\gttWebfleet\Connected Services\TripAndTimeReportingService\Reference.cs:line 20357\r\n
at gttWebfleet.WebFleetAPI.apiTripAndTimeReportingService.ShowTracks(DateTime startDay, DateTime endDay, String truckNumber, List`1& results) in C:\Development\Palm\gttWebFleet\gttWebfleet\WebFleetAPI\apiTripAndTimeReportingService.cs:line 204" string
您应该在您的绑定上添加该参数,并且需要在服务器端和客户端都添加它。这里的例子:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding maxBufferSize="64000000" maxReceivedMessageSize="64000000" />
</basicHttpBinding>
</bindings>
</system.serviceModel>
在@Steeeve 的一些提示和大量尝试和错误之后,我发现了一些有用的东西。
诀窍确实是增加绑定的大小,就像这样
<customBinding>
<binding name="tripAndTimeReportingServiceSoapBinding">
<mtomMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16" messageVersion="Soap12" writeEncoding="utf-8">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</mtomMessageEncoding>
<httpsTransport maxBufferSize="64000000" maxReceivedMessageSize="64000000" />
</binding>
还要为端点禁用 mtom。
<endpoint address="https://soap.webfleet.com/v1.53/tripAndTimeReportingService/disable-mtom"
binding="customBinding" bindingConfiguration="tripAndTimeReportingServiceSoapBinding"
contract="TripAndTimeReportingService.tripAndTimeReporting"
name="tripAndTimeReportingPort" />
出于某种原因,他们使用 mtom
作为默认传输,我不知道这是否是一个稳定的配置,但现在它似乎终于可以工作了。
我仍然愿意接受更好的建议。