Поделиться через


Edit .svcmap file to access "hidden" functions of service references

Not all code generation options of service references are exposed through its UI.  To prevent users to be confused by some advanced options, the configuration dialog is designed to only expose options which are most likely to be used.  We can only access other options by editing the .svcmap file.  Unfortunately, the file is hidden by default, so people won't discover it easily, and most people will prevent to edit hidden files as well to prevent corrupting the project by accident.

Well, this .svcmap file is editable, and Xml Intellisense actually works here, so changing it is not that difficult.  Certainly, we are not interested to change those options which can be changed easily through the configuration dialog.  Here are something you can do with editing this file, but otherwise not doable:

1, You can enable sharing service contract types:

   by adding ServiceContractMapping in the ServiceContractMappings section, you will force the code generator to use a shared service contract type defined in a referenced assembly (you cannot share a type defined in the current project.)  The service reference will still generate configuration to the app.config file.

2, you can define complex collection mappings:

  the configuration dialog only support some limited options. Adding CollectionMapping in the file, you get similar function you can get by using svcutil command line.

3, namespace mappings:

  it works like /namespace option in the svcutil command line

4, you can add additional MatadataSources!

  actually, you can reference two services in one service reference, and share the data types. Adding additional MetadataSource to the file by hand is the only way to do that today.  Once you added, it will be maintained, and it will not be lost, when you update the service. (Actually, you don't need add MetadataFiles by hand.  Just add a MetadataSource into the file, save it, and Update the reference, all metadata files will be downloaded automatically.

5, add additional Metadata files

  It is possible to add additional metadata files to a service reference, just copy them to the folder, and add additional MetadataFile node in the .svcmap file to reference them.  They will be used in the code generator.  All MetadataFile without a SourceId will not be automatically updated, so they will stay even when you update the service reference.

6, add private configuration file

 You can add a special extension file with name = "Reference.config" (very similar to configuration.svcinfo).  With the configuration file, you can add additional extensions to the code generator. (Unlike adding them to the machine level configuration, things in the Reference.config only affect the code generator in one reference.  Special security settings to enable downloading metadata files from a secured server is also possible through a such config file.

7, additional extension files

  The additional code generator extensions can locate those extensions file registed in the Extension section. It is possible to set additional options through those files.