This little handy-dandy utility will nearly become your best friend. In fact, it should be one of your favorite utilities in your WCF Utility Belt. This tool does two things:
- Creates service model code from your metadata documents
- Creates metadata documents from your service code
The tool is in the “\Program Files\Microsoft SDKs\Windows\{VERSION}\Bin” directory and is a command line tool, meaning you’ll need to open a command window and execute the executable followed by several parameters. This section lists the parameters and the available options that can be used with the SvcUtil utility. You can find the same information by typing the following at the command line:
Svcutil.exe /?
The general syntax for the utility is as follows:
SvcUtil [options] [metadatapath* | assemblypath* | metadataUrl*]
The following list explains the parameters that can be used with the SvcUtil utility:
- metadatadocumentpath – Path to the metadata document that contains the contract information to import into .wsdl, .xsd, .wspolicy, or .wsmex code.
- assemblyinfopath – Path to the assembly file that contains the service contracts that will be exported to metadata.
- url – URL to a service endpoint that contains metadata available for download via the WSMetadata Exchange or HTTP-Get.
The following tables list and explain the options available to the SvcUtil utility, broken out by option type.
Common Usages
Parameter | Short Form | Description |
---|---|---|
/directory:<directory> | /d:<directory> | Directory in which to create the files. If a directory is not specified, the current directory is used as the default. |
/target:<output type> | /t: | Specifies the output to be generated by this tool. Available values are code, metadata, and XmlSerializer. |
/config:<file1>[, <file2>] | Instructs the SvcUtil utility to generate a configuration file. If a single name is provided, that is the name of the configuration file. If two filenames are supplied, the first file is an input configuration file whose contents are combined with the generated configuration file and written into the second file. | |
/noConfig | Does not generate a configuration file. |
Code Generation
Parameter | Short Form | Description |
---|---|---|
/out:<file> | /o:<file> | Filename for the generated code. If a filename is not specified, the name of the file is taken from the WSDL filename, service name, or the target-Namespace of the schema document. |
/mergeConfig | Merges the generated config file into an existing file instead of overwriting the existing configuration file. | |
/language:<language> | /l:<language> | Specifies the programming language to use when generating code. Must be either a language name or a fully qualified name of a class that implements the System.CodeDom.Compiler.CodeDom Compiler namespace. Language name values include CS, VB, VJS, C#. Default is C#. |
/namespace:<string, string> | /n:<string, string> | Specifies a mapping from WSDK or schema target namespace to CLR namespace. Specifying ‘ * ‘ for the target namespace will map all target-Namespaces without an explicit mapping to that CLR namespace. |
/messageContract | /mc | Generates Message Contract types. |
/enableDataBinding | /edb | Implements the INotifyPropertyChanged interfaces on all Data Contract types to enable data binding. |
/serializer:Auto | /ser:Auto | Automatically selects the serializer that uses the Data Contract serializer. The XmlSerializer is used if the Data Contract serializer fails. |
/serializer:DataContractSerializer | /ser:DataContractSerializer | Generates data types that use the Data Contract serializer for serialization and deserialization. |
/serializer:XmlSerializer | /ser:XmlSerializer | Generates data types that use the XmlSerializer for serialization and deserialization. |
/importXmlTypes | Configures the Data Contract serializer to import non-Data Contract types as IXmlSerializable types. |
Metadata Export
Parameter | Short Form | Description |
---|---|---|
/serviceName:<serviceConfig | Specifies the configuration name of a service to be exported. An executable and an associated configuration file must be passed as input if this option is used. | |
/reference:<file path> | /r | Adds the specified assembly to the set of assemblies used for resolving type references. This option helps locate extension assemblies that are not in the GAC, especially if you are using a service that uses third-party extensions. |
/dataContractOnly | /dconly | Instructs the SvcUtil utility to operate on Data Contract types only. Service Contracts will not be processed. |
Serialization / Message
/edb
Parameter | Short Form | Description |
---|---|---|
/typedMessage | /tm | Generates code that uses Typed Messages. |
/useXmlSerializer | /uxs | Generates code that uses the XmlSerializer. |
/importXmlType | /ixt | Imports non-DataContract types as IXmlSerializable. |
/enableDataBinding | Implements INotifyPropertyChanged interface on all XmlFormatter types to enable data binding. |
Advanced
Parameter | Short Form | Description |
---|---|---|
/async | /a | Generates asynchronous method signatures.The default is to generate synchronous methods. |
/internal | /i | Generates classes marked internal. The default is to only generate public classes. |
/reference:<file path> | /r:<file path> | References the specified assembly. |
/noStdLib | Does not reference the standard library mscorlib.dll. | |
/CollectionType:<type> | /ct:<type> | Fully qualified or assembly qualified name of the type to use as referenced collection type. |
/excludeType:<type> | /et:<type> | Fully qualified or assembly qualified name to exclude from referenced types. |
/serializable | /s | Generates classes marked Serializable. |
Miscellaneous
Parameter | Short Form | Description |
---|---|---|
/svcutilConfig:<configfile> | Custom configuration file to use in place of the application configuration file. This can be used to change the metadata configuration without changing the tool’s configuration file. | |
/validate | /v | Validates services. A configuration file defining a service is loaded when an exe for the configuration file is passed as input to the tool. |
/noLogo | Suppresses the copyright and banner messages. | |
/help | /? | Displays the command syntax and tool options. |
You will notice that several options do not have a short form. This is by design, and when using those options the full parameter needs to be used.