【问题标题】:Trouble connecting to API无法连接到 API
【发布时间】:2015-07-27 12:27:42
【问题描述】:

我是 WCF/API 的新手,对安全性知之甚少。如果我需要提供更多信息,请告诉我。

我正在尝试使用

连接到服务
<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>

有了这个,我得到这个错误:

'System.ServiceModel.Security.MessageSecurityException'

The HTTP request is unauthorized with client authentication scheme 'Basic'. 
The authentication header received from the server was 'Basic Realm'.

编辑 我按照 cmets 中提供的链接中建议的说明进行操作,仍然给我这个错误。我更新了我的代码,但由于缺乏对这两种服务的了解,我对是否使用 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;
    }

【问题讨论】:

标签: wcf authentication wcf-security


【解决方案1】:

看起来,我无法使用这个特定的数据库访问 API,这就是我出错的原因。我尝试从同一服务器为单独的数据库发送其他凭据,它工作得非常好。购买了所需的许可证,代码按预期工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-09-12
    • 2022-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-15
    相关资源
    最近更新 更多