Home > Software design >  Can't figure out how to use the parameter MaxReceivedMessageSize in WebService
Can't figure out how to use the parameter MaxReceivedMessageSize in WebService

Time:09-17

I need to add a parameter to a webservice, but it won't let me.
This is my 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>

It works when I send messages, but sometimes I get this error

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.

So I try to do what the error told me to do, but c# says no.

What I tried so far

this gives designtime error "Invalid child element"

<binding name="tripAndTimeReportingServiceSoapBinding">
    <mtomMessageEncoding messageVersion="Soap12" />
    <httpsTransport />
    <maxReceivedMessageSize maxReceivedMessageSize="20000000" />
</binding>

this gives designtime error "Missing required whitespace"

<binding name="tripAndTimeReportingServiceSoapBinding">
    <mtomMessageEncoding messageVersion="Soap12" />
    <httpsTransport />
    <maxReceivedMessageSize="20000000" />
</binding>

this gives runtime error "Unrecognized attribute", also when I try with Uppercase (MaxReceivedMessageSize)

<endpoint address="https://soap.webfleet.com/v1.53/tripAndTimeReportingService"
    binding="customBinding" bindingConfiguration="tripAndTimeReportingServiceSoapBinding"
    contract="TripAndTimeReportingService.tripAndTimeReporting"
    maxReceivedMessageSize="20000000"
    name="tripAndTimeReportingPort" />

Other links I have read

enter image description here

EDIT

I changed my binding like this as suggested by @steeeeve

<binding name="tripAndTimeReportingServiceSoapBinding">
    <mtomMessageEncoding messageVersion="Soap12" />
    <httpsTransport maxBufferSize="20000000" maxReceivedMessageSize="20000000" />
</binding>

With this VS finaly accepts this, but at runtime I still get this error for some messages. So actually nothing has changed it seems.

execption:

ex {"Error creating a reader for the MTOM message"} System.Exception {System.ServiceModel.CommunicationException}

inner exeption :

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}

Stack trace:

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

CodePudding user response:

You should add the parameter on your binding, and need to add it on both server-side and client-side. Here the example:

<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding maxBufferSize="64000000" maxReceivedMessageSize="64000000" />
        </basicHttpBinding>
    </bindings>
</system.serviceModel>

CodePudding user response:

After some tips from @Steeeve and a lot of try and error, I found something that worked.

The trick is indeed to increase the size in the binding, like this

<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>

but also to disable mtom for the endpoint.

    <endpoint address="https://soap.webfleet.com/v1.53/tripAndTimeReportingService/disable-mtom"
        binding="customBinding" bindingConfiguration="tripAndTimeReportingServiceSoapBinding"
        contract="TripAndTimeReportingService.tripAndTimeReporting"
        name="tripAndTimeReportingPort" />

They use mtom as the default transport for some reason, I don't know if this is a stable configuration but for now it finally seems to be working.

I am still open for better suggestions.

  • Related