<p>I have a WPF application in VS 2008 with some web service references. For varying reasons (max message size, authentication methods) I need to manually define a number of settings in the WPF client's app.config for the service bindings.</p>

<p>Unfortunately, this means that when I update the service references in the project we end up with a mess - multiple bindings and endpoints. Visual Studio creates new bindings and endpoints with a numeric suffix (ie "Service1" as a duplicate of "Service"), resulting in an invalid configuration as there may only be a single binding per service reference in a project.</p>

<p>This is easy to duplicate - just create a simple "Hello World" ASP.Net web service and WPF application in a solution, change the maxBufferSize and maxReceivedMessageSize in the app.config binding and then update the service reference.</p>

<p>At the moment we are working around this by simply undoing checkout on the app.config after updating the references but I can't help but think there must be a better way!</p>

<p>Also, the settings we need to manually change are:</p>

<pre><code>&lt;security mode="TransportCredentialOnly"&gt;
    &lt;transport clientCredentialType="Ntlm" /&gt;
&lt;/security&gt;
</code></pre>

<p>and:</p>

<pre><code>&lt;binding maxBufferSize="655360" maxReceivedMessageSize="655360" /&gt;
</code></pre>

<p>We use a service factory class so if these settings are somehow able to be set programmatically that would work, although the properties don't seem to be exposed.</p>

[{'answer_id': 69154, 'author': 'cruizer', 'author_id': 6441, 'author_profile': 'https://Stackoverflow.com/users/6441', 'pm_score': 0, 'selected': False, 'text': '<p>Somehow I prefer using svcutil.exe directly than to use the "Add Service Reference" feature of Visual Studio :P This is what we\'re doing on our WCF projects.</p>\n'}, {'answer_id': 69557, 'author': 'Nathan', 'author_id': 10890, 'author_profile': 'https://Stackoverflow.com/users/10890', 'pm_score': 0, 'selected': False, 'text': '<p>I take your point, svcutil is definetly the more advanced way of adding and updating service references. Its just a fair bit more manual work when "right click, update reference" is so close to just working in a single step.</p>\n\n<p>I guess we could create some batch files or something to just output the reference code. Even then, manually checking out and updating the service code with svcutil will probably be more work than just undoing the check out on the config.</p>\n\n<p>Thanks for the advice in any case.</p>\n'}, {'answer_id': 69654, 'author': 'Wiren', 'author_id': 2538222, 'author_profile': 'https://Stackoverflow.com/users/2538222', 'pm_score': 3, 'selected': True, 'text': '<p>Create a .Bat file which uses svcutil, for proxygeneration, that has the settings that is right for your project. It\'s fairly easy. Clicking on the batfile, to generate new proxyfiles whenever the interface have been changed is easy.</p>\n\n<p>The batch can then later be used in automated builds. Then you only need to set up the app.config (or web.config) once. We generally separate the different configs for different environments, such as dev, test prod.</p>\n\n<p>Example (watch out for linebreaks):</p>\n\n<pre><code>REM generate meta data\ncall "SVCUTIL.EXE" /t:metadata "MyProject.dll" /reference:"MyReference.dll"\n\nREM making sure the file is writable\nattrib -r "MyServiceProxy.cs"\n\nREM create new proxy file\ncall "SVCUTIL.EXE" /t:code *.wsdl *.xsd /serializable /serializer:Auto /collectionType:System.Collections.Generic.List`1  /out:"MyServiceProxy.cs" /namespace:*,MY.Name.Space /reference:"MyReference.dll" \n</code></pre>\n\n<p>:)</p>\n\n<p>//W</p>\n'}, {'answer_id': 73154, 'author': 'Dylan', 'author_id': 4580, 'author_profile': 'https://Stackoverflow.com/users/4580', 'pm_score': 2, 'selected': False, 'text': '<p>Rather than changing the generated endpoint, uou could add a second endpoint and binding definition with the configuration you need, then in your code just put the name of the new endpoint in your service client constructor.</p>\n'}, {'answer_id': 80534, 'author': 'cruizer', 'author_id': 6441, 'author_profile': 'https://Stackoverflow.com/users/6441', 'pm_score': 0, 'selected': False, 'text': '<p>What we do is we check out (from source control) the app.config and *.cs files that are autogenerated by the svcutil.exe utility, then we run a batch file that runs svcutil.exe to retrieve the service metadata. When it\'s done, we recompile the code, make sure it works, then check the updated app.config and *.cs files back in. It\'s a whole lot more reliable than using the oft-buggy "Add Service Reference" with Visual Studio.</p>\n'}]
['https://Stackoverflow.com/questions/69000', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/10890/']