У меня есть служба WCF SOAP, которая использует базовую аутентификацию доступа. SSL не используется - я понимаю здесь проблемы с безопасностью.
Используя приложение WCFTestClient, я убедился, что служба работает, временно жестко закодировав в службе имя пользователя и пароль, которые будут использоваться, когда заголовок Authorization
отсутствует.
Сейчас я пытаюсь написать тестовое приложение, которое передает учетные данные через заголовок Authorization
. Я добавил ссылку на свою службу в своем тестовом приложении, но заголовок Authorization
отсутствует в HTTP-запросе. Сгенерированный класс MyServiceClient
использует System.ServiceModel.ClientBase
В моем тестовом приложении я устанавливаю учетные данные следующим образом
MyServiceClient client = new MyServiceClient("BasicHttpBinding_MyService");
client.ClientCredentials.UserName.UserName = "WebServiceUsername";
client.ClientCredentials.UserName.Password = "WebServicepassword";
Я также пробовал следующим образом
MyServiceClient client = new MyServiceClient();
ClientCredentials loginCredentials = new ClientCredentials();
loginCredentials.UserName.UserName = "WebServiceUsername";
loginCredentials.UserName.Password = "WebServicepassword";
client.Endpoint.Behaviors.Remove(client.Endpoint.Behaviors.Find<ClientCredentials>());
client.Endpoint.Behaviors.Add(loginCredentials);
Служба web.config выглядит следующим образом
<services>
<service name="MyService" behaviorConfiguration="MyBehavior" >
<endpoint contract="MyService" binding="basicHttpBinding" />
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
</service>
</services>
Тестовый файл app.config выглядит следующим образом
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_MyService">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Basic"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:55314/MyService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_MyService"
contract="MyService" name="BasicHttpBinding_MyService" />
</client>
</system.serviceModel>
</configuration>
Любые мысли о том, чего мне не хватает?