I have a collection of related webservices that share some of the types between them, notably the "token" generated by the TokenService.
When using "add reference" in Visual Studio, proxy classes are generated and many classes, such as the Token class, are duplicated for each webservice.
To resolve this I have written the following powershell script to generate .cs files for the webservices which reuse the types.
$svcutil = get-item ((get-item 'Env:\ProgramFiles(x86)').Value + "\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\x64\svcutil.exe")
$csc = "C:\Program Files (x86)\MSBuild\14.0\Bin\csc.exe"
& $svcutil "http://Path/to/WebService/WSTokenService?wsdl" /o:WSTokenService.cs
& $csc /target:library /out:temp.dll WSTokenService.cs
& $svcutil "http://Path/to/WebService/WSAssetService?wsdl" /r:temp.dll /o:WSAssetService.cs
& $csc /target:library /out:temp.dll WSTokenService.cs WSAssetService.cs
& $svcutil "http://Path/to/WebService/WSContactService?wsdl" /r:temp.dll /o:WSContactService.cs
& $csc /target:library /out:temp.dll WSTokenService.cs WSAssetService.cs WSContactService.cs
..
repeat for 8 webservices
This "chains" the webservices together, resusing the shared classes, and seems to work.
Are there any problems with this approach and/or is there a better way to achieve sharing classes between the related webservices?
Edit: please note that these are not webservices developed by us and we do not have access to the code or classes that are used server-side.
using ClassLibrary2Proxy.ServiceReference1;
in your source code. – SeamanshipDataContract
andDataMember
attributes, AND, they are part of yourIService
interfaces, then they will be picked up bysvcutil
and included in the namespace for the corresponding service. – Seamanshipusing
only for the proxies you want... – SeamanshipCompositeType
is the boilerplate class being shared between services 1 and 2 in our example. – Seamanship