トップ回答者
統合Windows認証でのWCFサービスの方法をご教授下さい。

質問
-
環境
Windows 2003 Server Standerd Edition SP2
IIS6.0
SilverlightからIIS6.0のWindows統合認証を行っているIISにホストされている
WCFサービスを呼び出したら、エラーになってしまいサービスを呼び出すことができませんでした。
WCFサービスは次の2種類(BasicHttpBinding,CustomBinding)をためしてみましたが二つともうまくいきませんでした。
Web.config:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="SilverlightDeployTestApp.Web.TestServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
<behavior name="SilverlightDeployTestApp.Web.BasicHttpBindingServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="basicHttpBinding1">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" />
</security>
</binding>
</basicHttpBinding>
<customBinding>
<binding name="customBinding0">
<binaryMessageEncoding />
<httpTransport />
</binding>
</customBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<services>
<service behaviorConfiguration="SilverlightDeployTestApp.Web.TestServiceBehavior"
name="SilverlightDeployTestApp.Web.TestService">
<endpoint address="" binding="customBinding" bindingConfiguration="customBinding0"
contract="SilverlightDeployTestApp.Web.TestService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
<service behaviorConfiguration="SilverlightDeployTestApp.Web.BasicHttpBindingServiceBehavior"
name="SilverlightDeployTestApp.Web.BasicHttpBindingService">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="basicHttpBinding1"
contract="SilverlightDeployTestApp.Web.BasicHttpBindingService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>イベントログには以下のようなメッセージが出力されていました。
WebHost で要求の処理に失敗しました。
送信者の情報: System.ServiceModel.ServiceHostingEnvironment+HostingManager/27006480
例外: System.ServiceModel.ServiceActivationException: コンパイル中に例外が発生したためサービス '/[サイト名]/Service/TestService.svc' をアクティブにできませんでした。例外メッセージ: このサービスのセキュリティ設定では 'Anonymous' 認証を必要としていますが、このサービスをホストする IIS アプリケーションではその認証方法が有効になっていません 。。 ---> System.NotSupportedException: このサービスのセキュリティ設定では 'Anonymous' 認証を必要としていますが、このサービスをホストする IIS アプリケーションではその認証方法が有効になっていません。
場所 System.ServiceModel.Channels.HttpChannelListener.ApplyHostedContext(VirtualPathExtension virtualPathExtension, Boolean isMetadataListener)
場所 System.ServiceModel.Activation.VirtualPathExtension.ApplyHostedContext(TransportChannelListener listener, BindingContext context)
場所 System.ServiceModel.Channels.HttpTransportBindingElement.BuildChannelListener[TChannel](BindingContext context)
場所 System.ServiceModel.Channels.BindingContext.BuildInnerChannelListener[TChannel]()
場所 System.ServiceModel.Channels.MessageEncodingBindingElement.InternalBuildChannelListener[TChannel](BindingContext context)
場所 System.ServiceModel.Channels.BinaryMessageEncodingBindingElement.BuildChannelListener[TChannel](BindingContext context)
場所 System.ServiceModel.Channels.BindingContext.BuildInnerChannelListener[TChannel]()
場所 System.ServiceModel.Channels.Binding.BuildChannelListener[TChannel](Uri listenUriBaseAddress, String listenUriRelativeAddress, ListenUriMode listenUriMode, BindingParameterCollection parameters)
場所 System.ServiceModel.Description.DispatcherBuilder.MaybeCreateListener(Boolean actuallyCreate, Type[] supportedChannels, Binding binding, BindingParameterCollection parameters, Uri listenUriBaseAddress, String listenUriRelativeAddress, ListenUriMode listenUriMode, ServiceThrottle throttle, IChannelListener& result, Boolean supportContextSession)
場所 System.ServiceModel.Description.DispatcherBuilder.BuildChannelListener(StuffPerListenUriInfo stuff, ServiceHostBase serviceHost, Uri listenUri, ListenUriMode listenUriMode, Boolean supportContextSession, IChannelListener& result)
場所 System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost(ServiceDescription description, ServiceHostBase serviceHost)
場所 System.ServiceModel.ServiceHostBase.InitializeRuntime()
場所 System.ServiceModel.ServiceHostBase.OnBeginOpen()
場所 System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout)
場所 System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
場所 System.ServiceModel.ServiceHostingEnvironment.HostingManager.ActivateService(String normalizedVirtualPath)
場所 System.ServiceModel.ServiceHostingEnvironment.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath)
--- 内部例外スタック トレースの終わり ---
場所 System.ServiceModel.ServiceHostingEnvironment.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath)
場所 System.ServiceModel.ServiceHostingEnvironment.EnsureServiceAvailableFast(String relativeVirtualPath)
プロセス名: w3wp
プロセス ID: 1400メッセージではサービスはAnonymous認証を必要としているが、その設定になっていないと言われていますが、
IIS側はWindows統合認証が必須なので、それは変更できません。
統合Windows認証しているIISにホストされたWCFサービスにアクセスできた方はいらっしゃいますでしょうか?
可能である場合はどのように設定したのでしょうか?
どうかご教授下さい。
回答
-
about flat さんこんにちは
<behaviors>
<serviceBehaviors>
<behavior name="SilverlightDeployTestApp.Web.TestServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
<behavior name="SilverlightDeployTestApp.Web.BasicHttpBindingServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="basicHttpBinding1">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" />
</security>
</binding>
</basicHttpBinding>
<customBinding>
<binding name="customBinding0">
<binaryMessageEncoding />
<httpTransport />
</binding>
</customBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<services>
<service behaviorConfiguration="SilverlightDeployTestApp.Web.TestServiceBehavior"
name="SilverlightDeployTestApp.Web.TestService">
<endpoint address="" binding="customBinding" bindingConfiguration="customBinding0"
contract="SilverlightDeployTestApp.Web.TestService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
<service behaviorConfiguration="SilverlightDeployTestApp.Web.BasicHttpBindingServiceBehavior"
name="SilverlightDeployTestApp.Web.BasicHttpBindingService">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="basicHttpBinding1"
contract="SilverlightDeployTestApp.Web.BasicHttpBindingService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>イベントログには以下のようなメッセージが出力されていました。
WebHost で要求の処理に失敗しました。
送信者の情報: System.ServiceModel.ServiceHostingEnvironment+HostingManager/27006480
例外: System.ServiceModel.ServiceActivationException: コンパイル中に例外が発生したためサービス '/[サイト名]/Service/TestService.svc' をアクティブにできませんでした。例外メッセージ: このサービスのセキュリティ設定では 'Anonymous' 認証を必要としていますが、このサービスをホストする IIS アプリケーションではその認証方法が有効になっていません 。。 ---> System.NotSupportedException: このサービスのセキュリティ設定では 'Anonymous' 認証を必要としていますが、このサービスをホストする IIS アプリケーションではその認証方法が有効になっていません
たとえば次のようにです。<services> <service behaviorConfiguration="SilverlightDeployTestApp.Web.BasicHttpBindingServiceBehavior" name="SilverlightDeployTestApp.Web.BasicHttpBindingService"> <endpoint address="" binding="basicHttpBinding" bindingConfiguration="basicHttpBinding1" contract="SilverlightDeployTestApp.Web.BasicHttpBindingService" /> </service> </services>
servicebehaviors の設定で、<serviceMetadata httpGetEnabled="true" />としているので、MetadataExchangeのエンドポイントを設定する必要はありません。.svc に?wsdl をつければ公開されているメタデータにアクセスできます。
参考になれば幸いです。
すべての返信
-
about flat さんこんにちは
<behaviors>
<serviceBehaviors>
<behavior name="SilverlightDeployTestApp.Web.TestServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
<behavior name="SilverlightDeployTestApp.Web.BasicHttpBindingServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="basicHttpBinding1">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" />
</security>
</binding>
</basicHttpBinding>
<customBinding>
<binding name="customBinding0">
<binaryMessageEncoding />
<httpTransport />
</binding>
</customBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<services>
<service behaviorConfiguration="SilverlightDeployTestApp.Web.TestServiceBehavior"
name="SilverlightDeployTestApp.Web.TestService">
<endpoint address="" binding="customBinding" bindingConfiguration="customBinding0"
contract="SilverlightDeployTestApp.Web.TestService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
<service behaviorConfiguration="SilverlightDeployTestApp.Web.BasicHttpBindingServiceBehavior"
name="SilverlightDeployTestApp.Web.BasicHttpBindingService">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="basicHttpBinding1"
contract="SilverlightDeployTestApp.Web.BasicHttpBindingService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>イベントログには以下のようなメッセージが出力されていました。
WebHost で要求の処理に失敗しました。
送信者の情報: System.ServiceModel.ServiceHostingEnvironment+HostingManager/27006480
例外: System.ServiceModel.ServiceActivationException: コンパイル中に例外が発生したためサービス '/[サイト名]/Service/TestService.svc' をアクティブにできませんでした。例外メッセージ: このサービスのセキュリティ設定では 'Anonymous' 認証を必要としていますが、このサービスをホストする IIS アプリケーションではその認証方法が有効になっていません 。。 ---> System.NotSupportedException: このサービスのセキュリティ設定では 'Anonymous' 認証を必要としていますが、このサービスをホストする IIS アプリケーションではその認証方法が有効になっていません
たとえば次のようにです。<services> <service behaviorConfiguration="SilverlightDeployTestApp.Web.BasicHttpBindingServiceBehavior" name="SilverlightDeployTestApp.Web.BasicHttpBindingService"> <endpoint address="" binding="basicHttpBinding" bindingConfiguration="basicHttpBinding1" contract="SilverlightDeployTestApp.Web.BasicHttpBindingService" /> </service> </services>
servicebehaviors の設定で、<serviceMetadata httpGetEnabled="true" />としているので、MetadataExchangeのエンドポイントを設定する必要はありません。.svc に?wsdl をつければ公開されているメタデータにアクセスできます。
参考になれば幸いです。 -
こんにちは
毎回発生するのではなく、初回アクセス時に、チャネルスタック(mexHttpBindingから作成)を構築するときに実行環境の認証方式(Windows認証) と mexHttpBinding が要求するセキュリティーモードが異なるために例外が発生したのだと思います。
mexHttpBinding のセキュリティーモードについては次のURLのmexHttpBinding の解説に記載されています。
http://msdn.microsoft.com/ja-jp/library/aa967390.aspx