Wcf 连接到API时出现问题
我是WCF/API新手,对安全性知之甚少甚至一无所知。如果我需要提供更多信息,请告诉我 我正在尝试使用连接到服务Wcf 连接到API时出现问题,wcf,authentication,wcf-security,Wcf,Authentication,Wcf Security,我是WCF/API新手,对安全性知之甚少甚至一无所知。如果我需要提供更多信息,请告诉我 我正在尝试使用连接到服务 <system.serviceModel> <bindings> <basicHttpBinding> <binding name="BasicHttpBinding_ISalesOrderService"> <security mode="Transp
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_ISalesOrderService">
<security mode="Transport" >
<transport clientCredentialType="Basic"></transport>
</security>
</binding>
<binding name="BasicHttpBinding_IDocumentationService">
<security mode="TransportCredentialOnly" >
<transport clientCredentialType="Basic"></transport>
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="address1"
name="BasicHttpBinding_ISalesOrderService"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_ISalesOrderService"
contract="SoCalls.ISalesOrderService" />
<endpoint address="address2"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IDocumentationService"
contract="DocCalls.IDocumentationService"
name="BasicHttpBinding_IDocumentationService" />
</client>
</system.serviceModel>
编辑
我按照评论中提供的链接中建议的说明操作,仍然在给我这个错误。我更新了我的代码,但我认为我仍然有点困惑是否使用HTTP/HTTPS,因为缺乏对这两种服务的了解
以下是我如何实例化我的服务:
private static SoCalls.SalesOrderServiceClient CreateSalesOrderServiceClient()
{
BasicHttpBinding myBinding = new BasicHttpBinding();
myBinding.MaxReceivedMessageSize = 10000 * 2;
myBinding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
myBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
EndpointAddress ea = new EndpointAddress("address1");
SoCalls.SalesOrderServiceClient client = new SoCalls.SalesOrderServiceClient();
client.ClientCredentials.UserName.UserName = ("username");
client.ClientCredentials.UserName.Password = ("password");
return client;
}
看起来,我没有访问这个特定数据库的API,这正是导致我出错的原因。我试着从同一台服务器上为一个单独的数据库发送其他凭据,但效果非常好。购买了所需的许可证,代码按预期工作 看起来,我没有权限使用这个特定的数据库访问API,这就是导致我出错的原因。我试着从同一台服务器上为一个单独的数据库发送其他凭据,但效果非常好。购买了所需的许可证,代码按预期工作 dublicate可能复制了@CodeCaster,您的意思是试图声明两个吗?我知道地址是不同的,因为它们是我项目中两个不同的服务引用。您认为我设置它们的方式会在运行时混淆程序吗?-谢谢这个评论意味着你的问题似乎是问题的重复,后者是一个链接。单击它,实施建议的解决方案。@CodeCaster啊,很抱歉。感谢您的链接。演示如何实例化客户端代理以及如何设置身份验证信息。dublicate可能重复@CodeCaster,您的意思是尝试声明两个吗?我知道地址是不同的,因为它们是我项目中两个不同的服务引用。您认为我设置它们的方式会在运行时混淆程序吗?-谢谢这个评论意味着你的问题似乎是问题的重复,后者是一个链接。单击它,实施建议的解决方案。@CodeCaster啊,很抱歉。感谢您的链接。演示如何实例化客户端代理以及如何设置身份验证信息。
private static SoCalls.SalesOrderServiceClient CreateSalesOrderServiceClient()
{
BasicHttpBinding myBinding = new BasicHttpBinding();
myBinding.MaxReceivedMessageSize = 10000 * 2;
myBinding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
myBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
EndpointAddress ea = new EndpointAddress("address1");
SoCalls.SalesOrderServiceClient client = new SoCalls.SalesOrderServiceClient();
client.ClientCredentials.UserName.UserName = ("username");
client.ClientCredentials.UserName.Password = ("password");
return client;
}