客户端身份验证方案'Basic'禁止HTTP请求.远程服务器返回错误:(403)禁止. [英] The HTTP request was forbidden with client authentication scheme 'Basic'.he remote server returned an error: (403) Forbidden.
问题描述
我按照下面的链接创建了一个自签名证书,并为其配置了IIS.我正在使用具有基本身份验证的Trasport安全性.
I followed below links to create a selfsigned cert and configure IIS for the same. I am using Trasport security with Basic authetication.
但是当我调用该服务时,却遇到了异常情况.
But I get below exception when I make a call to the service.
https://www.jayway.com/2014/09/03/creating-self-signed-certificates-with-makecert-exe-for-development/
https://www.jayway.com/2014/09/03/creating-self-signed-certificates-with-makecert-exe-for-development/
https://www.jayway.com/2014/10/27/configure-iis-to-use-your-self-signed-certificates-with-your-application/
https://www.jayway.com/2014/10/27/configure-iis-to-use-your-self-signed-certificates-with-your-application/
在System.Threading.ThreadHelper.ThreadStart()</StackTrace>< ExceptionString> System.ServiceModel.Security.MessageSecurityException中:客户端身份验证方案"Basic"禁止HTTP请求. ---& gt; System.Net.WebException: 远程服务器返回错误:(403)禁止.
at System.Threading.ThreadHelper.ThreadStart()</StackTrace><ExceptionString>System.ServiceModel.Security.MessageSecurityException: The HTTP request was forbidden with client authentication scheme 'Basic'. ---&gt; System.Net.WebException: The remote server returned an error: (403) Forbidden.
我的客户代码如下:
WSHttpBinding绑定=新的WSHttpBinding();
binding.Name ="Main";
binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
binding.Security.Mode = SecurityMode.Transport;
binding.ReliableSession.Enabled = false;
binding.TransactionFlow = false;
WSHttpBinding binding = new WSHttpBinding();
binding.Name = "Main";
binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
binding.Security.Mode = SecurityMode.Transport;
binding.ReliableSession.Enabled = false;
binding.TransactionFlow = false;
OMCFApp.OMCFServiceReference.ConnectorFrameworkClient代理=新的OMCFServiceReference.ConnectorFrameworkClient(); //OmcfServiceReference.ConnectorFrameworkClient();
proxy.ClientCredentials.UserName.UserName = @"Axyz";
proxy.ClientCredentials.UserName.Password ="ssd234";
OMCFApp.OMCFServiceReference.ConnectorFrameworkClient proxy = new OMCFServiceReference.ConnectorFrameworkClient(); //OmcfServiceReference.ConnectorFrameworkClient();
proxy.ClientCredentials.UserName.UserName = @"Axyz";
proxy.ClientCredentials.UserName.Password = "ssd234";
此对Web服务方法的调用失败.
After this call to the web service method fails.
我对此表示感谢.已经尝试了许多解决问题的方法.但没有运气.
I appreciate any help on this. Have been tried many many ways to resolve the issue. But no luck.
推荐答案
KadamSwati,
Hi KadamSwati,
客户端的配置文件中有什么设置?根据您的代码,您没有在"OMCFApp.OMCFServiceReference.ConnectorFrameworkClient"中使用绑定和地址,也没有通过"HttpClientCredentialType.Basic"设置Transport.ClientCredentialType.
Do you have any settings in configuration file of client? Based on your code, you did not use binding and address in "OMCFApp.OMCFServiceReference.ConnectorFrameworkClient", and you did not set Transport.ClientCredentialType by "HttpClientCredentialType.Basic".
这是使用基本身份验证在Trasport安全中为客户端提供的简单代码.
Here is a simple code for client in Trasport security with Basic authentication.
// Create the binding.
WSHttpBinding myBinding = new WSHttpBinding();
myBinding.Security.Mode = SecurityMode.Transport;
myBinding.Security.Transport.ClientCredentialType =
HttpClientCredentialType.Basic;
// Create the endpoint address. Note that the machine name
// must match the subject or DNS field of the X.509 certificate
// used to authenticate the service.
EndpointAddress ea = new
EndpointAddress("https://machineName/Calculator");
// Create the client. The code for the calculator
// client is not shown here. See the sample applications
// for examples of the calculator code.
CalculatorClient cc =
new CalculatorClient(myBinding, ea);
// The client must provide a user name and password. The code
// to return the user name and password is not shown here. Use
// a database to store the user name and passwords, or use the
// ASP.NET Membership provider database.
cc.ClientCredentials.UserName.UserName = ReturnUsername();
cc.ClientCredentials.UserName.Password = ReturnPassword();
try
{
// Begin using the client.
cc.Open();
Console.WriteLine(cc.Add(100, 11));
Console.ReadLine();
// Close the client.
cc.Close();
}
您可以参考下面的链接以获取更多信息.
You could refer the link below for more information.
#具有基本身份验证的传输安全性
https://msdn.microsoft.com /en-us/library/ms733775%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396
# Transport Security with Basic Authentication
https://msdn.microsoft.com/en-us/library/ms733775%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396
最好的问候,
Best Regards,
爱德华
这篇关于客户端身份验证方案'Basic'禁止HTTP请求.远程服务器返回错误:(403)禁止.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!