【问题标题】:How to pass the credentials to consume an asmx service?如何传递凭据以使用 asmx 服务?
【发布时间】:2015-03-07 09:16:43
【问题描述】:

我正在尝试在需要身份验证的控制台应用程序中使用 SAP Web 服务。我将服务引用添加到控制台应用程序。

        ServiceReference1.SAPServiceSoapClient myService = new ServiceReference1.SAPServiceSoapClient();

        System.Net.CredentialCache myCredentials = new System.Net.CredentialCache();

        NetworkCredential netCred = new NetworkCredential("UserName", "Password");

        Uri uriPrefix = new Uri("url");

        myCredentials.Add(uriPrefix, "Basic", netCred);

       //The following line is giving error that ClientCredentials cannot be assigned as it is read only.            

        myService.ClientCredentials = myCredentials;

【问题讨论】:

    标签: asp.net web-services soap asp.net-web-api asmx


    【解决方案1】:

    我们可以使用以下代码:

    AuthenticationToken token=new AuthenticationToken();
    token.UserName="username";
    token.Password="password";
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-03
      相关资源
      最近更新 更多