The type provider 'Microsoft.FSharp.Data.TypeProviders.DesignTime.DataProviders' reported an error: Error reading schema. The remote server returned an error: (401) Unauthorized.
Is there a way to use the OData type provider with an OData service which requires a username and password?
Static type parameters for the type provider:
Yes, but unfortunately it's not quite as slick, and you don't get compile-time validation, which is one of the nice benefits of type providers.
You need to grab the $metadata
from your service and save it locally as a .csdl
file, then use the LocalSchemaFile
static parameter in your code. You can then set credentials on the data context object in order to authenticate at runtime.
// download http://services.odata.org/Northwind/Northwind.svc/$metadata to local file Metadata.csdl
type Northwind = ODataService<"http://services.odata.org/Northwind/Northwind.svc/",
LocalSchemaFile="Metadata.csdl",
ForceUpdate=false>
let db = Northwind.GetDataContext()
db.Credentials <- System.Net.CredentialCache.DefaultCredentials // or whatever creds you need
// go party