我有以下 F# 代码来使用类型提供程序访问 Web 服务。调用Web方法时出现缺少用户名的错误。
An unhandled exception of type 'System.InvalidOperationException' occurred in mscorlib.dll
Additional information: The username is not provided. Specify username in ClientCredentials.
如何设置用户名/密码?我尝试使用代码智能来获取属性来设置它们,但我找不到它们。
open System
open System.ServiceModel
open Microsoft.FSharp.Linq
open Microsoft.FSharp.Data.TypeProviders
type service = WsdlService<"https://services.....?wsdl">
[<EntryPoint>]
let main argv =
let client = service.GetBasicHttpBinding_IXxxDataStorage()
let forecast = client.GetSomeList("201401") // Error: username not set
0 // return an integer exit code
最佳答案
我认为这会起作用。在 ClientCredentials
中嗅探一下,找到可以在此处转动的各种旋钮。
client.DataContext.ClientCredentials.UserName.UserName <- "user"
client.DataContext.ClientCredentials.UserName.UserName <- "password"
关于c# - 如何为Web服务类型提供商设置用户名和密码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27368979/