【发布时间】:2014-07-21 17:59:53
【问题描述】:
我只想使用带有用户名和密码的 c# 客户端使用 HTTPS-soap-webservice。 我不想使用 app.config,所以我只是直接在代码中设置了几个属性。
当我尝试访问网络服务方法时,我总是收到以下错误:
HTTP 请求未经客户端身份验证方案“匿名”授权。从服务器收到的身份验证标头是 'Basic realm......
这是我的代码(我尝试了更多想法,但现在这是我的代码):
var b = new WSHttpBinding(SecurityMode.TransportWithMessageCredential);
b.Security.Message.ClientCredentialType = MessageCredentialType.UserName;
b.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
....
var client = new MyClient(b, new Endpoint("https://myurl..."))
client.clientCredentials.UserName.UserName = "myuser";
client.clientCredentials.UserName.Password = "mypassword";
client.myMethodcall();
就像我上面写的那样,我已经找到了许多“解决方案”来解决这个错误,但它们对我不起作用。我用了basicHttpBinding,我用了WSHttpBinding,我设置了binding-timeouts,我用了SecurityMode.TransportWithMessageCredential等。看来客户端根本没有设置authentication-header!
直接在代码中设置所有属性或使用 app.config 应该没有区别,对吧?有人可以帮我解决这个问题吗?
【问题讨论】:
-
当我只使用 app.config 来定义绑定时,它可以正常工作。那么上面的代码有什么问题呢?编辑:我使用的是 EndpointAddress 而不是 Endpoint。
标签: c# web-services soap