Web服务调用问题
我从 ASP.NET 网站调用 Web 服务(需要证书)。当我在本地主机(调试)上测试它时,它可以工作,但在 IIS 6(Windows Server 2003)上它不起作用并引发异常:
请求失败,状态为 HTTP 403:禁止。
这是代码,我如何调用 Web 服务:
Service service = new Service();
service.ClientCertificates.Add(new X509Certificate("certificate path", "password"));
service.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(ValidationCallBack);
Result res = service.GetResult();
private static bool ValidationCallBack(object sender, X509Certificate cert, X509Chain chain, System.Net.Security.SslPolicyErrors error)
{
return true;
}
此错误的原因是什么以及如何避免此错误?
我尝试过使用 winForms 进行 Web 服务调用,它在服务器上运行良好。所以我认为这是 IIS 问题...
谢谢!
From ASP.NET web site I'm calling web service (which requires certificate). When I testing it on localhost (debugging) it works, but on IIS 6 (windows server 2003) it does not works and throws an exception:
The request failed with HTTP status
403: Forbidden.
Here is the code, how I'm calling web service:
Service service = new Service();
service.ClientCertificates.Add(new X509Certificate("certificate path", "password"));
service.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(ValidationCallBack);
Result res = service.GetResult();
private static bool ValidationCallBack(object sender, X509Certificate cert, X509Chain chain, System.Net.Security.SslPolicyErrors error)
{
return true;
}
What is the reason of this error and how can I avoid this?
I've tried web service call with winForms and it works fine on server. So I think it is IIS problem...
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要解决此问题,您应该查看此链接
To resolve this you should look at this link
您应该在服务器端启用跟踪更好地理解这个问题。您将看到更好的异常消息或可以为您提供线索的内容。
You should enable tracing on the server side for a better understanding os this issue. You will see a better exception message or something that will give you a clue.