我是F#的新手,特别是我很陌生的输入提供商。我正在开发一个使用WsdlService
type provider从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;
有没有办法实现这一点,或者至少比我到目前为止更优雅的东西?
答案 0 :(得分:2)
您可以使用类型缩写:
type AppReference = myService.ServiceTypes.My.Long.Namespace.Contracts.ApplicationReference
type AreaReference = myService.ServiceTypes.My.Long.Namespace.Contracts.AreaReference
let app = AppReference(Name="MyApplication")
let area = AreaReference(Name = "MyArea", Application = app)