Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何将System.Net.ICredentials传递给API?_C# - Fatal编程技术网

C# 如何将System.Net.ICredentials传递给API?

C# 如何将System.Net.ICredentials传递给API?,c#,C#,首先,为使用所述API进行认证提供凭证: Webservice.Authenticate.Credential credential = new Webservice.Authenticate.Credential { Username = "myUserName", Password = GetMD5("myPassword"), // See below for a MD5 encoding example method ApplicationId = new Gui

首先,为使用所述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)
};
如果我试图直接使用凭据作为ICredential,比如so
\u service.credentials=credential发生以下错误:

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

后来,我尝试在调用另一个服务时以这种方式利用凭据。但是,我不确定如何通过认证

TransactionService.TransactionService _service = new TransactionService.TransactionService();
TransactionService.TransactionSearchParameters _params = new TransactionService.TransactionSearchParameters();
_service.Credentials = new NetworkCredential(credential.Username, credential.Password);
这是一个收藏

尝试:

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