1
私はwcfアプリケーションとクライアントを作成しました。 WCFアプリ。ユーザーとパスワードがサービス操作にアクセスしたことを知る必要があります。それは私が行って何です:
ServerのWeb設定:clientCredentialTypeをUserNameに変更しますが、x509証明書を使用します
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="wsHttpEndpointBinding">
<security>
<message clientCredentialType="Certificate" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="Auth">
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceMetadata httpGetEnabled="true"/>
<serviceCredentials>
<clientCertificate>
<authentication certificateValidationMode="PeerTrust"/>
</clientCertificate>
<serviceCertificate findValue="WCfServer"
storeLocation="CurrentUser"
storeName="My"
x509FindType="FindBySubjectName" />
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="Auth" name="Service">
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="wsHttpEndpointBinding" contract="IService"/>
</service>
</services>
</system.serviceModel>
<system.web>
<compilation debug="true"/>
</system.web>
</configuration>
クライアントの設定: http://www.codeproject.com/:私は、証明書を生成する方法
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text"
textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Certificate" negotiateServiceCredential="true" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="CustomBehavior">
<clientCredentials>
<clientCertificate findValue="WcfClient" x509FindType="FindBySubjectName" storeLocation="CurrentUser" storeName="My" />
<serviceCertificate>
<authentication certificateValidationMode="PeerTrust"/>
</serviceCertificate>
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
<client>
<endpoint address="http://localhost:30341/WCFAuthTest/Service.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService"
contract="Service.IService" name="WSHttpBinding_IService" behaviorConfiguration="CustomBehavior">
<identity>
<dns value="WcfServer" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
KB/WCF/9StepsWCF.aspx
サービスの操作:
public string TestAccess()
{
return OperationContext.Current.ServiceSecurityContext.PrimaryIdentity.Name;
}
クライアント:
ServiceClient client = new ServiceClient();
client.ClientCredentials.UserName.UserName = "Admin";
client.ClientCredentials.UserName.Password = "123";
Console.WriteLine(client.TestAccess());
Console.ReadLine();
そして、プログラムは、管理を返さなければならないが、それはしていません: http://img27.imageshack.us/img27/3104/returnz.png
私はユーザー名にclientCredentialTypeを変更する必要があることを知っているが、それは私にエラーをgaves
証明書は必要ありませんか? あなたは後で、私は暗号化のためにそれが必要だと言ってきましたが、msdnチュートリアルでは何もありません。証明書が必要な場合は、正しい作成(makecert.exeを使用)のリンクを投稿してください。 – croisharp
申し訳ありませんが、記事の仕方は不完全です。 [this](http://wcfsecurityguide.codeplex.com/wikipage?title=Ch%2015%20-%20Internet%20%E2%80%93%20Windows%20Forms%20Client%20to%20Remote%20WCF%20Using% 20Message%20Security%20%28Original%20Caller%2c%20HTTP%29&referencedTitle = Home)サーバー用の証明書が必要で、クライアントは公開鍵を使用する必要があります。証明書の種類を証明書に設定すると、サーバー用の証明書があり、各クライアントには彼を識別する別の証明書があると言います。 –
リンクのTh Thx、役に立つ情報はたくさんありますが、必要なものはありません。私は、安全な接続を介して、ユーザー名とパスワードを渡す必要があります。 – croisharp