WCF での認証に関するいくつかの問題に直面しています。コンソール ベースのアプリからサービスを利用すると問題なく動作しますが、asp.net から試すと次のようになります。
The remote server returned an error: (401) Unauthorized.
[WebException: The remote server returned an error: (401) Unauthorized.]
System.Net.HttpWebRequest.GetResponse() +1126
System.ServiceModel.Channels.HttpChannelRequest.WaitForReply(TimeSpan timeout) +81
[MessageSecurityException: The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'Negotiate,NTLM'.]
System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) +10259322
ASP ページがホストされている IIS を構成する必要があると思います。匿名認証を無効にして Windows 認証を有効にしようとしましたが、うまくいきません。
私は BasicHttpBinding を使用しています。これは、私の WCF がホストされているサーバー上の私の web.config です。
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="basicBinding">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="Service1" behaviorConfiguration="ServiceBehavior" >
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="basicBinding" contract="Contract1"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="True"/>
</behavior>
</serviceBehaviors>
</behaviors>
ASP.net とコンソール ベースの構成ファイルは同じなので、サービスがホストされている IIS で作業する必要があると思います。
コードまたは構成ファイルに関する詳細情報を投稿する必要があるかどうかをお知らせください。
どんなアドバイスでも大歓迎です。
編集
これは、ASP ページでサービスを利用する方法です。
Client client = new Client("BasicBinding");
try
{
string strResult = client.ProcessTransaction(strRequestDetails);
}
catch (FaultException ex)
{
lbMessage.Text = ex.Message;
}
サーバー サイトでは、これは例外がスローされている行です。この 1 行で認証の問題を分離していることに注意してください。
public string ProcessTransaction(string strRequestDetails)
{
return OperationContext.Current.ServiceSecurityContext.WindowsIdentity.Name;
asp.net 3.5 と IIS 7.5 の使用