Как позвонить в службу WCF Rest с Basic Auth, используя Postman? - PullRequest
0 голосов
/ 05 апреля 2019

Я создал службу WCF с базовой аутентификацией, следуя этой статье https://docs.microsoft.com/en-gb/dotnet/framework/wcf/feature-details/transport-security-with-basic-authentication. Но когда я вызываю ее с помощью Postman, я получаю сообщение об ошибке (400 Bad Request).

Если я использую небольшойПриложение, написанное на C #, излагает ClientCredentials, оно работает хорошо.

Вот мой код сервера:

public class DataService : IDataService
{
    public bool GetData()
    {
        return true;
    }
}
[ServiceContract]
public interface IDataService
{
    [OperationContract]
    [WebInvoke(Method = "GET", UriTemplate = "GetData")]
    bool GetData();
}
<?xml version="1.0"?>
<configuration>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.6.2" />
    <httpRuntime targetFramework="4.6.2"/>
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <protocolMapping>
        <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>    
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
    <bindings>
        <wsHttpBinding>
            <binding name="UsernameWithTransport">
                <security mode="Transport">
                    <transport clientCredentialType="Basic" />
                </security>
            </binding>
        </wsHttpBinding>
    </bindings>
        <services>
            <service name="BasicAuthenticationTest">
                <endpoint 
                    address=""
                    binding="wsHttpBinding"   
                    bindingConfiguration="UsernameWithTransport"  
                    name="BasicEndpoint"  
                    contract="BasicAuthTest.IDataService"/>
            </service>
        </services>
    </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <directoryBrowse enabled="true"/>
  </system.webServer>
</configuration>

enter image description here

Я также отключил «Проверка сертификата SSL» и прокси в Почтальоне

...