How to pass user credentials to web service?

前端 未结 2 467
春和景丽
春和景丽 2020-12-29 11:38

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

The HTTP request is unauthorized

相关标签:
2条回答
  • 2020-12-29 12:13

    Here is the how it is working for me:-

    Config file setting looks like this:-

    <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";
    
    0 讨论(0)
  • 2020-12-29 12:14

    You can try to genereate your service client proxy using the method mentioned here. Once you have an instance of your WCF client proxy, it will have a property ClientCreditials which you can populate as needed. Hope this helps.

    0 讨论(0)
提交回复
热议问题