无法连接到API

时间:2015-07-27 12:27:42

标签: wcf authentication wcf-security

我是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'.

修改 我按照评论中提供的链接建议,仍然是给我这个错误。我更新了我的代码,但我认为由于缺乏对这两种服务的了解,我是否仍然对使用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;
    }

1 个答案:

答案 0 :(得分:0)

看起来,我没有访问这个特定数据库的API,而这正是给我的错误。我尝试从同一台服务器发送一个单独的数据库的其他凭据,它工作得很好。购买了所需的许可证,代码按预期工作。