0

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

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

My question

Does anybody can help me with an example on how to do this ?

why do I get this when I see this being done in so many answers here ?

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

GuidoG
  • 11,359
  • 6
  • 44
  • 79
  • Try to add it as an attribute to httptransport: ``. The other questions are referencing `` (which has a property `MaxReceivedMessageSize`) but you are using a ``. – Steeeve Aug 15 '21 at 10:37
  • @Steeeve This is some progress, the compiler accepts this finally. But, at runtime I get `Error creating a reader for the MTOM message`. Any ideas ? This error I only get when it needs the larger size, all small messages still work as before – GuidoG Aug 16 '21 at 08:51
  • Please put the new exception details in your question. The details should contain some explanation and a hint how to solve it.. – Steeeve Aug 16 '21 at 09:14
  • @Steeeve I just done that, from the innermessage it seems nothing has changed, it is still the same excecption with just another text in the message, but the inner exception is still the same – GuidoG Aug 16 '21 at 09:31
  • Did you put that maxBuffersize in both server and client config? – Steeeve Aug 16 '21 at 09:52
  • @Steeeve I have no acces to the server side, that is managed by another company. I send emails about this problem but no answer until now. Does this have to be the same on both sides ? – GuidoG Aug 16 '21 at 11:30
  • If the server side doesn't accept bigger messages, you can't overcome that restriction on the client side. But I'm surpised for what MTOM is used, if the maximum message size is restricted to 64K. It doesn't make much sense... Are there more bindings perhaps, one for small messages and another for bigger ones? – Steeeve Aug 16 '21 at 11:37
  • @Steeeve I finally got it working, see my own answer. Your comment about why they would use mtom got me thinking, and disabling it finally seems to do the trick – GuidoG Aug 16 '21 at 12:27

2 Answers2

0

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>
Jiayao
  • 510
  • 3
  • 7
  • This does not helps, I am not using HttpBinding but customBinding. I keep getting the same problems with this approach as described in my question – GuidoG Aug 16 '21 at 08:48
0

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.

GuidoG
  • 11,359
  • 6
  • 44
  • 79