且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

客户端身份验证方案'Basic'禁止HTTP请求.远程服务器返回错误:(403)禁止.

更新时间:2022-12-15 21:52:09

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,

爱德华