3

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?

Didier A.
  • 4,609
  • 2
  • 43
  • 45

2 Answers2

0

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

Marco Medrano
  • 2,530
  • 1
  • 21
  • 35
-1

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.

jessehouwing
  • 106,458
  • 22
  • 256
  • 341
  • I am currently generating my reference through Visual Studio 2012. It works well, but what I need is a way to generate the same reference through the command line. Is it impossible to do so? Will I need to change all my client consuming code to expect only one type of collection? Is there no way around this? – Didier A. Dec 06 '13 at 19:37
  • How would I go about adding all the assemblies referenced by my project to the command line svcutil tool to use for reusing types if I have more than one assembly? – Didier A. Dec 06 '13 at 19:39
  • for the commandline you must reference the compiled output using the `/reference:assemblya.dll /reference:assemblyb.dll` – jessehouwing Dec 06 '13 at 19:42
  • I'm still slightly confused at to which assemblies those would be. The project I added the service reference to only has System dlls in it's references. However, that project is used by other projects which will use the code generated by the service reference. Am I supposed to add all assembly reference of all projects that uses the service reference? – Didier A. Dec 06 '13 at 19:50
  • Do you have an assembly that contains the datacontracts? If so, reference that, if not, ignore this option. – jessehouwing Dec 06 '13 at 20:13
  • Ok, so I don't think I actually need to reference any assemblies. I tried to generate it in VS without the Reuse assemblies option, and everything works fine. But I still can not generate a working Reference.cs with svcutil. I get "Validation Error: Multiple definition of element '...' causes the content model to become ambiguous". Even though this error, it still generates a Reference.cs, but when I try and build my project I get: "The type or namespace name 'ExtensionDataObject' does not exist in namespace 'System.Runtime.Serialization'" – Didier A. Dec 06 '13 at 20:38