Partager via


Using SLsvcUtil.exe to Access a Service

Microsoft Silverlight will reach end of support after October 2021. Learn more.

This topic describes using the Silverlight Service Model Proxy Generation Tool (SLsvcUtil.exe) to generate Silverlight client proxies from service metadata documents.

Client proxies are applications that a client uses to communicate with a service. Some Web services use metadata to describe their functionality in a way that enables the automation of client generation. This metadata describes the operation of the service and the data types it uses in the form of a contract, and hence contains the information needed to build a proxy that can communicate with the service. Client proxies are said to be generated when they are created automatically with a tool that uses machine-readable metadata. Silverlight version 4 can use the Add Service Reference tool in Visual Studio 2010 to generate proxies that can access SOAP and ASP.NET AJAX services. The Silverlight Service Model Proxy Generation Tool (SLsvcUtil.exe) is used to generate a Silverlight client if you prefer working outside Visual Studio.

Common Uses

The following table shows some commonly used options for this tool.

Option Description

/directory:<directory>

Directory to create files in. Default: The current directory. Short form: /d

/help

Displays the command syntax and options for the tool. Short form: /?

/noLogo

Suppresses the copyright and banner message.

/slsvcutilConfig:<configFile>

Specifies a custom configuration file to use instead of the App.config file. This can be used to register System.ServiceModel extensions without altering the tool's configuration file.

Code Generation

SLsvcUtil.exe can generate code for service contracts, clients, and data types from metadata documents. These metadata documents can be on a durable storage medium, or be retrieved online. Online retrieval follows either the WS-Metadata Exchange protocol or the DISCO protocol.

Cc197958.Caution(en-us,VS.95).gifCaution:
SLsvcUtil.exe generates the client based on the WSDL or policy file received from the service. The user principal name (UPN) is generated by concatenating the user name, "@", and a fully qualified domain name (FQDN). However, for users who registered on Active Directory, this format is not valid and the UPN generated by the tool causes a failure in Kerberos authentication with the error message "The logon attempt failed." To resolve this problem, you should manually fix the client file generated by this tool.
SLsvcUtil.exe <metadataDocumentPath>* | <url>* | <epr>

Option Description

epr

The path to an XML file that contains a WS-Addressing EndpointReference for a service endpoint that supports WS-Metadata Exchange.

metadataDocumentPath

The path to a metadata document (.wsdl or .xsd) that contains the contract to import into code (.wsdl, .xsd, .wspolicy, or .wsmex). SLsvcUtil.exe follows imports and includes when you specify a remote URL for metadata. However, if you want to process metadata files on the local file system, you must specify all files in this argument. In this way, you can use SLsvcUtil.exe in a build environment where you cannot have network dependencies. You can use wildcards (for example, *.xsd or *.wsdl) for this argument.

url

The URL to a service endpoint that provides metadata or to a metadata document hosted online.

Option Description

/collectionType:<type>

Specifies a fully qualified name or assembly-qualified name of the type to be used as a collection data type, when code is generated from schemas. Short form: /ct

/config:<configFile>

Specifies the file name for the generated configuration file. Default: output.config

/enableDataBinding

Implements the INotifyPropertyChanged interface on all data contract types to enable data binding. Short form: /edb

/excludeType:<type>

Specifies a fully qualified name or assembly-qualified type name to be excluded from referenced contract types. When using this switch together with /r from separate DLLs, the full name of the XSD class is referenced. Short form: /et

/internal

Generates classes that are marked as internal. Default: generate public classes only. Short form: /i

/language:<language>

Specifies the programming language to use for code generation. You should provide either a language name registered in the Machine.config file, or the fully qualified name of a class that inherits from CodeDomProvider. Values: c#, cs, csharp, vb, visualbasic Default: csharp Short form: /l

/mergeConfig

Merges the generated configuration into an existing file, instead of overwriting the existing file.

/messageContract

Generates messge contract types. Short form: /mc

/namespace:<string,string>

Specifies a mapping from a WSDL or XML Schema targetNamespace to a CLR namespace. Using '*' for the targetNamespace maps all targetNamespaces without an explicit mapping to that CLR namespace. To ensure that the message contract name does not collide with the operation name, you should either qualify the type reference with ::, or make sure the names are unique. 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

/noConfig

Do not generate configuration files.

/noStdLib

Do not reference standard libraries. Default: Mscorlib.dll and System.servicemodel.dll are referenced.

/out:<file>

Specifies the file name for the generated code. Default: Derived from the WSDL definition name, WSDL service name, or target namespace of one of the schemas. Short form: /o

/reference:<file path>

References types in the specified assembly. When generating clients, use this option to specify assemblies that might contain types that represent the metadata being imported. You cannot specify message contracts and XmlSerializer types using this switch. Short form: /r

/serializer:Auto

Automatically selects the serializer. This uses the data contract serializer. If this fails, the XmlSerializer is used. Short form: /ser:Auto

/serializer:DataContractSerializer

Generates data types that use the Data Contract Serializer for serialization and deserialization. Short form: /ser:DataContractSerializer

/serializer:XmlSerializer

Generates data types that use the XmlSerializer for serialization and deserialization. Short form: /ser:XmlSerializer

Examples

The following command generates client code from a running service or online metadata documents.

slsvcutil http://example.com/service.svc?wsdl

The following command generates client code in Visual Basic from local metadata documents.

slsvcutil *.wsdl *.xsd /language:VB

The following command generates client code from a running service using settings that emulate the default Add Service Reference behavior. For a description of the procedure to use the Add Service Reference tool, see How to: Access a Service from Silverlight.

 
slsvcutil http://example.com/service.svc?wsdl /edb /namespace:"*,SilverlightApplication1.ServiceReference1" /ct:System.Collections.ObjectModel.ObservableCollection`1 /r:"c:\Program Files\Microsoft Silverlight\4.0.#####\System.Windows.dll"

See Also