Próbuję wykonać bardzo proste, ale bezpieczne uwierzytelnianie użytkownika/hasła za pomocą wcf.Podstawowe uwierzytelnianie dla WCF
Jednak gdy patrzę na wartość ServiceSecurityContext.Current.PrimaryIdentity;
, zawiera ona dane uwierzytelniające mojego komputera z systemem Windows i twierdzi, że jest autoryzowana (nawet jeśli nie dokonałem jeszcze żadnej autoryzacji) zamiast nazwy użytkownika i hasła podanego w usłudze.
Moje web.config usługi jest następująca
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding name="WsHttpBindingConfig">
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="None" />
<message clientCredentialType="UserName" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<protocolMapping>
<add binding="wsHttpBinding" scheme="http" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
i app.config z aplikacji klienckiej jest następujący
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IService1" />
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost/WcfSecuredService/Service1.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService1"
contract="ServiceReference1.IService1" name="WSHttpBinding_IService1">
</endpoint>
</client>
</system.serviceModel>
</configuration>
zgłoszę usługi z następującego kodu
ServiceReference1.Service1Client clnt = new ServiceReference1.Service1Client();
clnt.ClientCredentials.UserName.UserName = "peter";
clnt.ClientCredentials.UserName.Password = "grr";
string result=clnt.GetSecuredData();
Co robię źle?
Należy pamiętać, że zarówno aplikacja kliencka, jak i usługa działają na tym samym komputerze. Nie wiem, czy tożsamość jest identyczna z maszyną, na której działa ta usługa, czy z tą, która została przekazana klientowi, ponieważ są to te same poświadczenia ...
Przypuszczam, że inne pytanie brzmi: "Jak to zrobić? Dostaję nazwę użytkownika i hasło, które zostały przekazane do usługi? "
Próbowałem tego kilka razy, ale nazwa użytkownika otrzymana podczas uzyskiwania dostępu do 'ServiceSecurityContext.Current.PrimaryIdentity' nie wydaje się być używane do uwierzytelniania. czy możesz rzucić tutaj trochę światła? –