0
私はWCFサービスと対話する必要のあるWP7アプリケーションを作成しようとしています。
私が望むのは、userName/passwordを渡してWCFサービスで参照することです。WCF - サービス内でIdentity.UserNameを取得できません。
Service1Client proxy = new Service1Client();
proxy.ClientCredentials.UserName.UserName= "[email protected]";
proxy.ClientCredentials.UserName.Password = "abc";
我々は認証済みの名前を取得するにはサービスにしようとした(しかし、我々は代わりに、Windowsのアイデンティティを持って - MYPC \ MyLogin)をコードここ
HttpContext.Current.User.Identity.Name
は、クライアントの設定
<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>
ですそしてここにサーバー設定があります
私は答えはHttpContext.Current.User.Identity.Name
を介して、または現在のスレッドを介してサービスで
ClientCredentials.UserName.UserName
を見ることができるように、クライアントとサービスを構成する方法を示したいと思います
<?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>
また、私はcutomユーザ名バリデータを持っているが、それは
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");
}
}
}
呼び出されることはありませんアイデンティティ(または他の方法)。
まだテストされていませんが、必要なものはtnxです。 –
FYI - リンクが壊れています。 –