views:

1283

answers:

7

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.

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.

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.

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!

Also, the settings we need to manually change are:

<security mode="TransportCredentialOnly">
    <transport clientCredentialType="Ntlm" />
</security>

and:

<binding maxBufferSize="655360" maxReceivedMessageSize="655360" />

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.

A: 

Are you using ASP.NET Web Services or WCF?

A: 

ASP.Net web services. We considered WCF but have had some experience with ASP.Net so decided to stick with the older technology for this project.

If WCF can solve some of these problems we would look at converting the project in a later major revision, however at this time the amount of work required would probably be prohibitive.

Nathan
A: 

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.

cruizer
A: 

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.

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.

Thanks for the advice in any case.

Nathan
+2  A: 

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.

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.

Example (watch out for linebreaks):

REM generate meta data
call "SVCUTIL.EXE" /t:metadata "MyProject.dll" /reference:"MyReference.dll"

REM making sure the file is writable
attrib -r "MyServiceProxy.cs"

REM create new proxy file
call "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"

:)

//W

superwiren
Thanks superwren - this looks like it might do the trick.
Nathan
+1  A: 

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.

Dylan
A: 

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.

cruizer