使用目的:
- Generate code from running services or static metadata documents.
- Export metadata documents from compiled code.
- Validate compiled service code.
- Download metadata documents from running services.
- Pre-generate serialization code.
使用示例:
svcutil http://service/metadataEndpoint
- Generate client code from a running service or online metadata documents. Before must be add ServiceMetadataBehavior
svcutil /dconly http://service/metadataEndpoint
- Generate Data Contract types from a running service or online metadata documents.
svcutil [path]*.wsdl [path]*.xsd /language:C# [/d:outpath] [/o:fileName]
- Generate client code from local metadata documents.
svcutil /dconly *.xsd /language:VB
- Generate Data Contract types in VisualBasic from local schema documents.
svcutil /t:metadata http://service/metadataEndpoint
- Download metadata documents from running services
svcutil myAssembly.dll
- Generate metadata documents for Service Contracts and associated types in an assembly
svcutil myServiceHost.exe /serviceName:myServiceName
- Generate metadata documents for a service, and all associated Service Contracts and data types in an assembly
svcutil myServiceHost.exe /dconly
- Generate metadata documents for data types in an assembly
svcutil /validate /serviceName:myServiceName myServiceHost.exe
- Verify service hosting
svcutil /t:xmlserializer myContractLibrary.exe
- Generate serialization types for XmlSerializer types used by any Service Contracts in the assembly
详细说明:
Options:
/target:<output type> - The target output for the tool: code, metadata or xmlSerializer.
/directory:<directory> - Directory to create files in (default: current directory) (Short Form: /d)
/svcutilConfig:<configFile> - Custom configuration file to use in place of the app config file. This can be used to register system.serviceModel extensions without altering the tool's config file.
/noLogo - Suppress the copyright and banner message.
/help - Display command syntax and options for the tool. (Short Form: /?)
-= CODE GENERATION =-
Description: svcutil.exe can generate code for service contracts, clients and data types from metadata documents. These metadata documents can be on disk or retrieved online. Online retrieval follows either the WS-Metadata Exchange protocol or the DISCO protocol.
Syntax: svcutil.exe [/t:code] <metadataDocumentPath>* | <url>* | <epr>
<metadataDocumentPath> - The path to a metadata document (wsdl or xsd). Standard command-line wildcards can be used in the file path.
<url> - The URL to a service endpoint that provides metadata or to a metadata document hosted online. For more information on how these documents are retrieved see the Metadata Download section.
<epr> - The path to an XML file that contains a WS-Addressing EndpointReference for a service endpoint that supports WS-Metadata Exchange. For more information see the Metadata Download section.
Options:
/out:<file> - The filename for the generated code. Default: derived from the WSDL definition name, WSDL service name or targetNamespace of one of the schemas. (Short Form: /o)
/config:<configFile> - The filename for the generated config file. Default: output.config
/mergeConfig - Merge the generated config into an existing file instead of overwriting the existing file.
/noConfig - Do not generate config
/dataContractOnly - Generate code for Data Contract types only. Service Contract types will not be generated. (Short Form: /dconly)
/language:<language> - The programming language to use for generating code. Provide either a language name registered in the machine.config file or provide the fully-qualified name of a class that inherits from System.CodeDom.Compiler.CodeDomProvider. Examples of language names to use are CS and VB. Default: C#. (Short Form: /l)
/namespace:<string,string> - A mapping from a WSDL or XML Schema targetNamespace to a CLR namespace. Using the '*' for the targetNamespace maps all targetNamespaces without an explicit mapping to that CLR namespace. Default: derived from the target namespace of the schema document for Data Contracts. The default namespace is used for all other generated types. (Short Form: /n)
/messageContract - Generate Message Contract types. (Short Form: /mc)
/enableDataBinding - Implement the System.ComponentModel.INotifyPropertyChanged interface on all Data Contract types to enable data binding. (Short Form: /edb)
/serializable - Generate classes marked with the Serializable Attribute. (Short Form: /s)
/async - Generate both synchronous and asynchronous method signatures. Default: generate only synchronous method signatures. (Short Form: /a)
/internal - Generate classes that are marked as internal. Default: generate public classes. (Short Form: /i)
/reference:<file path> - Reference types in the specified assembly. When generating clients, use this option to specify assemblies that might contain types representing the metadata being imported. (Short Form: /r)
/collectionType:<type> - A fully-qualified or assembly-qualified name of the type to use as a collection data type when code is generated from schemas. (Short Form: /ct)
/excludeType:<type> - A fully-qualified or assembly-qualified type name to exclude from referenced contract types. (Short Form: /et)
/noStdLib - Do not reference standard libraries. By default mscorlib.dll and system.servicemodel.dll are referenced.
/serializer:Auto - Automatically select the serializer. This tries to use the Data Contract serializer and uses the XmlSerializer if that fails. (Short Form: /ser)
/serializer:DataContractSerializer - Generate data types that use the Data Contract Serializer for serialization and deserialization
/serializer:XmlSerializer - Generate data types that use the XmlSerializer for serialization and deserialization
/importXmlTypes - Configure the Data Contract serializer to import non-Data Contract types as IXmlSerializable types.
-= METADATA EXPORT =-
Description: svcutil.exe can export metadata for services, contracts and data types in compiled assemblies. To export metadata for a service, you must use the /serviceName option to indicate the service you would like to export. To export all Data Contract types within an assembly use the /dataContractOnly option. By default metadata is exported for all Service Contracts in the input assemblies.
Syntax: svcutil.exe [/t:metadata] [/serviceName:<serviceConfigName>] [/dataContractOnly] <assemblyPath>*
<assemblyPath> - The path to an assembly that contains services, contracts or Data Contract types to be exported. Standard command-line wildcards can be used to provide multiple files as input.
Options:
/serviceName:<serviceConfigName> - The config name of a service to export. If this option is used, an executable assembly with an associated config file must be passed as input. Svcutil will search through all associated config files for the service configuration. If the config files contain any extension types, the assemblies containing these types must either be in the GAC or explicitly provided using the /r option.
/reference:<file path> - Add the specified assembly to the set of assemblies used for resolving type references. If you are exporting or validating a service that uses 3rd-party extensions (Behaviors, Bindings and BindingElements) registered in config use this option to locate extension assemblies that are not in the GAC. (Short Form: /r)
/dataContractOnly - Operate on Data Contract types only. Service Contracts will not be processed. (Short Form: /dconly)
/excludeType:<type> - The fully-qualified or assembly-qualified name of a type to exclude from export. This option can be used when exporting metadata for a service or a set of service contracts to exclude types from being exported. This option cannot be used with the /dconly option. (Short Form: /et)
-= SERVICE VALIDATION =-
Description: Validation is useful to detect errors in service implementations without hosting the service. You must use the /serviceName option to indicate the service you would like to validate.
Syntax: svcutil.exe /validate /serviceName:<serviceConfigName> <assemblyPath>*
<assemblyPath> - The path to an assembly containing service types to be validated. The assembly must have an associated config file to provide service configuration. Standard command-line wildcards can be used to provide multiple assemblies.
Options:
/validate - Validate a service implementation. To validate a service, you must use the /serviceName option to indicate the service you would like to validate. If this option is used, an executable assembly with an associated config file must be passed as input. (Short Form: /v)
/serviceName:<serviceConfigName> - The config name of a service to validate. To validate a service this option must be provided. Svcutil will search through the associated config files of all input assemblies for the service configuration. If the associated configuration file contain any extension types, the assemblies containing these types must either be in the GAC or explicitly provided using the /r option.
/reference:<file path> - Add the specified assembly to the set of assemblies used for resolving type references. If you are exporting or validating a service that uses 3rd-party extensions (Behaviors, Bindings and BindingElements) registered in config use this option to locate extension assemblies that are not in the GAC. (Short Form: /r)
/dataContractOnly - Operate on Data Contract types only. Service Contracts will not be processed. (Short Form: /dconly)
/excludeType:<type> - The fully-qualified or assembly-qualified name of a service type to exclude from validation. (Short Form: /et)
-= METADATA DOWNLOAD =-
Description: svcutil.exe can be used to download metadata from running services and save the metadata to local files. To download metadata, you must explicitly specify the /t:metadata option. Otherwise, client code will be generated. For http and https URL schemes svcutil.exe will try to retrieve metadata using WS-Metadata Exchange and DISCO. For all other URL schemes svcutil.exe will only try WS-Metadata Exchange. By default, svcutil.exe uses the bindings defined in the System.ServiceModel.Description.MetadataExchangeBindings class. To configure the binding used for WS-Metadata Exchange you must define a client endpoint in config that uses the IMetadataExchange contract. This can be defined either in svcutil.exe's config file or in another config file specified using the /svcutilConfig option.
Syntax: svcutil.exe /t:metadata <url>* | <epr>
<url> - The URL to a service endpoint that provides metadata or an URL that points to a metadata document hosted online.
<epr> - The path to an XML file that contains a WS-Addressing EndpointReference for a service endpoint that supports WS-Metadata Exchange.
-= XMLSERIALIZER TYPE GENERATION =-
Description: svcutil.exe can pre-generate C# serialization code that is required for types that can be serialized using the XmlSerializer. svcutil.exe will only generate code for types used by Service Contracts found in the input assemblies.
Syntax: svcutil.exe /t:xmlSerializer <assemblyPath>*
<assemblyPath> - The path to an assembly containing Service Contract types. Serialization types will be generated for all Xml Serializable types in each contract
Options:
/reference:<file path> - Add the specified assembly to the set of assemblies used for resolving type references. (Short Form: /r)
/excludeType:<type> - Fully-qualified or assembly-qualified type name to exclude from export or validation. This option can be used when exporting metadata for a service or a set of service contracts to exclude types from being exported. This option cannot be used with the /dataContractOnly option. (Short Form: /et)
/out:<file> - Filename for the generated code. This option will be ignored when multiple assemblies are passed as input to the tool. Default: derived from the assembly name. (Short Form: /o)