我有一个基础的ASMX服务,正在尝试运行它(我更愿意使用WCF,但无法使服务器与它一起工作)。它在没有安全设置的情况下可以正常运行,但是一旦打开安全性,我就会收到以下错误信息:“HTTP请求未经授权,客户端身份验证方案为'匿名'。从服务器接收到的身份验证标头为“基本领域=“安全区域”。”我想要的是最简单的解决方案,即“请求用户的名称和密码”。使用Intellisense查看代码并没有找到需要的内容。这里看起来可能会有所帮助,但它似乎是关于WCF的,所以谁知道呢。
我刚意识到我可以将其制作成实时演示:
这是服务:http://smplsite.com/sandbox3/Service1.asmx 用户名为
在添加了安全性之前,在VS项目上运行
我刚意识到我可以将其制作成实时演示:
这是服务:http://smplsite.com/sandbox3/Service1.asmx 用户名为
testapp
,密码为testpw
。我需要一个调用该服务功能的命令行应用程序。在添加了安全性之前,在VS项目上运行
添加Web服务引用
后,此行可以正常工作。new ServiceReference1.Service1SoapClient().HelloMom("Bob");
这是我目前的尝试(这不起作用)
class Program
{
private static bool customValidation(object s, X509Certificate c, X509Chain ch, SslPolicyErrors e)
{ return true }
static void Main(string[] args)
{
// accept anything
ServicePointManager.ServerCertificateValidationCallback +=
new RemoteCertificateValidationCallback(customValidation);
var binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
binding.Security.Transport.Realm = "Secured area";
// the generated Web Service Reference class
var client = new ServiceReference1.Service1SoapClient(
binding,
new EndpointAddress("https://smplsite.com/sandbox3/Service1.asmx")
);
client.ClientCredentials.UserName.UserName = "testapp";
client.ClientCredentials.UserName.Password = "testpw";
Console.WriteLine(client.HelloMom("Bob"));
}
}
编辑:顺便说一下,这不是一个网站或在浏览器中运行,访问代码是一个C#命令行应用程序。此外,身份验证是由另一个我无法控制的IIS插件完成的。
编辑2:明确一点;我正在寻找的解决方案是纯客户端问题。
编辑3:访问控制通过.haccess
类型的系统进行,我很喜欢这种方式。
我不希望服务代码执行任何身份验证。