Table of contents
Collapse the table of content
Expand the table of content

WsdlService Type Provider (F#)

Den Delimarsky|Last Updated: 8/18/2017
1 Contributor

Provides the types for a WSDL (Web Services Description Language) web service.

Namespace/Module Path: Microsoft.FSharp.Data.TypeProviders

Assembly: FSharp.Data.TypeProviders (in FSharp.Data.TypeProviders.dll)


type WsdlService<ServiceUri : string,
                 ?LocalSchemaFile : string,
                 ?ForceUpdate : bool                 
                 ?MessageContract : bool,                 
                 ?EnableDataBinding : bool,                 
                 ?Serializable : bool,                 
                 ?Async : bool,                 
                 ?CollectionType : string>

Static Type Parameters

Type ParameterDescription
ServiceUri : stringThe URI for the web service.
?LocalSchemaFile : stringA .wsdlschema file to store locally cached service schema.
?ForceUpdate : boolRequires that a direct connection to the service is available at design-time and force the refresh of the local schema file. The default is true. When ForceUpdate is false, the provider reacts to changes in the LocalSchemaFile.
?MessageContract : boolIf true, generates Message Contract types. The default value is false.
?EnableDataBinding : boolIf true, the generated Data Contract types implement the System.ComponentModel.INotifyPropertyChanged interface to enable data binding.
?Serializable : boolIf true, the generated types are serializable. The default is false. If this is set to true, the generated types have the Serializable attribute applied.
?Async : boolIf true, generates both synchronous and asynchronous method signatures. The default value is false.
?CollectionType : stringA fully qualified or assembly-qualified name of the type to use as a collection data type when code is generated from schemas.


For a walkthrough that shows how to use this type provider, see Walkthrough: Accessing a Web Service by Using Type Providers (F#).

About WSDL

WSDL is an XML-based language for describing web services. Web services expose method calls or function calls over a network and, in the case of WSDL, the Internet. WSDL is used by services to provide a description of the function calls available on the service and the associated data types. The WSDL type provider allows you to use data types from any WSDL service immediately in your code, without the usual overhead of creating them for each service.

A WSDL document contains the description for a web service. WSDL documents are in the XML format and contain definitions of the interfaces and operations offered, the messages and data types used, and information about networking endpoints, such as the URIs, ports, and protocols used. A WSDL document has two major sections, the abstract definitions of the interfaces, their types, operations, and messages, and the bindings section.

WSDL interfaces, also known as portTypes, are groupings of operations. Operations are like methods on an interface. Operations, like methods, can have parameters and return values. The operations are described in the WSDL document in an abstract form that is not specific to the protocol used. The bindings section of the WSDL document describes how the interfaces are exposed as web services, through a specific endpoint, or port and protocol. The protocol used with WSDL is typically SOAP (Simple Object Access Protocol) over HTTP. The SOAP protocol provides a way of encoding object-oriented types and methods.

WSDL 2.0 is a significant revision of the WSDL protocol.

For more information see, Understanding WSDL.

About the WSDL Type Provider

The WSDL type provider allows you to program against a web service with a set of auto-generated types. Behind the scenes, the compiler runs svcutil.exe to generate types that you can use to access the web service. They are generated by declaring the type provider in F# code for the service. The following lines of code illustrate this:

type terraService = WsdlService<"">
let terraClient = terraService.GetTerraServiceSoap ()

The service object hides the details of the SOAP protocol and exposes the functionality of the web server to client code. The service object is referred to as a SOAP client because its job is to interact with the server by using the SOAP protocol to call web service operations. It is analogous to the types created by running wsdl.exe and inherits from System.ServiceModel.ClientBase&#96;1. The client objects contain not only the inherited methods from its base class but also the web methods provided by the web service.

The static arguments DataContractOnly, EnableDataBinding, MessageContract, Async, CollectionType, and DataContractSerializer affect the command-line arguments with similar names given to svcutil.exe. For more information on the effect of these arguments, see ServiceModel Metadata Utility Tool (Svcutil.exe). Types required for the service are generated under the WsdlService type under ServiceTypes.

You must add a reference to the assembly System.ServiceModel to use the WsdlService type provider. You might also need System.Runtime.Serialization.

The types that are used for the web methods are included in a series of nested types under ServiceTypes.


The following example shows how to use the WsdlService type provider to call a method on a web service, in this case, the TerraServer site published by Microsoft Research.

open System
open System.ServiceModel
open Microsoft.FSharp.Linq
open Microsoft.FSharp.Data.TypeProviders
type terraService = Microsoft.FSharp.Data.TypeProviders.WsdlService<"">
let terraClient = terraService.GetTerraServiceSoap ()
let myPlace = new = "Redmond", State = "Washington", Country = "United States")
let myLocation = terraClient.ConvertPlaceToLonLatPt(myPlace)
printfn "Redmond Latitude: %f Longitude: %f" (myLocation.Lat) (myLocation.Lon)
| :? ServerTooBusyException as exn ->
let innerMessage =
match (exn.InnerException) with
| null -> ""
| innerExn -> innerExn.Message
printfn "An exception occurred:\n %s\n %s" exn.Message innerMessage
| exn -> printfn "An exception occurred: %s" exn.Message
Console.WriteLine("Press any key to continue...");
Console.ReadLine() |> ignore


Redmond: Latitude: 47.669998 Longitude: -122.110001Press any key to continue...


Windows 8.1, Windows 8, Windows 7, Windows Server 2012, Windows Server 2008 R2

Version Information

F# Core Library Versions

Supported in: 2.0, 4.0, Portable

See Also

Microsoft.FSharp.Data.TypeProviders Namespace (F#)

Walkthrough: Accessing a Web Service by Using Type Providers (F#)

ServiceModel Metadata Utility Tool (Svcutil.exe)

© 2020 Microsoft