Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/283.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# 在VisualStudio2010中尝试添加Web服务时遇到的问题_C#_Vb.net_Visual Studio 2010_Web Services - Fatal编程技术网

C# 在VisualStudio2010中尝试添加Web服务时遇到的问题

C# 在VisualStudio2010中尝试添加Web服务时遇到的问题,c#,vb.net,visual-studio-2010,web-services,C#,Vb.net,Visual Studio 2010,Web Services,我需要使用一个web服务。该Web服务需要用户身份验证。当我尝试添加对web服务的引用时,我得到一个错误 HTTP请求未经客户端身份验证方案授权 “匿名”。从服务器接收的身份验证标头为 “Basic realm=“AXIS””。远程服务器返回错误:(401) 未经授权。如果服务是在当前解决方案中定义的,请重试 生成解决方案并再次添加服务引用 有没有办法摆脱此错误?您需要从代码中提供凭据,还需要从app.config文件中配置客户端凭据类型类型和领域 <security mode="Tran

我需要使用一个web服务。该Web服务需要用户身份验证。当我尝试添加对web服务的引用时,我得到一个错误

HTTP请求未经客户端身份验证方案授权 “匿名”。从服务器接收的身份验证标头为 “Basic realm=“AXIS””。远程服务器返回错误:(401) 未经授权。如果服务是在当前解决方案中定义的,请重试 生成解决方案并再次添加服务引用


有没有办法摆脱此错误?

您需要从代码中提供
凭据
,还需要从
app.config
文件中配置
客户端凭据类型
类型和
领域

<security mode="TransportCredentialOnly">
<transport clientCredentialType="Basic" proxyCredentialType="None"
 realm="AXIS" />
请遵循以下步骤:

步骤1:
app.config
文件中添加以下标记集

<security mode="TransportCredentialOnly">
<transport clientCredentialType="Basic" proxyCredentialType="None"
 realm="AXIS" />
//在源代码中添加以下两行代码:

 client.ClientCredentials.UserName.UserName = "yourusername";
 client.ClientCredentials.UserName.Password = "yourpassword";