我对 F# 很陌生,尤其是对类型提供程序很陌生。我正在开发一个使用WsdlService
类型提供程序从 WCF 服务生成合同的项目。这是我的代码现在的样子:
type myService = WsdlService<"http://services.mydomain.com/myservices.svc?wsdl">
let myClient = myService.GetIMyService_Basic()
到目前为止看起来还不错,除了从绑定名称生成的奇怪名称,IMyService_Basic
. 但是,来自服务的数据契约是在一系列嵌套类中生成的。这意味着,我必须做这样的事情:
let app = new myService.ServiceTypes.My.Long.Namespace.Contracts.ApplicationReference (Name = "MyApplication")
let area = new myService.ServiceTypes.My.Long.Namespace.Contracts.AreaReference (Name = "MyArea", Application = app)
let level = new myService.ServiceTypes.My.Long.Namespace.Contracts.LevelReference (Name = "MyLevel", Area = area)
let node = new myService.ServiceTypes.My.Long.Namespace.Contracts.NodeReference (ExternalKeys = [|"123abc"|], Level = level)
let req = new myService.ServiceTypes.My.Long.Namespace.Contracts.GetChangeSetsByNodeRequest (Node = node)
let res = myClient.GetChangeSets(req).Results
printf "This node has %i total change sets" res.Length;
这是一个相当丑陋的。我宁愿做一些事情,比如使用其中一种生成的类型,就好像它是一个模块或命名空间一样,如下所示:
open myService.ServiceTypes.My.Long.Namespace.Contracts // Doesn't work
let app = new ApplicationReference (Name = "MyApplication")
let area = new AreaReference (Name = "MyArea", Application = app)
let level = new LevelReference (Name = "MyLevel", Area = area)
let node = new NodeReference (ExternalKeys = [|"123abc"|], Level = level)
let req = new GetChangeSetsByNodeRequest (Node = node)
let res = myClient.GetChangeSets(req).Results
printf "This node has %i total change sets" res.Length;
有什么方法可以实现这一点,或者至少比我目前所拥有的更优雅吗?