c# - 如何为Web服务类型提供商设置用户名和密码?

标签 c# web-services f# type-providers

我有以下 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/

相关文章:

c# - 无法通过 ssl 使用 web 服务

database - 将字段添加到 App Engine 托管的数据库

wpf - F#/WPF 事件绑定(bind)

f# - 我希望Canopy Web测试结果显示在VS 2013测试浏览器中...

c# - 在 UWP 应用程序中使用资源文件的所有文化版本

c# - 无法识别的转义序列 C#6 字符串插值

c# - 远程服务器返回错误 : (401) Unauthorized. wcf httpbinding basic

c# - C# 中的斜杠和转义问题

c# - 为 Web 服务创建 Java stub 的库

c# - F# 看不到 C# 可序列化抽象类的抽象属性