我正在尝试在需要身份验证的控制台应用程序中使用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;
答案 0 :(得分:0)
我们可以使用以下代码:
AuthenticationToken token=new AuthenticationToken();
token.UserName="username";
token.Password="password";