How to reuse all assembly types in svcutil and specify a dictionary collection type?

3.3k views Asked by At

I am trying to generate my solution's Service Reference through the command line, so I've been trying to do it with svcutil. I have two problems.

  1. In Visual Studio 2012, I can specify a collection type of System.Array and a dictionary collection type of System.Collections.Generic.Dictionary. In svcutil, there is only an option for collectionType, how can I specify both collection types?

  2. In Visual Studio 2012, I can choose to reuse types in referenced assemblies. I can then pick to Reuse types in all referenced assemblies. Is there a way to instruct svcutil to reuse all types from a solution, or even a way for me to list multiple assemblies from which to re-use types from?

Extra details: My project is a silverlight one. I have many assemblies, and I'm not sure what types are reused and where. Dictionary types are converted to Dictionary, and all other collection type are converted to System.Array.

Here is my current attempt at reproducing my Reference.cs file using the command line instead of Visual Studio 2012:

SvcUtil.exe /target:code "myMexServiceAddress" /language:cs /out:Reference.cs /noConfig /async /collectionType:System.Array /serializable /serializer:Auto /enableDataBinding /namespace:*,myNamespace

EDIT: I am currently successfully generating my service references through Visual Studio 2012, but I need to be able to generate them through command line. This is where I fail to do so.

UPDATE1: So I solved issue 2. You simply need to add /r:assembly.dll /r:assembly2.dll /r:assembly3.dll to the svcutil to have it reuse types in those assemblies. It's a bit annoying to have to manually add the path to all assemblies you want, but there is no way to have it automatically use all types from your project references like in Visual Studio.

UPDATE2: To generate Silverlight 5 service references and Portable Library service reference in code you need to use SLSvcUtil.exe instead of SvcUtil.exe as such:

SLSvcUtil.exe "myMexServiceAddress" /out:Reference.cs /language:cs /enableDataBinding /namespace:*,myNamespace /serializer:Auto /config:ServiceReference.config

I still do not know how you can specify two types of collections, one for Dictionaries and one for other collection types. Any ideas?

2

There are 2 answers

6
jessehouwing On BEST ANSWER

1) The Commandline only supports generating one type of collections, you can however, configure your webservice through the Visual Studio Add Servcie Refenerence Dialog. It's advanced panel supports selecting a CollectionType and a DictionaryType.

2) When you chose this option in Visual Studio it looks at all assemblies already referenced by the project you're adding teh Service Reference to. If you add these references before running the Add Service Reference wizard Visual Studio should pick them up.

If all else fails, you can manually edit the .svcmap file that Visual Studio generates. Here you can add additional Collection Types you want to be (re-)used, these can be custom collection types, you can add addditional reference assemblies as well through this file.

0
Marco Medrano On

Just in case anyone looking for an answer on 2022. The new tool to do it is dotnet-svcutil

To install:

dotnet tool install --global dotnet-svcutil

To use multiple collection use --collectionType multiple times or simpler -ct

dotnet-svcutil "myMexServiceAddress" -ct System.Collections.Generic.List`1 -ct System.Collections.Generic.Dictionary`2

Postdata: If running on Powershell escape the `1 as ``1