我在 Windows 应用程序中使用 WSDL 使用 Web 服务。当我尝试使用方法时,出现以下错误:-
The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was '"
{"The remote server returned an error: (401) Unauthorized."}
我有用户凭据,但不知道如何在 Windows 应用程序中使用 C# 代码传递它。
最佳答案
这是它对我的工作方式:-
配置文件设置如下所示:-
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="bindingName" >
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Basic" proxyCredentialType="None" realm=""/>
<message clientCredentialType="UserName" algorithmSuite="Default"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://10.10.10.10:1880/testpad/services/Testwebservice"
binding="basicHttpBinding" bindingConfiguration="bindingName"
contract=testService.GetData" name="test_Port1" />
</client>
</system.serviceModel>
</configuration>
我在这里传递用户凭据:-
var ser = new GetDataClient();
ser.ClientCredentials.UserName.UserName = "userid";
ser.ClientCredentials.UserName.Password = "Pa$$word1";
关于c# - 如何将用户凭据传递给 Web 服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17031999/