J'essaie de faire une application WP7 qui doit interagir avec le service WCF.
Ce que je veux est de passer userName/mot de passe et le voir dans le service WCF.WCF - ne peut pas obtenir Identity.UserName à l'intérieur du service
Service1Client proxy = new Service1Client();
proxy.ClientCredentials.UserName.UserName= "[email protected]";
proxy.ClientCredentials.UserName.Password = "abc";
code, nous avons essayé en service pour obtenir le nom authentifié (mais nous avons l'identité de fenêtres à la place - MyPc \ myLogin)
HttpContext.Current.User.Identity.Name
Voici config client
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService1" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647">
<!--<security mode="None" />-->
<security mode="TransportCredentialOnly">
<!--<transport clientCredentialType="Basic" />-->
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:45148/Service1.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService1" contract="ServiceReference1.IService1"
name="BasicHttpBinding_IService1" />
</client>
</system.serviceModel>
Et voici la configuration du serveur
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors >
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="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"/>
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom"
customUserNamePasswordValidatorType="WP7Service.WpfCustomValidator, WP7Service" />
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService1">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="None" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
J'ai aussi validateur nom d'utilisateur cutom, mais il est jamais appelé
public class WpfCustomValidator :
System.IdentityModel.Selectors.UserNamePasswordValidator
{
public override void Validate(string userName, string password)
{
if (userName == null || password == null)
{
throw new ArgumentNullException();
}
var rf = WindsorAccessor.InitializeRepositoryFactory(userName);
if (!ValidateLogOn(rf, userName, password))
{
throw new FaultException("Incorrect Username or Password");
}
}
}
Je veux la réponse à montrer comment configurer le client et le service pour être en mesure de voir ClientCredentials.UserName.UserName
en service via HttpContext.Current.User.Identity.Name
ou par thread courant identité (ou de toute autre manière).
N'a pas encore testé, mais semble que c'est ce dont nous avons besoin, tnx. –
FYI - Le lien est maintenant cassé. –