这practical Haskell example鼓励我安装Visual Studio 2012试用版以使用F#类型的提供程序。但是,我完全不知道如何使用它来解决这个问题。有一个RCSB SOAP web service。我使用RCSB中的WSDL Web服务的URL复制了an example(由于Web服务API已更改,因此无效):
open Microsoft.FSharp.Data.TypeProviders
type pdb = WsdlService<"http://www.rcsb.org/pdb/services/pdbws?wsdl">
do
let ws = pdb.Getpdbws()
ws.getCurrentPdbIds()
|> printfn "%A"
但是这会在运行时因错误而崩溃:
Unhandled Exception: System.InvalidOperationException: RPC Message blastPDBRequest1 in operation blastPDB1 has an invalid body name blastPDB. It must be blastPDB1
at System.ServiceModel.Description.XmlSerializerOperationBehavior.Reflector.OperationReflector.EnsureMessageInfos()
at System.ServiceModel.Description.XmlSerializerOperationBehavior.Reflector.EnsureMessageInfos()
at System.ServiceModel.Description.XmlSerializerOperationBehavior.CreateFormatter()
at System.ServiceModel.Description.XmlSerializerOperationBehavior.System.ServiceModel.Description.IOperationBehavior.ApplyClientBehavior(OperationDescription description, ClientOperation proxy)
at System.ServiceModel.Description.DispatcherBuilder.BindOperations(ContractDescription contract, ClientRuntime proxy, DispatchRuntime dispatch)
at System.ServiceModel.Description.DispatcherBuilder.ApplyClientBehavior(ServiceEndpoint serviceEndpoint, ClientRuntime clientRuntime)
at System.ServiceModel.Description.DispatcherBuilder.BuildProxyBehavior(ServiceEndpoint serviceEndpoint, BindingParameterCollection& parameters)
at System.ServiceModel.Channels.ServiceChannelFactory.BuildChannelFactory(ServiceEndpoint serviceEndpoint, Boolean useActiveAutoClose)
at System.ServiceModel.ChannelFactory.CreateFactory()
at System.ServiceModel.ChannelFactory.OnOpening()
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
at System.ServiceModel.ChannelFactory.EnsureOpened()
at System.ServiceModel.ChannelFactory`1.CreateChannel(EndpointAddress address, Uri via)
at System.ServiceModel.ChannelFactory`1.CreateChannel()
at System.ServiceModel.ClientBase`1.CreateChannel()
at System.ServiceModel.ClientBase`1.CreateChannelInternal()
at System.ServiceModel.ClientBase`1.get_Channel()
at Program.pdb.ServiceTypes.PdbWebServiceClient.getCurrentPdbIds()
at Program.pdb.ServiceTypes.SimpleDataContextTypes.PdbWebServiceClient.getCurrentPdbIds()
at <StartupCode$ConsoleApplication2>.$Program.main@() in c:\users\jon\documents\visual studio 11\Projects\ConsoleApplication2\ConsoleApplication2\Program.fs: line 5
此外,SOAP web service已被弃用,转而使用a RESTful one。我如何使用F#3.0中的那个?最简单的工作示例是什么样的?
答案 0 :(得分:7)
看起来操作BlastPDB
被重载并且TypeProvider使用的底层生成代码没有正确支持它(它没有在主体名称上放置“1”)。直接使用Svcutil时,请参阅此答案以了解同一问题WCF: Svcutil generates invalid client proxy, Apache AXIS Web Service, overload operations - 此页面显示Type Provider uses svcutil internally。
AFAIK您将无法使用类型提供程序访问REST服务,因为REST服务不提供架构(请参阅此答案F# Type Providers and REST apis)。您可能不得不回退REST客户端库(请参阅此处.NET Rest Client Frameworks中的一些选项)或执行原始HTTP。
最简单的工作示例是什么样的?
以下是使用List all current PDB IDs REST API获取当前PDB ID列表的简单示例(我相信这相当于您使用Web服务尝试的调用)。您需要添加对System.Net.Http。
的引用open System.Net.Http
open System.Threading.Tasks
[<EntryPoint>]
let main argv =
use httpClient = new HttpClient()
let task = httpClient.GetStringAsync("http://www.rcsb.org/pdb/rest/getCurrent")
printfn "%s" task.Result
0