我正在寻找使用 F# WSDL 类型提供程序。要调用我正在使用的 Web 服务,我需要将我的客户端凭据附加到System.ServiceModel.Description.ClientCredentials
.
这是我拥有的 C# 代码:
var serviceClient = new InvestmentServiceV1Client.InvestmentServiceV1Client();
foreach (ClientCredentials behaviour in serviceClient.Endpoint.Behaviors.OfType<ClientCredentials>())
{
(behaviour).UserName.UserName = USERNAME;
(behaviour).UserName.Password = PASSWORD;
break;
}
这是我到目前为止的 F# 代码:
let client = new service.ServiceTypes.InvestmentServiceV1Client()
let xxx = client.Endpoint.Behaviors
|> Seq.choose (fun p ->
match box p with
:? System.ServiceModel.Description.ClientCredentials as x -> Some(x)
_ -> None)
|> (System.ServiceModel.Description.ClientCredentials)p.UserName.UserName = USERNAME
是否有 F# 等价物System.Linq.Enumerable.OfType<T>
或者我应该只使用 raw OfType<T>
?