Click here to Skip to main content
15,886,055 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I feel I've been wrongfully confident that just as you do Update Service Reference for a WCF Service in your client application, the latter picks up the latest values for things like maxStringContentLength from your contract's binding in Web.config and updates its own binding details, so client & service can have agreeable data exchange as per the maximum string size that can be passed.

I have already killed numerous hours trying to comprehend why on earth this doesn't work, i.e. when we do the reference update on the client side it generates the wrong (default) values for all such binding properties. For example, it always creates maxStringContentLength="8192" :(

There are so many posts out there of people trying to make sense out of it, but nothing of good value.

Some suggest use of external configuration, which is no good, because my client needs to add reference and initiate correct binding remotely. Others suggest modification of the client side after adding the reference, which is overly stupid and doesn't work anyway. There are those who say that giving service full name or using unnamed binding configuration helped them, but it's all reading off coffee grounds, and gave me no result.

So how do we configure Web.config on the WCF Service side to make sure its clients can automatically pick up the right binding parameters when adding or updating reference to the service?

Configuration snippet from the service's Web.config:
XML
<services>
    <service name="MyService">
        <host>
            <baseAddresses>
                <add baseAddress="http://localhost:1234/"/>
            </baseAddresses>
        </host>
        <endpoint address="MyService.svc" binding="basicHttpBinding" contract="MyNamespace.IMyService"/>
    </service>
</services>
<bindings>
    <basicHttpBinding>
        <binding sendTimeout="00:50:00" receiveTimeout="00:40:00">
            <readerQuotas maxStringContentLength="100000"/>
        </binding>
    </basicHttpBinding>
</bindings>
Posted
Updated 10-Jul-12 10:36am
v13
Comments
Kenneth Haugland 10-Jul-12 21:35pm    
Hi
I have only used the WCF tool for communicating with an SQL server and sending e-mails to an SMPT server, so Im more curious as to why you would want to change the default settings. Do you have any examples were this is really nessesary?

Im not really sure about the binding properties in the WebConfig file either. I think I set most of the variables in code, but I cant remember exactly if I had set the default values in the config file. If I understand you correctly you cant chenge them after you set them in the WebConfig file or?

Regards

Kenneth
Vitaly Tomilov 11-Jul-12 2:37am    
As shown in the example, I am trying to increase the maximum string size that can be passed from service to the client.

And no, you misunderstood, it is not about just picking up changed binding properties, it is about the client side ignoring them from the beginning, and using the default values no matter what. That's the problem.

And I cannot set them on the client side in any way other than by adding a reference, because the service is remote, and the client has no idea what size of data the service is configured to pass, until the does.
SASS_Shooter 11-Jul-12 14:26pm    
If the client code, and the configuration, is so important to use of your application then have you looked at providing a proxy that programmatically sets your values for your consumers?
Vitaly Tomilov 11-Jul-12 14:33pm    
So, if anonymous client pulls a reference from the service's public URL, what kind of proxy and how can set the client to use the right max-size parameters?
SASS_Shooter 11-Jul-12 14:36pm    
you can use svcutil to generate the proxy code. In the proxy you would then make sure that when the connection is constructed that the parameter size is set correctly. The client would not create a reference but utilize your proxy. The proxy handles the connection to the service.

1 solution

Try this:
getting maxstringcontent to work[^]

In it the answer below states you must have both the binding AND behavior defined.
 
Share this answer
 
Comments
MuhtarQong 11-Jul-12 17:00pm    
I think Vitaly is asking to change (or define) "MaxStringContentLength" property on the "XmlDictionaryReaderQuotas" object in the server-side programmatically.
SASS_Shooter 11-Jul-12 18:03pm    
From my discussions with Vitaly he needs the client to bind to the service and pick up the maxStringContextLength for communication to the WCF service. In his configuration he only has the protocol binding defined and not the behavior which I posted the reply for.
Vitaly Tomilov 12-Jul-12 2:52am    
I had the behavior also, just didn't think it was important to include into the sample that I showed. Anyway, that link offers nothing interesting. Use of an alternative binding doesn't seem like a solution. Besides, I simplified the example, whereas in reality I am using TCP binding.

I'm getting convinced more and more there is simply no solution to my post...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900