I am trying to write a simple SOAP client using an F# type provider. The complete program is:
open System
open System.Runtime.Serialization
open System.ServiceModel
open Microsoft.FSharp.Data.TypeProviders
type EntrezService = WsdlService<"http://eutils.ncbi.nlm.nih.gov/soap/v2.0/eutils.wsdl">
[<EntryPoint>]
let main argv =
let client = EntrezService.GeteUtilsServiceSoap()
try
let req = EntrezService.ServiceTypes.eSearchRequest()
let res = client.run_eSearch req
printfn "%A" res
with
| ex ->
let rec inner (ex : Exception) =
if ex.InnerException <> null then
inner ex.InnerException
printfn "%s" ex.Message
inner ex
0
Unfortunately, it looks like the app crashes before it can even make the SOAP call, with the following TypeLoadException:
Could not load type 'UrlTypeLNG' from assembly 'EntrezGeneAdaptor, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null '.
This type is defined in the WSDL. I don't why .NET would try to load it from my assembly.
Stack trace indicates that the exception is thrown from System.Xml.Serialization.XmlReflectionImporter.ImportMembersMapping
.
What's going on here, and is there an easy fix? The equivalent program works fine in C#, so is this a problem with the F# type provider?
It looks like the problem was caused by the WSDL. The service defines a complex type called "UrlType", which contains an attribute called "LNG". Somehow, this was getting combined incorrectly into "UrlTypeLNG". I manually edited the WSDL to use a plain string instead of the complex type, and it seems to be working now.