2

I am trying to generate proxy for a wcf service through command line. As required, I am using *svcutil.exe.

There are bunch of services which I need to create proxies for. A sample command is shown below. Everything goes humming about generation of proxies.

For one of the proxy I need to have Collection type as List instead of Array which is default. However, with explicitly mentioned like below, I am not able to get the collectiontype correct. The resulting proxy still has Array type for collections. There are no errors while execution of these commands. Not sure what's going around.

svcutil.exe  http://localhost/DealService.svc /noLogo               
/out:D:/Proxies/DealServiceReference.cs /n:*,MyApp.WinUI.DealServiceReference 
/ct:System.Collections.Generic.List`1

Does anyone know, why would I be getting default collectiontype despite of explicit mention? Does anyone know how to get it right?

(Subquestion - All the examples I have seen for defining collectiontype as list, the mysterious `1 appears at the end of System.Collections.Generic.List but I could not understand the need of it, neither I could get a valid explanation somewhere. So if someone could throw light on that, it would be great.)

Subhash Dike
  • 1,836
  • 1
  • 22
  • 37
  • I think it's becuase Generics isn't something supported by WSDL. It uses an array as it's the closest thing to a List. Dictionary is something you can't use in WSDL either. – Tomas McGuinness May 03 '11 at 12:59
  • What about this. http://blogs.microsoft.co.il/blogs/tamirs/archive/2009/06/16/generic-list-lt-t-gt-using-svcutil-exe.aspx – Subhash Dike May 03 '11 at 13:01

2 Answers2

0

Caution:-

svcutil.exe will overwrite existing files on a disk if the names supplied as parameters are identical. This can include code files, configuration or metadata files. To avoid this when generating code and configuration files, use the /mergeConfig switch. In addition, the /r and /ct switches for referencing types are for generating data contracts. These switches do not work when using XmlSerializer.

Reference: https://msdn.microsoft.com/en-us/library/aa347733(v=vs.110).aspx

This may be your situation, check the Serializer used...

terence hill
  • 3,354
  • 18
  • 31
nava
  • 1
  • 1
0

You should be getting the List of T type in the DataMember classes with that switch. For troubleshooting, try creating the proxy by adding a Service Reference for that service and configuring the collection settings as shown here. If the service reference is created with the expected List of T then the WSDL is good. If not, it may be that SvcUtil can't allow serializing/deserializing the collections as List of T.

Sixto Saez
  • 12,610
  • 5
  • 43
  • 51
  • Thanks. I already had gone the "Add service reference" route. In fact, I am working on existing project wherein it is working fine with "Add service reference" option. I am trying to do refactoring, thereby getting away from manual adding of service reference (My question here can provide more insights - http://stackoverflow.com/questions/5787727/alternative-to-service-reference) .. Any other thoughts – Subhash Dike May 03 '11 at 15:02
  • Without seeing the complete WSDL docs, its hard to know why the command line generated version might behave differently. The only easy alternative to this is putting the original ServiceContract (and DataMembers) into a separate assembly and "sharing" it as a reference in the client project. That way you can use create ChannelFactory directly from that interface without generating any proxy code (see link below). It does violate the SOA tenents but it is a pragmatic approach. Link: http://blogs.msdn.com/b/juveriak/archive/2008/02/03/using-channels-vs-proxies-in-wcf.aspx – Sixto Saez May 03 '11 at 15:14