如何将用户凭证传递给Web服务? [英] How to pass user credentials to web service?

查看:91
本文介绍了如何将用户凭证传递给Web服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Windows应用程序中使用WSDL使用Web服务.当我尝试使用方法时,出现以下错误:-

I am consuming a webservice using WSDL in windows application. When I try to use method, i get the following error:-

HTTP请求未经客户端身份验证方案授权'匿名的'.从服务器收到的身份验证标头是"

The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was '"

{远程服务器返回错误:(401)未经授权."}

{"The remote server returned an error: (401) Unauthorized."}

我有用户凭据,但不知道如何在Windows应用程序中使用c#代码传递它.

I have user credentials but don't know how to pass it using c# code in windows application.

推荐答案

以下是它对我的工作方式:-

Here is the how it is working for me:-

配置文件设置如下:-

<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>

在这里,我正在传递用户凭据:-

and here i am passing user credentials:-

 var ser = new GetDataClient();
 ser.ClientCredentials.UserName.UserName = "userid";
 ser.ClientCredentials.UserName.Password = "Pa$$word1";

这篇关于如何将用户凭证传递给Web服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆