首先,提供用于使用所述 API 进行身份验证的凭据:

Webservice.Authenticate.Credential credential = new Webservice.Authenticate.Credential
{
    Username = "myUserName",
    Password = GetMD5("myPassword"), // See below for a MD5 encoding example method
    ApplicationId = new Guid("00000000-0000-0000-0000-000000000000"), //YOUR ID HERE
    IdentityId = new Guid("00000000-0000-0000-0000-000000000000") //Default is empty guid (no need to edit this)
};

如果我尝试直接使用凭据作为 Icredentials,像这样 _service.Credentials = credential; 会发生以下错误:

无法将类型 auth.credential 隐式转换为 system.net.icredentials。我试图转换它,但它没有正常工作。

后来,我尝试在调用另一个服务时以这种方式使用凭据。但是,我不确定如何传递凭据。
TransactionService.TransactionService _service = new TransactionService.TransactionService();
TransactionService.TransactionSearchParameters _params = new TransactionService.TransactionSearchParameters();
_service.Credentials = new NetworkCredential(credential.Username, credential.Password);

最佳答案

System.Net.ICredentials 是一个集合。

尝试:

_service.Credentials.Add("uri:my.uri"
   , "authenticationType"
   , new NetworkCredential(credential.Username, credential.Password)
);

关于c# - 如何将 System.Net.ICredentials 传递给 API?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30740285/

10-15 22:43